Embedding Helvetica Font File into PDF | Word DOCX to PDF Conversion | Set Custom Fonts Folder | C# .NET

Dear Sir or Madam,

We use Helvetica font in our application. Recently we noticed that it outputs fin in Word document and doesn’t in the PDF document. The simple project is attached.Helvetica.zip (44.0 KB)

Regards,
Alex

@AlexanderNovickov,

Please try the following code:

Document doc = new Document("C:\\Temp\\Helvetica\\in.docx");

FontSettings fontSettings = new FontSettings();
AddCustomFontsFolder(fontSettings, @"C:\Temp\Helvetica\Helvetica\");
doc.FontSettings = fontSettings;

doc.Save(@"C:\Temp\Helvetica\\21.2.docx");
doc.Save(@"C:\Temp\Helvetica\\21.2.pdf");

private static void AddCustomFontsFolder(FontSettings fontSettings, string folder)
{
    ArrayList fontSources = new ArrayList(fontSettings.GetFontsSources());

    // Add a new folder source which will instruct Aspose.Words to search the following folder for fonts.
    FolderFontSource folderFontSource = new FolderFontSource(folder, true);

    // Add the custom folder which contains our fonts to the list of existing font sources.
    fontSources.Add(folderFontSource);

    // Convert the Arraylist of source back into a primitive array of FontSource objects.
    FontSourceBase[] updatedFontSources = (FontSourceBase[])fontSources.ToArray(typeof(FontSourceBase));

    // Apply the new set of font sources to use.
    fontSettings.SetFontsSources(updatedFontSources);
}

Hi Awais,

Thank you for your reply, it works.

Regards,
Alex