i lose special caracter and style while exporting word to pdf

3 Answers 823 Views
General Discussions PdfProcessing SpreadStreamProcessing WordsProcessing
wajdi
Top achievements
Rank 1
Iron
wajdi asked on 07 Sep 2021, 07:51 AM | edited on 07 Sep 2021, 03:14 PM

hello,

i'm working on function to export word to PDF, and the result is inconherent, i'm loosing the special caracter like "é"  , "ô". the document is in french language, also the style of wording of the document.

this is my function, any suggestion to resolve it?

regards.


public static void ConvertWordtopdf(string input, string output)
        {
            var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
            var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();


            try
            {
                //var docxBytes = File.ReadAllBytes(input);
                var docxBytes = System.IO.File.OpenRead(input);
                RadFlowDocument docx = docxProvider.Import(docxBytes);

                var pdfBytes = pdfProvider.Export(docx);
                File.WriteAllBytes(output, pdfBytes);

                docxBytes.Dispose();
                
            }
            catch (Exception ex)
            {
                ;
            }
        }

3 Answers, 1 is accepted

Sort by
1
Martin
Telerik team
answered on 08 Sep 2021, 07:24 AM

Hi Wajdi,

Such behavior is usually observed when using the Document Processing`s .NET Standard assemblies in order to export to PDF format documents containing fonts different than the Standard Fonts. In such cases, the FontsProvider property inside the FixedExtensibilityManager has to be set. For more information check the FixedExtensibilityManager in the PdfProcessing`s Cross-Platform Support. We have a good SDK example in our GitHub repository demonstrating this functionality as well: ConvertDocuments.

If this is not the case or the suggested information doesn't help, please, provide us with more details on the specific scenario.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

wajdi
Top achievements
Rank 1
Iron
commented on 08 Sep 2021, 09:46 AM | edited

Hello Martin, thank you for your help,

the override function GetFontData resolved the special caracter but not the fontstyle, this is my code bellow, i'm using time new roman as a style in my docx, you can see the difference between the PDF file and docx in attached pictures.

regards,

 


    public static void ConvertWordtopdf(string input, string output)
        {
            var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
            var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
            Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
            Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;

            try
            {
                //var docxBytes = File.ReadAllBytes(input);
                var docxBytes = System.IO.File.OpenRead(input);
                RadFlowDocument docx = docxProvider.Import(docxBytes);

                var pdfBytes = pdfProvider.Export(docx);
                File.WriteAllBytes(output, pdfBytes);

                docxBytes.Dispose();
                
            }
            catch (Exception ex)
            {
                ;
            }
        }


    }

    public class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
    {
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFileName = fontProperties.FontFamilyName + ".ttf";
            string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            string targetPath = Path.Combine(fontFolder, fontFileName);

            DirectoryInfo directory = new DirectoryInfo(fontFolder);
            FileInfo[] fontFiles = directory.GetFiles("*.ttf");
            if (fontFiles.Any(s => s.Name.Equals(fontFileName, StringComparison.InvariantCultureIgnoreCase)))
            {
                using (FileStream fileStream = File.OpenRead(targetPath))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        return memoryStream.ToArray();
                    }
                }
            }

            return null;
        }
    }

1
Martin
Telerik team
answered on 09 Sep 2021, 08:31 AM

Hello Wajdi,

The example provided in the Cross-Platform help article is just a sample of how to use the API and it is not a complete solution. In order to handle the font style as well, you will need to expand the implementation. A more complete example can be found in the FontsProvider class in the suggested SDK example.

While examining the screenshots you provided I found out that the document contains several currently not supported by the WordsProcessing library functionalities:

I want to apologize for the inconvenience these missing functionalities might be causing you. Please, make sure to cast your vote for their implementation as well as subscribe to the task by clicking the Follow button so you can receive updates when their status changes.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

wajdi
Top achievements
Rank 1
Iron
commented on 16 Sep 2021, 08:11 AM

hello, 

your nuget does'nt support merge mail and export to pdf, so i had to bought another nuget "syncfusion" it's work perfectly.

 

regards.

0
Martin
Telerik team
answered on 17 Sep 2021, 05:58 AM

Hi Wajdi,

I am sorry to hear about your disappointment. I understand your frustration and I want to apologize one more time for the inconvenience the previously described missing functionalities might be causing you. 

As for the mail merge functionality, it is supported by the WordsProcessing library. Information about it you can find in the Mail Merge and Merge Field help topics. We have a good SDK example demonstrating this functionality in our GitHub repository as well: MailMerge.

If you need any further assistance with Mail Merge, export to PDF, or any other functionality, please, let us know.

Regards,
Martin
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
General Discussions PdfProcessing SpreadStreamProcessing WordsProcessing
Asked by
wajdi
Top achievements
Rank 1
Iron
Answers by
Martin
Telerik team
Share this question
or