Document Conversion with Foreign Fonts

1 Answer 16 Views
UI for ASP.NET AJAX in ASP.NET MVC Window
David
Top achievements
Rank 1
David asked on 02 May 2025, 05:30 PM

Hello,

I am trying to generate a solution for processing Word .DOCX documents, adding some headers and footer and then saving them as a PDF.  My original code used Aspose libraries to accomplish this.  Our current version is many years old and outside the update path, their recent releases seem to handle this, so I know Telerik handles some of the same functionality and was considering standardizing on Telerik and re-writing the code.

I created a real simple example as a test to just read in the .docx as a stream and then export as a PDF.  The PDF seems to be corrupted or fails with Cambodian, and if I load just a standard English, Spanish or similar document (without doing the header work, etc) it seems to save the PDF fine.

I did not know if there was additional statements I needed to get this to convert/save as a pdf because of the font family.  Thanks

 

            Telerik.Windows.Documents.Flow.Model.RadFlowDocument doc;

            var docxPRovider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
            var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
            TimeSpan timeoutInterval = TimeSpan.FromSeconds(180);

            using (FileStream stream = File.Open(@"C:\Telerik\15-190.docx", FileMode.Open))
            {
                doc = docxPRovider.Import(stream, timeoutInterval);
            }
        
            using (Stream output = File.Open(@"C:\Telerik\Out\15-190.pdf", FileMode.Create))
            {
                pdfProvider.Export(doc, output, timeoutInterval);
            }

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 May 2025, 01:51 PM

Hi, David,

I am sorry to hear that you are facing any difficulties when converting DOCX documents to PDF formats. According to the provided information, I suspect that you are using the .NET Standard version of the WordsProcessing library. Please correct me if I am wrong.

The Telerik Document Processing libraries are available in two versions:

- A version for .NET Framework 4.0 or later

- A version for .NET Standard 2.0

Both versions are available as NuGet packages but with different names. The assemblies for .NET Standard do not contain the word Windows in their name. More information can be found here: Available NuGet Packages

If this is not the case, please let me know.

I have tested in a .NET Framework project and converting the DOCX file to PDF format works as expected. However, for the .NET Standard scenario, RadPdfProcessing does not offer a default mechanism to read fonts. The FixedExtensibilityManager class is exposed to help implement this functionality. 

PdfProcessing needs to have access to the font data so that it can read it and add it to the PDF file. That is why, to allow the library to create and use fonts, you will need to provide an implementation of the FontsProviderBase abstract class and set this implementation to the FontsProvider property of the FixedExtensibilityManager.

You can find a detailed FixedExtensibilityManager and FontsProvider descripiton and implementaion in the How to implement a FontsProvider article. It would be necessary to adjust it according to the used fonts in the specific document.

Please give this approach a try and let me know whether it has a positive impact on the exported document on your end.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
UI for ASP.NET AJAX in ASP.NET MVC Window
Asked by
David
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or