This is a migrated thread and some comments may be shown as answers.

The type initializer for 'Telerik.Windows.Documents.Flow.Model.RadFlowDocument'

5 Answers 667 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
adithya
Top achievements
Rank 1
adithya asked on 23 Dec 2019, 08:07 PM

i am getting the following error when trying to convert a docx to pdf at the following line

providerDocx.Import(input)

The type initializer for 'Telerik.Windows.Documents.Flow.Model.RadFlowDocument' threw an exception.

 

using System;
using System.IO;
using Telerik.Windows.Documents.Common.FormatProviders;
using Telerik.Windows.Documents.Flow.FormatProviders.Docx;
using Telerik.Windows.Documents.Flow.FormatProviders.Pdf;
using Telerik.Windows.Documents.Flow.Model;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var providerDocx = new DocxFormatProvider();
            string path = System.IO.Directory.GetCurrentDirectory();
            string fileName = Path.Combine(path, "1.docx");
            RadFlowDocument document = null;
            using (FileStream input = new FileStream(fileName, FileMode.Open))
            {
                document = providerDocx.Import(input);
            }

            var providerPdf = new PdfFormatProvider();
            Stream outStream = new MemoryStream();
            providerPdf.Export(document, outStream);

            //Test the conversion:
            var fileStream = File.Create("PdfTest.pdf");
            outStream.Seek(0, SeekOrigin.Begin);
            outStream.CopyTo(fileStream);
            fileStream.Close();
        }
    }
}

 

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Dec 2019, 10:52 AM

Hello Aditya,

Your code is ok and works without issues on my side. Can you test this with another document and see if the exception still occurs. 

In addition, could you send us the complete stack trace and check if the inner exception contains more information about this?

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
adithya
Top achievements
Rank 1
answered on 24 Dec 2019, 03:43 PM

Found the issue. Its because of .netcore version 3.0. With version 2.1 it worked perfectly fine for a simple text document. but for the original document with images it shows me this exception when trying to convert to pdf

"Can not export other than Jpeg and Jpeg2000 and ImageQuality different than High"

 

Are there any specify rules on image type and image quality? how to solve this issue as I don't have an option to change the image type it can be anything. Or is this a issue because of a trail version?

Can you please give me more details on this?

0
Dimitar
Telerik team
answered on 27 Dec 2019, 08:06 AM

Hi Adithya,

This is a known limitation with the version for .NET standard. This is logged in our feedback portal. You can track its progress, subscribe to status changes and add your comment to it here: https://feedback.telerik.com/document-processing/1422029-pdfprocessing-netstandard-add-support-for-exporting-png-images.

In addition, I wanted to ask what kind of project you will use this with? Wath is your environment as well? I am asking because we have separate assemblies for .NET standard and .Net Core and for example, this will work in a WPF .NET Core project. 

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
adithya
Top achievements
Rank 1
answered on 27 Dec 2019, 10:32 AM

Hi Dimitar,

 

Thanks for your reply. I am using this in .NET core API service. This support ticket that you mentioned here just talks about the support for PNG images but I also need for BMP images (or in future some other image type will also come in).If that is not possible at the time of pdf conversion, can I do something like converting all the images in the word document to jpeg (with some simple method from code)? and then use that document for pdf conversion.

 

Also want to know if there is any text written on top of a image can be converted to pdf in the same way?

Thanks,

Adithya.

0
Dimitar
Telerik team
answered on 30 Dec 2019, 09:33 AM

Hello Аdithya,

I have investigated this and it appears to be a way to convert the images to the Jpeg format using the .NET API. I have attached a project that shows a sample implementation. This will work for BMP images as well. 

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
WordsProcessing
Asked by
adithya
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
adithya
Top achievements
Rank 1
Share this question
or