Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache PDFBox - Difference among PDFont types

Tags:

java

pdfbox

I started recently to use PDFBox to process some PDF files. I loaded successfully the Roboto font, however, I don't understand the difference between PDType0Font, PDType1Font and PDTrueTypeFont. Which one is better to use?

Regards

like image 575
José Escorche Avatar asked Oct 25 '25 00:10

José Escorche


1 Answers

If you want to use the standard 14 fonts (times, helvetica, courier, symbol, zapf dingbats) => use PDType1Font.HELVETICA etc. (Only WinAnsiEncoding supported)

If you have type1 fonts on your computer and want to use these => use the PDType1Font constructor.

If you want to use TrueType fonts in an inefficient way (only 256 glyphs, no subsetting) => use PDTrueTypeFont.load().

If you want to use TrueType fonts in an efficient way (more than 256 glyphs, subsetting) => use PDType0Font.load(). You can and should use the same font object for the whole PDF, i.e. don't create a new PDFont object for each page.

If you want to use TrueType collections, do this:

TrueTypeCollection ttc = new TrueTypeCollection(new File("C:/windows/fonts/mingliu.ttc"));
PDFont font = PDType0Font.load(doc, ttc.getFontByName("MingLiU"));
...
ttc.close(); // only after PDF has been saved
like image 192
Tilman Hausherr Avatar answered Oct 26 '25 14:10

Tilman Hausherr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!