|
| 1 | +--- |
| 2 | +title: Resolving missing content after HTML/DOCX to PDF conversion with WordsProcessing in .NET Standard |
| 3 | +description: Learn how to handle missing content in PDF files generated using RadWordsProcessing for Document Processing due to fonts' specifics. |
| 4 | +type: how-to |
| 5 | +page_title: Fixing Missing Content in PDFs Generated with RadWordsProcessing |
| 6 | +slug: missing-content-word-to-pdf-radwordsprocessing |
| 7 | +tags: words, processing, document, pdf, font, custom, fixedextensibilitymanager, fontsprovider, netstandard |
| 8 | +res_type: kb |
| 9 | +ticketid: 1690314 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| ---- | ---- | ---- | |
| 16 | +| 2025.2.520| Telerik Document Processing|[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +When generating PDF files using [RadWordsProcessing]({%slug radwordsprocessing-overview%}) 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]({%slug radpdfprocessing-overview%}) does not have a default mechanism to read fonts. To resolve this issue, the font data must be provided explicitly using the **FixedExtensibilityManager** and a custom implementation of the [FontsProviderBase]({%slug pdfprocessing-implement-fontsprovider%}) class. |
| 21 | + |
| 22 | +This knowledge base article also answers the following questions: |
| 23 | +- Why is some text missing in RadWordsProcessing-generated PDFs? |
| 24 | +- How do I add support for custom fonts in RadPdfProcessing? |
| 25 | +- How can I fix missing content in exported PDF files? |
| 26 | + |
| 27 | +## Solution |
| 28 | + |
| 29 | +To ensure that custom fonts are correctly embedded in the PDF files: |
| 30 | + |
| 31 | +1. **Implement a FontsProvider**: |
| 32 | + Create a custom class that inherits from `FontsProviderBase` and override the `GetFontData` method to provide the font data for the required fonts. |
| 33 | + |
| 34 | + Example implementation: |
| 35 | + ```csharp |
| 36 | + internal class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase |
| 37 | + { |
| 38 | + private string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); |
| 39 | + |
| 40 | + public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties) |
| 41 | + { |
| 42 | + string fontFamilyName = fontProperties.FontFamilyName; |
| 43 | + bool isBold = fontProperties.FontWeight == Telerik.Documents.Core.Fonts.FontWeights.Bold; |
| 44 | + if (fontFamilyName == "David") |
| 45 | + { |
| 46 | + fontFolder = @"..\..\..\"; |
| 47 | + var fontData = this.GetFontDataFromFontFolder("David.ttf"); |
| 48 | + fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); |
| 49 | + return fontData; |
| 50 | + } |
| 51 | + |
| 52 | + Debug.WriteLine($"Font not found: {fontFamilyName} (Bold: {isBold})"); |
| 53 | + return null; |
| 54 | + } |
| 55 | + |
| 56 | + private byte[] GetFontDataFromFontFolder(string fontFileName) |
| 57 | + { |
| 58 | + using (FileStream fileStream = File.OpenRead(this.fontFolder + "\\" + fontFileName)) |
| 59 | + { |
| 60 | + using (MemoryStream memoryStream = new MemoryStream()) |
| 61 | + { |
| 62 | + fileStream.CopyTo(memoryStream); |
| 63 | + return memoryStream.ToArray(); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + ``` |
| 69 | + |
| 70 | +2. **Set the FontsProvider in FixedExtensibilityManager**: |
| 71 | + Assign the custom FontsProvider implementation to the `FontsProvider` property of `FixedExtensibilityManager`. |
| 72 | + |
| 73 | + ```csharp |
| 74 | + Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider(); |
| 75 | + Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider; |
| 76 | + ``` |
| 77 | + |
| 78 | +3. **Ensure Font Availability**: |
| 79 | + Download and include all necessary font files (e.g., `David.ttf`) used in your document. Place them in an accessible location relative to your application. |
| 80 | + |
| 81 | +4. **Rebuild and Run**: |
| 82 | + 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. |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +- [Implementing FontsProvider]({%slug pdfprocessing-implement-fontsprovider%}) |
| 87 | +- [Standard Fonts]({%slug radpdfprocessing-concepts-fonts%}) |
0 commit comments