I have a simple spring boot web app, where i create downloadable pdf with flying-saucer-pdf from html that i render with thymeleaf. It's work well and generate the html string correctly. I develop on windows and during develop generating the pdf is also works well, but on ubuntu server don't work.
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont(fontFile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
fontFile is exist, on ubuntu too, it's accessibly by the program, and can access it, but when i want render a pdf i got the following exception. I have no ide what actually it means.
Caused by: com.lowagie.text.DocumentException: Table 'name' does not exist in /opt/RFIT/TextileApp/conf/font/Rubik-Regular.ttf at com.lowagie.text.pdf.TrueTypeFont.getBaseFont(Unknown Source) ~[itext-2.1.7.jar:na] at com.lowagie.text.pdf.TrueTypeFont.process(Unknown Source) ~[itext-2.1.7.jar:na] at com.lowagie.text.pdf.TrueTypeFontUnicode.(Unknown Source) ~[itext-2.1.7.jar:na] at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source) ~[itext-2.1.7.jar:na] at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source) ~[itext-2.1.7.jar:na] at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source) ~[itext-2.1.7.jar:na] at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:201) ~[flying-saucer-pdf-9.1.6.jar:na] at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:193) ~[flying-saucer-pdf-9.1.6.jar:na] at org.xhtmlrenderer.pdf.ITextFontResolver.addFont(ITextFontResolver.java:188) ~[flying-saucer-pdf-9.1.6.jar:na] at hu.rfit.textile.service.impl.PdfPrinterService.printPDF(PdfPrinterService.java:53) ~[TextileApp-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT:4749]
on some forum they said i should add the font to /usr/share/fonts dirt, and re build the font cache. But it's does not work.
I had same problem about adding font with flying-saucher. Problems main cause is cropped font file. Your operating system or maven filtering may cause this problem. In my example, i used maven and following steps are solved the problem.
If you are using maven, you should add font file to your resource folder.
For example,
src/main/resources/fonts/samplefont.ttf
After that, you should define resources on pom.xml like following;
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>fonts/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>fonts/*</include>
</includes>
</resource>
</resources>
After that, you can use following definition,
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("/fonts/samplefont.ttf",
BaseFont.IDENTITY_H,
BaseFont.EMBEDDED);
I hope it will be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With