Resolving missing content after HTML/DOCX to PDF conversion with WordsProcessing in .NET Standard
Environment
| Version | Product | Author |
|---|---|---|
| 2025.2.520 | Telerik Document Processing | Desislava Yordanova |
Description
When you generate PDF files with RadWordsProcessing from HTML or DOCX templates, specific content may be missing in the output due to the fonts used in the document. This occurs because the .NET Standard version of RadPdfProcessing does not have a default mechanism to read fonts. To resolve this issue, provide the font data explicitly through the FixedExtensibilityManager and a custom implementation of the FontsProviderBase class.
This knowledge base article also answers the following questions:
- Why is some text missing in RadWordsProcessing-generated PDFs?
- How do I add support for custom fonts in RadPdfProcessing?
- How do I fix missing content in exported PDF files?
Solution
To ensure that custom fonts are correctly embedded in the PDF files:
-
Implement a FontsProvider: Create a custom class that inherits from
FontsProviderBaseand override theGetFontDatamethod to provide the font data for the required fonts.The following example shows the implementation:
csharpinternal class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase { private string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties) { string fontFamilyName = fontProperties.FontFamilyName; bool isBold = fontProperties.FontWeight == Telerik.Documents.Core.Fonts.FontWeights.Bold; if (fontFamilyName == "David") { fontFolder = @"..\..\..\"; var fontData = this.GetFontDataFromFontFolder("David.ttf"); fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); return fontData; } Debug.WriteLine($"Font not found: {fontFamilyName} (Bold: {isBold})"); return null; } private byte[] GetFontDataFromFontFolder(string fontFileName) { using (FileStream fileStream = File.OpenRead(this.fontFolder + "\\" + fontFileName)) { using (MemoryStream memoryStream = new MemoryStream()) { fileStream.CopyTo(memoryStream); return memoryStream.ToArray(); } } } } -
Set the FontsProvider in FixedExtensibilityManager: Assign the custom FontsProvider implementation to the
FontsProviderproperty ofFixedExtensibilityManager.csharpTelerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider(); Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider; -
Ensure Font Availability: Download and include all necessary font files (for example,
David.ttf) used in your document. Place them in an accessible location relative to your application. -
Rebuild and Run: Integrate the FontsProvider implementation into your application, rebuild, and test the PDF generation process. The previously missing content should now appear in the exported PDF files.