Articles in this section
Category / Section

How to resolve font problems during PowerPoint to PDF or image conversion?

5 mins read

Syncfusion .NET PowerPoint library allows you to convert Presentation file to PDF and image. While performing PowerPoint to PDF/Image conversion, internally Presentation uses the fonts installed in the environment to measure and draw the content of Presentation file during conversion. If a font is not available in the environment, an alternate font will be used. This can lead to differences in the output PDF or image, such as missing text or different font sizes.

What happens if used fonts in Presentation file not available during PowerPoint to PDF/Image?

If font is not installed in the environment, you will face the content will not be preserved in the output PDF/Image as like input Presentation file.

How to resolve font missing problem during PowerPoint to PDF/Image

You can use any one of the suggestions to resolve the problem.

Suggestion 1: Install all the necessary fonts

Install all the necessary fonts in the production environment, which are used in your Presentation file.

Suggestion 2: Substitute alternate fonts

PowerPoint supports event handler to substitute alternate fonts when the necessary fonts not available in the production environment during PowerPoint to PDF/image conversion.
The following code example shows how to add event handler to set alternate font when the specified font is not installed in the machine. You can use same event handler for PowerPoint to Image conversion also.

C#:

//Load the PowerPoint presentation as stream
using (FileStream fileStream = new FileStream("Sample.pptx", FileMode.Create))
{
   //Load the PowerPoint presentation from stream
   using (IPresentation pptxDoc = Presentation.Open(fileStream))
   {
       // Initializes the 'SubstituteFont' event to set the replacement font
       pptxDoc.FontSettings.SubstituteFont += SubstituteFont;
       //Convert the PowerPoint presentation to PDF file
       PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
       //Create new instance of file stream
       FileStream pdfStream = new FileStream("Output.pdf", FileMode.Create);
       //Save the generated PDF to file stream
       pdfDocument.Save(pdfStream);
       //Release all resources
       pdfStream.Dispose();
       pdfDocument.Close(true);
   }
}

Event to set alternate installed font

You can use any other alternate installed font names instead of missed fonts during PowerPoint to PDF/Image conversion.
The following code example shows how to set the alternate installed font name when converting a Presentation file to PDF/Image.

C#:

private void SubstituteFont(object sender, SubstituteFontEventArgs args)
{
   //Sets the alternate font when a specified font is not installed in the production environment
   //If "Arial Unicode MS" font is not installed, then it uses the "Arial" font
   //For other missing fonts, uses the "Times New Roman"
   if (args.OriginalFontName == "Arial Unicode MS")
       args.AlternateFontName = "Arial";
   else
       args.AlternateFontName = "Times New Roman";
}

You can download a complete working sample from GitHub.

Event to set alternate font without installing in machine

You can also use any other alternate fonts without installing during PowerPoint to PDF/Image conversion.

Note: If the font is installed but the style type of the font is missing, the font will be thrown in the event handler. For example, if Cambria italic is installed on your machine but Cambria bold is used in the Presentation file, then Cambria bold will be thrown in the event.

C#:

private void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args)
{
   //Sets the alternate font when a specified font is not installed in the production environment
   if (args.OrignalFontName == "Arial Unicode MS" && args.FontStyle == FontStyle.Regular)
       args.AlternateFontStream = new FileStream("Arial.TTF", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
   else
          args.AlternateFontStream = new FileStream("Calibri.TTF", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}

You can download a complete working sample from GitHub.

What to do if still facing any preservation difference in PDF, after using above solutions?

If you are still facing any preservation issues after using the above solutions, it is possible that your machine does not contain the respective font and the PDF viewer is unable to load the content properly. To resolve this, you can embed the fonts in the PDF document itself. This will allow you to transfer the PDF documents to any device without experiencing any content preservation differences.

Embed Subset Fonts

This setting allows you to embed the particular font information (glyphs) from the TrueType fonts used for the rendered characters in converted PDF document.
The following code sample shows how to embed the TrueType fonts into the converted PDF document.

C#:

IPresentation pptxDoc = Presentation.Open("Template.pptx");
//Instantiation of PresentationToPdfConverterSettings
PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
// Sets true to embed TrueType fonts
settings.EmbedFonts = true;
//Convert Presentation to PDF
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);

Embed Complete Fonts

This setting allows you to embed the complete font information (glyphs) from the TrueType fonts used in converted PDF document.
The following code sample shows how to embed the complete TrueType fonts into the converted PDF document.

C#:

IPresentation pptxDoc = Presentation.Open("Template.pptx");
//Instantiation of PresentationToPdfConverterSettings
PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
// Sets true to embed TrueType fonts
settings.EmbedCompleteFonts = true;
//Convert Presentation to PDF
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);

Take a moment to peruse the documentation, where you can find basic presentation document processing options along with features like clone and merge slides and encrypt and decrypt PowerPoint presentation and most importantly PDF and image conversion with code examples.

Explore more about the rich set of Syncfusion PowerPoint Framework features.

Conclusion

I hope you enjoyed learning how to resolve font problems during PowerPoint to PDF or image conversion using C#.

You can refer to our .NET PowerPoint Library feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied