Save as PDF - Roboto Font Incorrect

Please see attached sample project. In order to run this sample you will need the Roboto font installed (https://fonts.google.com/specimen/Roboto).
In the sample project when the “Agenda.docx” file is saved to PDF using Aspose.Words the Roboto regular font comes out as “Roboto thin” - causing the text to be lighter. If I open the same file in Word 2016 and save as PDF the font gets saved as “Roboto light” - which is still not quite correct - but looks much more like the font used in the Word document.
In my sample I have used “pdfSaveOptions.Compliance = PdfCompliance.PdfA1b” as this is what we use in our actual project. However I find that I get the same behaviour when I remove this option.
How can we get the PDF produced by Aspose to use the correct Roboto regular font?
Thanks,
David

Hi David,

Thanks for your inquiry.

We have tested the scenario using latest version of Aspose.Words for .NET 17.4 and have not found the shared issue. Please upgrade to the latest version of Aspose.Words for .NET 17.4. We have attached the output PDF with this post for your kind reference.

Hello Tahir,

Thanks for your reply. I did as you suggested and upgraded to version 17.4. Unfortunately it made no difference to the reported issue. I have attached the following:

  1. An upgraded version of the sample project using Aspose.Words version 17.4
  2. A copy of the PDF that it generates on my machine.
  3. A copy of my installed fonts.

There must be something different in our setups that is not allowing you to replicate the problem.

I get the problem on my local development machine and on our server in production.

Kind regards,

David

Hi David,

Thanks for your inquiry. We downloaded the fonts from shared link and installed them. We tested the scenario at Windows 7 (64 bit). Please make sure that you are using the same font.

Could you please share your operating system detail here for further testing? We will investigate the issue and and provide you more information on this.

I am using Windows 10 64 bit on my development machine and Windows Server 2012 64 bit on my production server. Both exhibit the reported problem.

I tried uninstalling the font my development machine, clearing the font cache and restarting my machine. When I ran the code to create the PDF from the Word document it still contained the Roboto-Thin(embedded) font.

I also tried reinstalling the Roboto font - but this time only downloading and installing Roboto regular. Still I ended up with the same problem in the produced PDF.

Hi David,

Thanks for your inquiry. We have tested the scenario at Windows 10 using shared document and fonts. We have not found the shared issue. Please make sure that you are using the same document and fonts.

We have attached the input and output documents and fonts with this post. Please remove fonts from your system, install the attached fonts, and convert your document to PDF. Moreover, please apply the license before converting document.

Please request for 30-days temporary license from here:

Get temporary license

Please refer to the following article about applying license.

Apply a License

Hi Tahir,

I have done exactly as you requested and it has made no difference. I have attached to this email a copy of the document generated by Aspose and a copy generated when I save the document as PDF from Word 2016. You can see that Aspose still does not correctly render the Roboto font.

Hi Tahir,

I have done exactly as you requested and it has made no difference. I have attached to this email a copy of the document generated by Aspose and a copy generated when I save the document as PDF from Word 2016. You can see that Aspose still does not correctly render the Roboto font.

Kind regards,

David

Hi Tahir,

I have done exactly as you requested and it has made no difference. I have attached to this email a copy of the document generated by Aspose and a copy generated when I save the document as PDF from Word 2016. You can see that Aspose still does not correctly render the Roboto font.

Kind regards,

David

Hi David,

Thanks for your inquiry. Following code example shows how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts. Please put the Roboto fonts inside “C:\Roboto” folder, try following code example and let us know if you still face problem.

Moreover, please implement IWarningCallback interface to be notified of any font substitution during document save. If you face any font substitution, please share it here for our reference.

Document doc = new Document(MyDir + "input.docx");
// Retrieve the array of environment-dependent font sources that are searched by default. For example this will contain a "Windows\Fonts\" source on a Windows machines.
// We add this array to a new ArrayList to make adding or removing font entries much easier.
FontSettings fontSettings = new FontSettings();
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("C:\\Roboto\\", 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);
doc.FontSettings = fontSettings;
doc.WarningCallback = new HandleDocumentWarnings();
doc.Save(MyDir + "Out.pdf");
public class HandleDocumentWarnings : IWarningCallback
{
    /// 
    /// Our callback only needs to implement the "Warning" method. This method is called whenever there is a
    /// potential issue during document processing. The callback can be set to listen for warnings generated during document
    /// load and/or document save.
    /// 
    public void Warning(WarningInfo info)
    {
        // We are only interested in fonts being substituted.
        if (info.WarningType == WarningType.FontSubstitution)
        {
            Console.WriteLine("Font substitution: " + info.Description);
        }
    }
}

Hello Tahir,

I did not get any font substution warnings, however loading the fonts directly from the custom folder seems to have resolved my problem. I will implement this solution in our application. Thanks for all your help in resolving this problem.

Kind regards,

David

Hi David,

Thanks for your feedback. You were facing this issue because of missing fonts in Windows/Fonts directory. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hello Tahir,

No I was not definitely not missing fonts in the Windows Fonts directory. Something else was going on. I have attached a screen shot showing you the contents of the C:\Windows\Fonts\Roboto folder on my development PC.

Kind regards,

David

Hi David,

Thanks for your inquiry. Please implement IWarningCallback interface and do not use custom folder for fonts. Please share if you get any font substitution warning.

Hi Tahir,

I already implemented IWarningCallback interface with custom folder for fonts. There were no font substitution warnings.

I am happy with the current solution - using custom folder for fonts. However I wanted to make sure that you were aware that there is some other issue that is impacting the use of the Roboto font. It does not seem to affect any other fonts.

Kind regards,

David

Hello Tahir,

In my previous reply I meant to say:

“I already implemented IWarningCallback interface without custom folder for fonts. There were no font substitution warnings.”

Regards,

David

Hi David,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.