Word to PDF font question

Hi,

I have a question regarding fonts when converting a word document to a pdf in java using Aspose word.
The conversion is executed on a Linux server which lacks the fonts used in the word doc. I can use the pdfSaveOptions setEmbedFullFonts(true) to solve the problem but the generated pdf becomes very large.
When generating the pdf without setEmbedFullFonts the output pdf is about 61KB and when I enable setEmbedFullFonts the output pdf is 1.8MB.

I know that a second solution would be to install the fonts on the Linux server but I’m looking for a third alternative.

Is it possible to somehow use the fonts from the word document when the pdf is generated on the Linux server? and not include them in the generated pdf, because the generated pdf document is only viewed on client windows machines that has the fonts.

Simplified code example that do the conversion from word to pdf.

com.aspose.words.PdfSaveOptions pdfOptions = new com.aspose.words.PdfSaveOptions();
pdfOptions.setEmbedFullFonts(true);

ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
// doc is com.aspose.words.Document
	doc.save(output, pdfOptions);
} catch (Exception e) {
}

@tobjo853,

Thanks for your inquiry. If Aspose.Words does not find the font on the system, it tries to find the required font among the fonts embedded in the original Word document. Please refer to the following article.
How Aspose.Words Uses True Type Fonts

Hi again,

Yes, I can see that Aspose can generate the PDF using the fonts from the DOCX file but only when I use the PdfSaveOptions.setEmbedFullFonts(true) which causes the size of the PDF to get rather big.

My scenario:
I have a DOCX file that uses Arial (fonts are included in the DOCX).
On a Linux server where Arial is not installed I generate a PDF.
When I use setEmbedFullFonts(true) the generated PDF is correct but if I don’t use setEmbedFullFonts the PDF don’t use Arial, instead another font is used.

So my question is if there is some possibility/option to generate the PDF using the fonts from the DOCX file without including them in the generated PDF?

@tobjo853,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Hi,

the word docx was too large to attach.
The zip can be found here: https://www.dropbox.com/s/aod6ixfxc4njlok/error.zip?dl=0

@tobjo853,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for Java 18.1 and have not found the shared issue. Please use Aspose.Words for Java 18.1. You can test this scenario using following code example. In this case, the temp folder contains no font.

We have noticed that you are using the Aspose.Pdf for final output PDF. If you still face problem, please share the code example (source code without compilation errors) to reproduce your issue at our end. We will investigate the issue and provide you more information on this.

FontSettings.getDefaultInstance().setFontsFolder("/temp/", true);
Document doc = new Document(MyDir + "input.docx");
com.aspose.words.PdfSaveOptions pdfOptions = new com.aspose.words.PdfSaveOptions();
pdfOptions.setEmbedFullFonts(true);
doc.save(MyDir + "18.1.pdf", pdfOptions);

Hi,

Thanks for the quick reply!

Yes, in the case I use setEmbedFullFonts(true) it works for me as well but the generated pdf becomes quite large.

So, my question was if there are some way to make this work when setEmbedFullFonts is set to false?
My goal is to have a correct pdf generated, with the text in Arial, but the font is not included in the generated file in order to keep the down the file size.

It’s ok that the pdf is not displayed correctly when it’s viewed on a machine that doesn’t have the font installed but when it’s opened on a machine that has the font it should be correct.

@tobjo853,

Thanks for your inquiry. Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (JPEG, PNG, PDF or XPS).

The default value of PdfSaveOptions.EmbedFullFonts property is false, which means the fonts are subsetted before embedding. Subsetting is useful if you want to keep the output file size smaller. Subsetting removes all unused glyphs from a font.

You need to make sure that the Arial font is installed at the machine where are you converting document to PDF.

If you open the PDF file at the machine where Arial font is install, the whole text will be displayed correctly. Please make sure that you have generated the PDF file using Aspose.Wored at the machine where Arial is installed.

Ok. So to summarize, now we need to either install the fonts on the Linux server or include them in the generated PDF using setEmbedFullFonts(true).

Is it possible to do a feature request for this to be implemented in a future version?

@tobjo853,

Thanks for your inquiry. Please note that rendering document to PDF (document to PDF conversion) is different from embedding font into PDF document.

Aspose.Words requires true type fonts for document to PDF conversion. Aspose.Words try to find a font on the file system with an exact font name match. If required fonts are not available on the system, Aspose.Words try to find the required font among the fonts embedded in the original Word document.

If fonts are installed on the machine where you are opening the PDF, you do not need to embed the fonts into PDF using PdfSaveOptions.setEmbedFullFonts(true).

Moreover, fonts need to be embedded into any Adobe PDF document to ensure the document can be correctly read on any machine. By default, Aspose.Words embeds subsets of fonts used in the document into the generated PDF.

Just an other question regarding including fonts.
Is there some way to read the value of the word documents “Embed fonts in the file” option using Aspose.word for Java?Capture.PNG (42.6 KB)

@tobjo853,

Thanks for your inquiry. Please use FontInfoCollection.EmbedTrueTypeFonts property as shown below to get the desired output.

Document doc = new Document(MyDir + @"in.docx");
FontInfoCollection fonts = doc.FontInfos;
Console.WriteLine(fonts.EmbedTrueTypeFonts);
Console.WriteLine(fonts.EmbedSystemFonts);