Embed glyphs into PDF

Hallo

Is it possible to embed only used glymphs into the PDF?
I searched through the documentation, but only found something like RemoveDuplicatedFonts and RemoveSimilarFontsWithDifferentWidths. That is not what I want.
I want to know whether it is possible to tell aspose to embed only the glyphs that are actually used, instead of the whole font.

The problem I have is that the PDF gets very large when using certain fonts. If I use “NotoSansCJKjp-Regular” font from Google Noto Fonts, the document increases in size with more than 10MB.

The code snippet below demonstrates this issue. There is one table and 2 cells with some text. The result is saved in the attachment: “ResultNoto.pdf”.
If I comment out the line of code that specifies usage of “NotoSansCJKjp-Regular”, the resulting PDF more than 10MB smaller: “Result.pdf”.
The files are attached and the sample code is below:

List fontPaths = com.aspose.pdf.Document.getLocalFontPaths();
fontPaths.add(“C:\temp\Noto-hinted”);
com.aspose.pdf.Document.setLocalFontPaths(fontPaths);

List inputStringList = new ArrayList<>();
inputStringList.add(“äöüß é ç Здравствуйте 3 df a dad a END”);
inputStringList.add(“äöüß é ç Здравствуйте 昨夜のコンサートは最高でし adsf dfg END”);

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(“Blank.pdf”);
com.aspose.pdf.Table table = new com.aspose.pdf.Table();
table.getDefaultCellTextState().setFont(com.aspose.pdf.FontRepository.findFont(“NotoSansCJKjp-Regular”));
table.setColumnWidths(“400”);

for (String currentString : inputStringList) {
Row row = table.getRows().add();
row.getCells().add(currentString);
}

I am using aspose.pdf verson 11.8.0

Thank you,
Samuel

Hi Samuel,


Thanks for your inquriy. After initial investigation, we have logged a ticket PDFJAVA-36481 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress within this forum thread.

We are sorry for the inconvenience.

Best Regards,

Hallo

I noticed that some fonts actually embed used glyphs only. For example, when using the “Arial Unicode MS”(Dropbox - File Deleted - Simplify your life)(I made sure to delete other windows fonts so that the attached font is actually used), the size of the attached pdf “Result.pdf” is small. From this I would think that aspose is embedding used glypsh only by default. Is this an undefined behavior?
Is the ticket issued in the reply above related to cases where the whole font is embedded instead of the used glyphs only(as the scenario originally described), or is it related to a new feature that should allow only used glyphs to be embedded in the pdf?

Thank you,
Samuel

Hi Samuel,


Thanks for sharing your findings. We have shared the details with product team, they will consider it during issue investigation. Furthermore, above logged ticket is to investigate your requirement to embed glyphs instead complete fonts. Subset font option adds only the characters used instead font, but it is not working in the scenario. So as soon as our product team complete the investigation, we will share some fix or workaround with you.

Thanks for your patience and cooperation.

Best Regards,

The issues you have found earlier (filed as PDFJAVA-36481) have been fixed in Aspose.PDF for Java 21.3.