Free Support Forum - aspose.com

Wrong font family is used by Aspose.Words when converting from DOCX to PDF and the font is not available

Please see the attached docx file. The text uses “Liberation Sans;Arial” and “DejaVu Sans” fonts, they are not installed on the system. When converting to PDF, the resulting document uses Times New Roman font.

And I am using Aspose.Words for C++ 21.5

This is incorrect. Aspose.Words should be smart enough to figure out that the fonts used by the document are sans serif (do not have serifs) and it should use a default font without serifs e.g Arial.
file-sample_1MB out.pdf (662.7 KB)

@romank,

I am afraid, I do not see any Word DOCX document attached in your previous post. Can you please reattach source Word file here for our reference? Please also convert that DOCX file to PDF format by using MS Word on the same machine and attach it here for testing.

P.S. please first compress the above DOCX & PDF files into ZIP format and then attach the .zip file

Thank you for your reply. The files are attached below.
file-sample_1MB.zip (1.8 MB)

@romank,

You’re right; the current font substitution mechanism of “Aspose.Words for C++” API should be improved. We have logged this problem in our issue tracking system with ID WORDSNET-22384. We will keep you posted here on the status of the linked issue. Sorry for any inconvenience.

As a workaround, you can explicitly add font substitution by using the following C++ code:

System::SharedPtr<Document> doc = System::MakeObject<Document>(u"C:\\Temp\\file-sample_1MB\\file-sample_1MB.docx");

System::SharedPtr<FontSettings> fontSettings = System::MakeObject<FontSettings>();

fontSettings->get_SubstitutionSettings()->get_TableSubstitution()->AddSubstitutes(u"Liberation Sans;Arial", System::MakeArray<System::String>({ u"Arial" }));
fontSettings->get_SubstitutionSettings()->get_TableSubstitution()->AddSubstitutes(u"DejaVu Sans", System::MakeArray<System::String>({ u"Arial" }));

doc->set_FontSettings(fontSettings);

doc->Save(uR"(C:\\temp\\file-sample_1MB\\awcpp-201.6.pdf)");