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 65 Views
Top achievements
Rank 1
dharmesh asked on 22 Jun 2021, 08:06 AM


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);


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


1 Answer, 1 is accepted

Sort by
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. 


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.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question