Braunbaer
Braunbaer

Reputation: 53

PDFBox "This font does not permit subsetting" - Possible to use font without subsetting?

I used PDFBox (2.0.11) to create/edit PDFs and struggled with the usage of two fonts that always lead to an exception as follows

This font does not permit subsetting

Even though it is possible to subset the fonts with other tools like Everything fonts without any issues.

Is it possible to use a font with PDFbox without subsetting it or are there any other ways to solve this problem?

Exception message:

Exception in thread "main" java.io.IOException: This font does not permit subsetting
    at org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:298)
    at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:239)

SOLVED:

Here is a working example on how to load a font without subsetting it:

File fontFile1 = new File("/fonts/fontfile.ttf");
InputStream fontFile1Stream = new FileInputStream(fontFile1);
PDType0Font product_title_font = PDType0Font.load(doc, fontFile1Stream, false);

Upvotes: 1

Views: 991

Answers (1)

Tilman Hausherr
Tilman Hausherr

Reputation: 18851

Yes, you can still use the font without subsetting, use

PDType0Font.load(PDDocument doc, InputStream input, boolean embedSubset)

with the last parameter = false. Your files will be bigger, that's all. If another product can subset the font, then it means either that it doesn't respect the license settings, or that there's a bug in PDFBox. Open your font in a tool that can display the os2 table, e.g. DTL OTMaster Light. There look for the "fstype" entry. https://learn.microsoft.com/en-us/typography/opentype/spec/os2#fstype

Upvotes: 1

Related Questions