This is a question for the Aspose.Words product (not Aspose.Words.Cloud) but I didn’t have the option to just choose Aspose.Words from the dropdown.
I have a dotx file with some embedded font in it and it gets lost when I generate the pdf.
Is Aspose.Words able to use the embedded font in order to generate the pdf file or do I have to search for another solution ?
@bogandy Aspose.Words supports embedded fonts and they should be used while generating PDF. Could you please attach your document here for testing? We will check the issue and provide you more information. Also, please specify which version of Aspose.Words you use for testing.
I added the test document (test.docx)
I use aspose words version 20.4
Code I use is:
Document doc = new Document("test.docx");
FontSubstitutionWarningCollector callback = new FontSubstitutionWarningCollector();
doc.setWarningCallback(callback);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setEmbedFullFonts(true);
saveOptions.setFontEmbeddingMode(PdfFontEmbeddingMode.EMBED_ALL);
doc.save("test.pdf", saveOptions);
callback.fontSubstitutionWarnings.forEach( warningInfo -> System.out.println(warningInfo.getDescription()));
and
private static class FontSubstitutionWarningCollector implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
fontSubstitutionWarnings.warning(info);
}
public WarningInfoCollection fontSubstitutionWarnings = new WarningInfoCollection();
}
The resulting pdf is: test.pdf (1.5 MB)
As you can see if you open up fonts from acrobat reader, the Lato font is not there test.pdf.png (29.4 KB)
Furthermore, the warning I get from the callback say this
Font 'Lato' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.
Font 'Roboto Slab' has not been found. Using 'Times New Roman' font instead. Reason: alternative name from document.
Font 'Lato Light' has not been found. Using 'Calibri Light' font instead. Reason: alternative name from document.
@bogandy Thank you for additional information. I have investigated your document as as I can see the only embedded font in your document is Calibri. Here is fonttable.xml fragment from your document:
Lato and Roboto fonts are Microsoft cloud fonts. Aspose.Words does not support cloud fonts and does not use cloud fonts downloaded by MS Office by default.
To get the expected result you have two options:
Embed all required fonts into your MS Word document. Here is your document with all the fonts embedded and the result PDF produced by Aspose.Words. in_allfonts.docx (2.7 MB) out.pdf (32.4 KB)
Another option is to provide Aspos.Words with the required fonts, by specifying their location. On my side cloud fonts are downloaded into the following folder: C:\Users\alexe\AppData\Local\Microsoft\FontCache\4\CloudFonts. If specify this folder as font source Aspose.Words uses Lato font:
doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsSources(
new FontSourceBase[] {
new SystemFontSource(1),
new FolderFontSource("C:\\Users\\alexe\\AppData\\Local\\Microsoft\\FontCache\\4\\CloudFonts", true, 2)});
@bogandy You can also check if the particular font is embedded into the document using FontInfo. getEmbeddedFont method. It returns null if the font is not embedded.
in addition, see Document.getFontInfos property to get font infos read from from the document.