Displaying embedded fonts with PDFBox and Swing

2019-06-07 07:04发布

I am using PDFBox to display PDF files inside a JInternalFrame. When opening PDF I get lots of warnings like this:

Changing font on <m> from <Tahoma Negrita> to the default font

I am aware that the fonts being reported are not part of the standard set of 14 fonts. So I decided to check if those fonts are embedded on the PDF file (thinking that there shouldn't be a problem loading embedded fonts, right?).

So I open the file on different readers and check properties/fonts. I am in doubt whether this section reports fonts required by the document or fonts actually embedded in the document.

The information that I get is as follows:

BAAAA+Tahoma-Bold (embedded Subset), type:TrueType, Encoding:
CAAAA+Tahoma (Embedded Subset), type:TrueType, Encoding:

Confused about this, I researched on how to embed fonts from OpenOffice and found that the PDF/A-1a option should be checked. So I made another PDF using this option (in case this was not used when making the original PDF file), yet I got the same results.

I would like your guidance understanding how this works. I would like to be able to open PDF files just as PDF readers do. I also read about the PDFBox_External_Fonts.properties but I am guessing this file shouldn't be modified since I am dealing with embedded fonts.

Thanks.

标签: java pdfbox
1条回答
手持菜刀,她持情操
2楼-- · 2019-06-07 07:35

pdfbox is not able to parse embedded subsets of TrueType fonts.

As far as I understand it, embedded TrueType subsets are missing some metadata for the font file that pdfbox needs.

The bug is known but not easy to solve. Right now I can only advise to use embedded Type 1 Fonts if possible, pdfbox can deal with them.

You can also try to set the path to your complete font files in your pdfbox.jar under org/apache/pdfbox/resources/PDFBox_External_Fonts.properties, so if pdfbox cannot parse the subset, at least it can find a full path to the original font file. Maybe that works, but I have not tested this.

Good Luck!

查看更多
登录 后发表回答