问题描述:
使用itext生成PDF,itext-asian亚洲包提供字体文件。本地使用可以正常生成pdf,部署到服务器上会报错 。
提示错误: nested exception is java.lang.NoSuchMethodError:com.itextpdf.text.pdf.PdfPTable
.addCell(Lcom/itextpdf/text/pdf/PdfPCell;)Lcom/itextpdf/text/pdf/PdfPCell;","data":null}
尝试解决:目前网上的解决方式都说因为 itext 和 itext-asian版本不匹配,版本替换后依然报错;
https://www.cnblogs.com/iyyy/p/9347006.html 看到这篇文章后,感觉可能是字体的原因。
itextpdf生成pdf引用"STSong-Light"字体而linux环境下没有这个字体,因此生成pdf的时候就给它指定系统存在的字体。
最终解决方法:在linux服务器添加字体(宋体) https://www.ngui.cc/zz/1514813.html
cd /usr/share/fonts //打开字体存放目录
mkdir chinese //创建中文字体目录
从Windows的 C:\Windows\Fonts下获取相应字体,拖到服务器中
[supdevUser@xxxx fonts]$ cd chinese
[supdevUser@xxxx chinese]$ ll
total 11424
-rw-r--r-- 1 root root 11697600 Mar 24 2021 STSONG.TTF
安装
[supdevUser@xxx chinese]$ fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 3 dirs
/usr/share/fonts/chinese: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/dejavu: caching, new cache contents: 9 fonts, 0 dirs
/usr/share/fonts/urw-base35: caching, new cache contents: 69 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/home/supdevUser/.local/share/fonts: skipping, no such directory
/home/supdevUser/.fonts: skipping, no such directory
/usr/share/fonts/chinese: skipping, looped directory detected
/usr/share/fonts/dejavu: skipping, looped directory detected
/usr/share/fonts/urw-base35: skipping, looped directory detected
/usr/lib/fontconfig/cache: not cleaning unwritable cache directory
/home/supdevUser/.cache/fontconfig: cleaning cache directory
/home/supdevUser/.fontconfig: not cleaning non-existent cache directory
/usr/bin/fc-cache-64: succeeded
刷新内存,如果不行就需要重启服务器
[supdevUser@xxx chinese]$ fc-cache
查看是否安装完成
[supdevUser@xxx chinese]$ fc-list
/usr/share/fonts/urw-base35/NimbusMonoPS-Italic.otf: Nimbus Mono PS:style=Italic
/usr/share/fonts/urw-base35/D050000L.t1: D050000L:style=Regular
/usr/share/fonts/urw-base35/NimbusSansNarrow-Regular.t1: Nimbus Sans Narrow:style=Regular
/usr/share/fonts/urw-base35/NimbusSansNarrow-BoldOblique.t1: Nimbus Sans Narrow:style=Bold Oblique
/usr/share/fonts/urw-base35/NimbusMonoPS-Bold.otf: Nimbus Mono PS:style=Bold
/usr/share/fonts/urw-base35/P052-Roman.otf: P052:style=Roman
/usr/share/fonts/urw-base35/P052-Italic.t1: P052:style=Italic
/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/urw-base35/C059-BdIta.otf: C059:style=Bold Italic
/usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
/usr/share/fonts/urw-base35/StandardSymbolsPS.t1: Standard Symbols PS:style=Regular
/usr/share/fonts/urw-base35/URWBookman-DemiItalic.t1: URW Bookman:style=Demi Italic
/usr/share/fonts/urw-base35/C059-Roman.t1: C059:style=Roman
/usr/share/fonts/urw-base35/NimbusRoman-Italic.t1: Nimbus Roman:style=Italic
/usr/share/fonts/urw-base35/C059-BdIta.t1: C059:style=Bold Italic
/usr/share/fonts/urw-base35/URWBookman-LightItalic.otf: URW Bookman:style=Light Italic
/usr/share/fonts/urw-base35/URWGothic-DemiOblique.otf: URW Gothic:style=Demi Oblique
/usr/share/fonts/urw-base35/NimbusSansNarrow-BoldOblique.otf: Nimbus Sans Narrow:style=Bold Oblique
/usr/share/fonts/urw-base35/NimbusSans-Bold.otf: Nimbus Sans:style=Bold
/usr/share/fonts/urw-base35/NimbusRoman-Bold.otf: Nimbus Roman:style=Bold
/usr/share/fonts/urw-base35/D050000L.otf: D050000L:style=Regular
/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/urw-base35/Z003-MediumItalic.otf: Z003:style=Medium Italic
/usr/share/fonts/urw-base35/NimbusSans-Italic.otf: Nimbus Sans:style=Italic
/usr/share/fonts/urw-base35/NimbusSans-Bold.t1: Nimbus Sans:style=Bold
/usr/share/fonts/urw-base35/URWGothic-Demi.t1: URW Gothic:style=Demi
/usr/share/fonts/urw-base35/NimbusRoman-BoldItalic.otf: Nimbus Roman:style=Bold Italic
/usr/share/fonts/urw-base35/NimbusRoman-Italic.otf: Nimbus Roman:style=Italic
/usr/share/fonts/urw-base35/C059-Roman.otf: C059:style=Roman
/usr/share/fonts/urw-base35/C059-Italic.otf: C059:style=Italic
/usr/share/fonts/urw-base35/NimbusSansNarrow-Oblique.otf: Nimbus Sans Narrow:style=Oblique
/usr/share/fonts/urw-base35/NimbusSans-Regular.t1: Nimbus Sans:style=Regular
/usr/share/fonts/urw-base35/P052-Bold.otf: P052:style=Bold
/usr/share/fonts/urw-base35/NimbusSans-BoldItalic.t1: Nimbus Sans:style=Bold Italic
/usr/share/fonts/urw-base35/NimbusSansNarrow-Bold.otf: Nimbus Sans Narrow:style=Bold
/usr/share/fonts/urw-base35/NimbusMonoPS-BoldItalic.otf: Nimbus Mono PS:style=Bold Italic
/usr/share/fonts/urw-base35/URWGothic-BookOblique.otf: URW Gothic:style=Book Oblique
/usr/share/fonts/urw-base35/NimbusMonoPS-Italic.t1: Nimbus Mono PS:style=Italic
/usr/share/fonts/urw-base35/URWBookman-Light.t1: URW Bookman:style=Light
/usr/share/fonts/urw-base35/NimbusMonoPS-Regular.t1: Nimbus Mono PS:style=Regular
/usr/share/fonts/urw-base35/NimbusSans-BoldItalic.otf: Nimbus Sans:style=Bold Italic
/usr/share/fonts/urw-base35/URWGothic-Book.otf: URW Gothic:style=Book
/usr/share/fonts/urw-base35/NimbusRoman-Regular.t1: Nimbus Roman:style=Regular
/usr/share/fonts/urw-base35/URWBookman-Demi.otf: URW Bookman:style=Demi
/usr/share/fonts/urw-base35/NimbusSansNarrow-Oblique.t1: Nimbus Sans Narrow:style=Oblique
/usr/share/fonts/urw-base35/URWGothic-Demi.otf: URW Gothic:style=Demi
/usr/share/fonts/urw-base35/NimbusSans-Regular.otf: Nimbus Sans:style=Regular
/usr/share/fonts/urw-base35/NimbusRoman-BoldItalic.t1: Nimbus Roman:style=Bold Italic
/usr/share/fonts/urw-base35/P052-Italic.otf: P052:style=Italic
/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/urw-base35/NimbusSansNarrow-Regular.otf: Nimbus Sans Narrow:style=Regular
/usr/share/fonts/chinese/STSONG.TTF: STSong:style=Regular
/usr/share/fonts/urw-base35/C059-Bold.otf: C059:style=Bold
/usr/share/fonts/urw-base35/P052-BoldItalic.otf: P052:style=Bold Italic
/usr/share/fonts/urw-base35/URWGothic-Book.t1: URW Gothic:style=Book
/usr/share/fonts/urw-base35/URWBookman-Demi.t1: URW Bookman:style=Demi
/usr/share/fonts/urw-base35/URWBookman-Light.otf: URW Bookman:style=Light
/usr/share/fonts/urw-base35/URWBookman-DemiItalic.otf: URW Bookman:style=Demi Italic
/usr/share/fonts/urw-base35/P052-BoldItalic.t1: P052:style=Bold Italic
/usr/share/fonts/urw-base35/C059-Bold.t1: C059:style=Bold
/usr/share/fonts/urw-base35/NimbusRoman-Bold.t1: Nimbus Roman:style=Bold
/usr/share/fonts/urw-base35/NimbusMonoPS-BoldItalic.t1: Nimbus Mono PS:style=Bold Italic
/usr/share/fonts/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
/usr/share/fonts/urw-base35/P052-Bold.t1: P052:style=Bold
/usr/share/fonts/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight
/usr/share/fonts/urw-base35/NimbusMonoPS-Regular.otf: Nimbus Mono PS:style=Regular
/usr/share/fonts/urw-base35/URWGothic-BookOblique.t1: URW Gothic:style=Book Oblique
/usr/share/fonts/urw-base35/URWBookman-LightItalic.t1: URW Bookman:style=Light Italic
/usr/share/fonts/urw-base35/NimbusRoman-Regular.otf: Nimbus Roman:style=Regular
/usr/share/fonts/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
/usr/share/fonts/urw-base35/NimbusMonoPS-Bold.t1: Nimbus Mono PS:style=Bold
/usr/share/fonts/urw-base35/NimbusSans-Italic.t1: Nimbus Sans:style=Italic
/usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique
/usr/share/fonts/urw-base35/Z003-MediumItalic.t1: Z003:style=Medium Italic
/usr/share/fonts/urw-base35/C059-Italic.t1: C059:style=Italic
/usr/share/fonts/urw-base35/URWGothic-DemiOblique.t1: URW Gothic:style=Demi Oblique
/usr/share/fonts/urw-base35/P052-Roman.t1: P052:style=Roman
/usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique
/usr/share/fonts/urw-base35/NimbusSansNarrow-Bold.t1: Nimbus Sans Narrow:style=Bold