I have a RadFlowDocument that I am exporting to PDF via the standard flow PDFFormatProvider. If the document has some text that used the Arial Narrow font that is either bold, italicized or both the PDF output is always showing just plain Arial Narrow. This seems to be the only font that is having this problem.
Has anyone else encountered this or have any suggestions on how to fix it?
4 Answers, 1 is accepted
Thank you for contacting us about this issue.
PdfProcessing uses internally Typeface.TryGetGlyphTypeface method in order to access font files installed on the machine. However, while debugging the issue I have noticed that there is a bug in this method and it always returns the normal "Arial Narrow" font file path even when we require the bold or italic version of this font. A similar issue with this font is discussed in this MSDN forum post.
You can easily workaround this issue by simply register the correct font files before doing the PDF export. I am attaching a demo project that shows how exactly this can be achieved. A few words about this demo:
- It is a console application.
- Before exporting the PDF the RegisterWrongFontPaths method is executed. This method basically gets the bytes of the correct font files and registers them for the corresponding font properties.
- Alternatively, you can embed the font files in you project and access the embedded font file bytes. This way you will not access the fonts from the file system and the program will be working even on machines where the "Arial Narrow" font files are not installed.
- When the demo program finishes, it opens the exported PDF file, so that you can view the result.
I hope this information is helpful. If you have any other questions or concerns please do not hesitate to contact us again.
the Telerik team
Thank you for your reply. This approach works perfectly. Thanks!
Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider _docxFormatProvider = new Telerik.Windows.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider();
Telerik.Windows.Documents.Model.RadDocument radDocument = _docxFormatProvider.Import(System.IO.File.ReadAllBytes("input.docx"));
Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider _pdfFormatProvider = new Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider();
We have tried to use Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider, but some parts of document wasn't formatted correctly (position of a table, ..), so we need a solution for Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider.
The internal implementation of the PdfFormatoProvider used in the demo project Deyan has provided uses the PdfProcessing library when exporting to PDF. The mechanism to register fonts in the PdfProcessing library, provides custom implementation allowing to map them by name, weight and style. However, the PdfFormatoProvider, part of the RadRichTextBox control, has different implementation and the mechanism for font registration is built and dependent on the .NET framework. For this reason, the solution from the demo project wouldn't work for this format provider. This issue has already been discussed in the forum, however, since it's related to the .NET framework implementation, I am afraid that we couldn't find any workaround to provide you with.