pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mickael Marrache <mickaelmarra...@gmail.com>
Subject PDFBOX cache warning and embedded fonts
Date Fri, 27 Apr 2018 06:13:34 GMT
Hi,

After encountering the following error:

java.lang.IllegalArgumentException: U+05E5 ('afii57685') is not available
in this font Helvetica encoding: WinAnsiEncoding
at org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:426)
I'm embedding the font I want to use as follows:

PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
PDResources res = acroForm.getDefaultResources();
PDType0Font font = PDType0Font.load(pdfDocument,
PDFBoxUtils.class.getClassLoader().getResourceAsStream("DAVID.TTF"));
COSName fontName = res.add(font);
acroForm.setDefaultResources(res);
textField.setDefaultAppearance("/" + fontName.getName() + " 0 Tf 0 g");

I expect the font to be embedded but then I see the following in the logs:

[org.apache.pdfbox.pdmodel.font.PDCIDFontType2] - Using fallback font
LiberationSans for CID-keyed TrueType font David

Before fixing fonts for text fields using the snippet above, the text
fields are set with the font David (via Acrobat DC). I can understand
PDFBOX can't find this font because it is not installed on the server.
However, the fonts are changed with an embedded font available on the
classpath so I don't understand why I get that warning.

I also thought the warnings are generated when the document is loaded
(before text fields are fixed) but then I tried to open the generated PDF
with Acrobat Reader and I see squares instead of valid characters.

I also precise I flatten the acroform.

Thanks,
Mickael

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message