EmbedFullFonts not working correctly

Aspose.Words.Document doc2 = new Aspose.Words.Document(stream);
Aspose.Words.Saving.PdfSaveOptions po = new Aspose.Words.Saving.PdfSaveOptions();
po.EmbedFullFonts = true;
po.SaveFormat = Aspose.Words.SaveFormat.Pdf;
doc2.Save(pdf_stream, po);

We need to convert word document to pdf with fonts embedded. This option EmbedFullFonts is not working. Is there any other option or should I use it differently then I did?

https://drive.akademika.si/d/s/trUoypzqNe9K2NdrGOK9MPJUY7JCX9tp/pSItRqsv1zS2lcAAgp2XIgTrYP9dGlhc-K7DgV3Sifgo
Here is an example.

Thanks in advance!

@leon.oven can you please check that all the fonts are installed and available in your running environment. You can easily verify it by implementing the interface IWarningCallback:

Document doc = new Document("C:\\Temp\\input.docx", new LoadOptions
{
    LoadFormat = LoadFormat.Docx,
    WarningCallback = new ConversionIssueCallBack(),
});
public class ConversionIssueCallBack : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine($"{ info.Description}");
    }
}

@leon.oven The problem occurs because your document uses cloud font - Open Sans. Aspose.Words does not load cloud fonts, so to get the desired output you should either embed the font into the MS Word document or put this font into the folder and specify it as fonts source .

FYI @eduardo.canal

1 Like

Hi,

I tried to set font source but it is still not working as expected. I tried to set setfontssourcers and setfontsfolder, both at once and separate but no combination works. Can someone try it with my docx example from first post? Thank you very much.

Aspose.Words.Document doc2 = new Aspose.Words.Document(msFile); FontSettings FontSettings = new FontSettings();
FileFontSource fileFontSource1 = new FileFontSource("D:\\Temp\\fonts\\OpenSans-Bold.ttf", 0);
FileFontSource fileFontSource2 = new FileFontSource("D:\\Temp\\fonts\\OpenSans-Regular.ttf", 0);
FontSettings.SetFontsSources(new FontSourceBase[] { fileFontSource1, fileFontSource2 });
FontSettings.SetFontsFolder(@"D:\Temp\fonts\", false);
doc.FontSettings = FontSettings;

doc2.Save(ConfigurationManager.AppSettings["OutFolder"] + "\\" + file.Name + ".pdf");

Regards,
Leon

@leon.oven please check the following code it produces the expected output, also embed the fonts in the resultant PDF document:

string _winFontFolder = @"C:\Windows\Fonts"; 
string _fontFolder = @"C:\Temp\fonts\Open-sans";
FontSettings.DefaultInstance.SetFontsFolders(new[] { _winFontFolder, _fontFolder }, true);

Document doc = new Document("C:\\Temp\\input.docx", new Aspose.Words.Loading.LoadOptions
{
    WarningCallback = new ConversionIssueCallBack()
});

PdfSaveOptions opt = new PdfSaveOptions();
opt.ExportDocumentStructure = true;
opt.SaveFormat = SaveFormat.Pdf;
opt.AllowEmbeddingPostScriptFonts = true;
opt.UpdateFields = false;
opt.PreserveFormFields = true;
opt.HeaderFooterBookmarksExportMode = HeaderFooterBookmarksExportMode.All;
opt.OpenHyperlinksInNewWindow = true;
opt.CustomPropertiesExport = PdfCustomPropertiesExport.Standard;
opt.EmbedFullFonts = true;
opt.UseCoreFonts = true;
opt.FontEmbeddingMode = PdfFontEmbeddingMode.EmbedNonstandard;

doc.Save("C:\\Temp\\output.pdf", opt);
public class ConversionIssueCallBack : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        Console.WriteLine($"{ info.Description}");
    }
}

Hi,

It is working now. The problem was in missing open sans light fonts in source folder. Thank you very much for your help.

Regards,
Leon

1 Like