Fallback fonts in PowerPoint to PDF conversion
2 Dec 202423 minutes to read
During PowerPoint to PDF conversions, if a glyph of the input text is unavailable in the specified font, the text will not be rendered properly. To address this, the Syncfusion® PowerPoint (Presentation) library allows users to specify fallback fonts. When a glyph is missing, the library will use one of the fallback fonts to render the text correctly in the output PDF document.
Users can configure fallback fonts in the following ways:
- Initialize default fallback fonts.
- Set custom fonts as fallback fonts for specific script types, including Arabic, Hebrew, Chinese, Japanese, and more.
- Set custom fonts as fallback fonts for a particular range of Unicode text.
NOTE
Presentation internally uses user-initialized or specified fallback fonts for Unicode characters during PowerPoint to PDF conversion. Therefore, the specified fallback fonts must be installed in the production environment. Otherwise, it will not render the text properly using the fallback fonts.
Initialize default fallback fonts
The following code example demonstrates how to initialize a default fallback font while converting a PowerPoint presentation to PDF. The InitializeDefault API sets the default fallback fonts for specific script types like Arabic, Hebrew, Chinese, Japanese etc.
NOTE
Refer to the appropriate tabs in the code snippets section: C# [Cross-platform] for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; C# [Windows-specific] for WinForms and WPF; VB.NET [Windows-specific] for VB.NET applications.
//Load the PowerPoint presentation into stream.
using (FileStream fileStreamInput = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault();
//Create the MemoryStream to save the converted PDF.
using (MemoryStream pdfStream = new MemoryStream())
{
//Convert the PowerPoint document to PDF document.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
{
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
}
//Create the output PDF file stream.
using (FileStream fileStreamOutput = File.Create("Output.pdf"))
{
//Copy the converted PDF stream into created output PDF stream.
pdfStream.CopyTo(fileStreamOutput);
}
}
}
}
//Opens a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Initialize the conversion settings.
PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings();
//Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true;
//Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault();
//Converts the PowerPoint Presentation into PDF document with Portable rendering option.
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
//Saves the PDF document.
pdfDocument.Save("Sample.pdf");
//Closes the PDF document.
pdfDocument.Close(true);
//Closes the Presentation.
pptxDoc.Close();
'Opens a PowerPoint Presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Initialize the conversion settings.
Dim pdfConverterSettings As PresentationToPdfConverterSettings = new PresentationToPdfConverterSettings()
'Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true
'Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault
'Converts the PowerPoint Presentation into PDF document.
Dim pdfDocument As PdfDocument = PresentationToPdfConverter.Convert(pptxDoc)
'Saves the PDF document.
pdfDocument.Save("Sample.pdf")
'Closes the PDF document.
pdfDocument.Close(True)
'Closes the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Fallback fonts based on script type
The following code example demonstrates how a user can add fallback fonts based on the script types, which Presentation considers internally when converting a PowerPoint presentation to PDF.
//Load the PowerPoint presentation into stream.
using (FileStream fileStreamInput = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Adds fallback font for "Arabic" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman");
//Adds fallback font for "Hebrew" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New");
//Adds fallback font for "Hindi" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI");
//Adds fallback font for "Chinese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU");
//Adds fallback font for "Japanese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho");
//Adds fallback font for "Thai" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif");
//Adds fallback font for "Korean" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang");
//Create the MemoryStream to save the converted PDF.
using (MemoryStream pdfStream = new MemoryStream())
{
//Convert the PowerPoint document to PDF document.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
{
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
}
//Create the output PDF file stream.
using (FileStream fileStreamOutput = File.Create("Output.pdf"))
{
//Copy the converted PDF stream into created output PDF stream.
pdfStream.CopyTo(fileStreamOutput);
}
}
}
}
//Opens a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Initialize the conversion settings.
PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings();
//Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true;
//Adds fallback font for "Arabic" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman");
//Adds fallback font for "Hebrew" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New");
//Adds fallback font for "Hindi" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI");
//Adds fallback font for "Chinese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU");
//Adds fallback font for "Japanese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho");
//Adds fallback font for "Thai" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif");
//Adds fallback font for "Korean" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang");
//Converts the PowerPoint Presentation into PDF document with Portable rendering option.
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
//Saves the PDF document.
pdfDocument.Save("Sample.pdf");
//Closes the PDF document.
pdfDocument.Close(true);
//Closes the Presentation.
pptxDoc.Close();
'Opens a PowerPoint Presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Initialize the conversion settings.
Dim pdfConverterSettings As PresentationToPdfConverterSettings = new PresentationToPdfConverterSettings()
'Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true
'Adds fallback font for "Arabic" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman")
'Adds fallback font for "Hebrew" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial,Courier New")
'Adds fallback font for "Hindi" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI")
'Adds fallback font for "Chinese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU")
'Adds fallback font for "Japanese" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho")
'Adds fallback font for "Thai" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif")
'Adds fallback font for "Korean" script type.
pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang")
'Converts the PowerPoint Presentation into PDF document.
Dim pdfDocument As PdfDocument = PresentationToPdfConverter.Convert(pptxDoc)
'Saves the PDF document.
pdfDocument.Save("Sample.pdf")
'Closes the PDF document.
pdfDocument.Close(True)
'Closes the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Fallback fonts for range of Unicode text
Users can set fallback fonts for specific Unicode range of text to be used in presentation to PDF conversion.
The following code example demonstrates how users can add fallback fonts by using a specific Unicode range of text that Presentation considers internally while converting a PowerPoint presentation to PDF.
//Load the PowerPoint presentation into stream.
using (FileStream fileStreamInput = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Adds fallback font for specific unicode range.
// Arabic.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial"));
// Hebrew.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial"));
// Hindi.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal"));
// Chinese.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian"));
// Japanese.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho"));
// Korean.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic"));
//Create the MemoryStream to save the converted PDF.
using (MemoryStream pdfStream = new MemoryStream())
{
//Convert the PowerPoint document to PDF document.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
{
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
}
//Create the output PDF file stream.
using (FileStream fileStreamOutput = File.Create("Output.pdf"))
{
//Copy the converted PDF stream into created output PDF stream.
pdfStream.CopyTo(fileStreamOutput);
}
}
}
}
//Opens a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Initialize the conversion settings.
PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings();
//Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true;
//Adds fallback font for specific unicode range.
// Arabic.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial"));
// Hebrew.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial"));
// Hindi.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal"));
// Chinese.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian"));
// Japanese.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho"));
// Korean.
pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic"));
//Converts the PowerPoint Presentation into PDF document.
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
//Saves the PDF document.
pdfDocument.Save("Sample.pdf");
//Closes the PDF document.
pdfDocument.Close(true);
//Closes the Presentation.
pptxDoc.Close();
'Opens a PowerPoint Presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Initialize the conversion settings.
Dim pdfConverterSettings As PresentationToPdfConverterSettings = new PresentationToPdfConverterSettings()
'Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true
'Adds fallback font for specific unicode range.
' Arabic.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(1536, 1791, "Arial"))
' Hebrew.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(1424, 1535, "Arial"))
' Hindi.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(2304, 2431, "Mangal"))
' Chinese.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(19968, 40959, "DengXian"))
' Japanese.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(12352, 12447, "MS Mincho"))
' Korean.
pptxDoc.FontSettings.FallbackFonts.Add(New FallbackFont(44032, 55203, "Malgun Gothic"))
'Converts the PowerPoint Presentation into PDF document.
Dim pdfDocument As PdfDocument = PresentationToPdfConverter.Convert(pptxDoc)
'Saves the PDF document.
pdfDocument.Save("Sample.pdf")
'Closes the PDF document.
pdfDocument.Close(True)
'Closes the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Modify the exiting fallback fonts
The following code example demonstrates how user can modify or customize the existing fallback fonts using FontNames API while converting a PowerPoint presentation to PDF.
//Load the PowerPoint presentation into stream.
using (FileStream fileStreamInput = new FileStream("Template.pptx", FileMode.Open, FileAccess.Read))
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault();
// Customize a default fallback font name.
FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts;
foreach (FallbackFont fallbackFont in fallbackFonts)
{
//Customize a default fallback font name as "David" for the Hebrew script.
if (fallbackFont.ScriptType == ScriptType.Hebrew)
fallbackFont.FontNames = "David";
}
//Create the MemoryStream to save the converted PDF.
using (MemoryStream pdfStream = new MemoryStream())
{
//Convert the PowerPoint document to PDF document.
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
{
//Save the converted PDF document to MemoryStream.
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
}
//Create the output PDF file stream.
using (FileStream fileStreamOutput = File.Create("Output.pdf"))
{
//Copy the converted PDF stream into created output PDF stream.
pdfStream.CopyTo(fileStreamOutput);
}
}
}
}
//Opens a PowerPoint Presentation.
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Initialize the conversion settings.
PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings();
//Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true;
//Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault();
// Customize a default fallback font name.
FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts;
foreach (FallbackFont fallbackFont in fallbackFonts)
{
//Customize a default fallback font name as "David" for the Hebrew script.
if (fallbackFont.ScriptType == ScriptType.Hebrew)
fallbackFont.FontNames = "David";
}
//Converts the PowerPoint Presentation into PDF document.
PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc);
//Saves the PDF document.
pdfDocument.Save("Sample.pdf");
//Closes the PDF document.
pdfDocument.Close(true);
//Closes the Presentation.
pptxDoc.Close();
'Opens a PowerPoint Presentation.
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")
'Initialize the conversion settings.
Dim pdfConverterSettings As PresentationToPdfConverterSettings = new PresentationToPdfConverterSettings()
'Enable the portable rendering.
pdfConverterSettings.EnablePortableRendering = true
'Use a sets of default FallbackFont collection to IPresentation.
pptxDoc.FontSettings.FallbackFonts.InitializeDefault()
'Customize a default fallback font name.
Dim fallbackFonts As FallbackFonts = pptxDoc.FontSettings.FallbackFonts
For Each fallbackFont As FallbackFont In fallbackFonts
'Customize a default fallback font name as "David" for the Hebrew script.
If fallbackFont.ScriptType = ScriptType.Hebrew Then
fallbackFont.FontNames = "David"
End If
Next
'Converts the PowerPoint Presentation into PDF document.
Dim pdfDocument As PdfDocument = PresentationToPdfConverter.Convert(pptxDoc)
'Saves the PDF document.
pdfDocument.Save("Sample.pdf")
'Closes the PDF document.
pdfDocument.Close(True)
'Closes the Presentation.
pptxDoc.Close()
You can download a complete working sample from GitHub.
Supported script types
The following table illustrates the supported script types by the .NET PowerPoint library (Presentation) in Presentation to PDF conversion.
Script types | Ranges | Default fallback fonts considered in InitializeDefault() API |
---|---|---|
Arabic |
0x0600 - 0x06ff 0x0750 - 0x077f 0x08a0 - 0x08ff 0xfb50 - 0xfdff 0xfe70 - 0xfeff |
Arial, Times New Roman, Microsoft Uighur |
Hebrew |
0x0590 - 0x05ff 0xfb1d - 0xfb4f |
Arial, Times New Roman, David |
Hindi |
0x0900 - 0x097F 0xa8e0 - 0xa8ff 0x1cd0 - 0x1cff |
Mangal, Utsaah |
Chinese |
0x4E00 - 0x9FFF 0x3400 - 0x4DBF 0xd840 - 0xd869 0xdc00 - 0xdedf 0xA960 - 0xA97F 0xFF00 - 0xFFEF 0x3000 - 0x303F |
DengXian, MingLiU, MS Gothic |
Japanese |
0x30A0 - 0x30FF 0x3040 - 0x309F |
Yu Mincho, MS Mincho |
Thai | 0x0E00 - 0x0E7F | Tahoma, Microsoft Sans Serif |
Korean |
0xAC00 - 0xD7A3 0x1100 - 0x11FF 0x3130 - 0x318F 0xA960 - 0xA97F 0xD7B0 - 0xD7FF 0xAC00 - 0xD7AF |
Malgun Gothic, Batang |