Exporting from docx to pdf using PdfFormatProvider utlizes a lot of memory and time as the number of pages in word document increase.

1 Answer 237 Views
PDFViewer
dharmesh
Top achievements
Rank 1
dharmesh asked on 22 Jun 2021, 08:06 AM

Hi

I am using Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider() to convert a word document(.docx) to pdf.

This takes a lot of time and gives system out of memory exception when the number of pages in the word document is more than 500.

 

Below is the code snippet:

using (Stream input = new FileStream("temp.docx"), FileMode.Open))

                {
                    var providerDocx = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
                    var document = providerDocx.Import(input);

                    var providerPdf = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();

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

                    var fileStream = File.Create("temp.pdf");
                    outStream.Seek(Constants.Int0, SeekOrigin.Begin);
                    outStream.CopyTo(fileStream);
                    fileStream.Close();
                }

 

Please suggest a solution to this or any other alternative which takes less time and memory.

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Jun 2021, 08:45 AM

Hello Dharmesh,

What is the memory consumption when the exception occurs? It is expected the memory to grow when such documents are converted. The pdf file will need a lot of objects that contain a lot of properties and all these need to be stored in the memory. I would suggest building for the x64 platform which will allow your application to use the entire available memory. Is this suitable for you? 

At this point, I cannot suggest another approach that will consume less memory and will work faster. 

Thank you for your understanding. 

Regards,


Dimitar
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
PDFViewer
Asked by
dharmesh
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or