Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Dec 22, 2021 5:05 pm

Hello,

We have license copy for .NET.
Version - 9.12.7

We are having issue while converting document to PDF, Its taking forever for few documents. I research little bit and found below code is taking time (sometimes 109,120 ms) --
Basically document.SaveToStream takes a lot like 150,000 ms every time.

Code: Select all
  private byte[] ConvertPdfToByteArray(Document document)
        {
            byte[] wordByteArray;
            using (MemoryStream ms1 = new MemoryStream())
            {
                document.SaveToStream(ms1, FileFormat.PDF);
                //save to byte array
                wordByteArray = ms1.ToArray();
            }
            return wordByteArray;
        }



Can some one look into it and let us know what else we can do to improve performance ?

Thanks
Chandra

ChandraMaral
 
Posts: 6
Joined: Wed Dec 22, 2021 3:09 pm

Thu Dec 23, 2021 1:59 am

Hello,

Thank you for your inquiry.
The issue you mentioned is mostly related to the content and layout of the Word file. To help us investigate your issue quickly and effectively, please provide the following information. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your sample Word file.
2) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
3) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1642
Joined: Wed Apr 07, 2021 2:50 am

Wed Dec 29, 2021 10:47 pm

I have sent you all the related information in email. Kindly have a look and let me know what we can do so that we can reduce the time.

Thanks
Chandra

ChandraMaral
 
Posts: 6
Joined: Wed Dec 22, 2021 3:09 pm

Thu Dec 30, 2021 5:52 am

Hello,

Thanks for sharing the information via email.
I tested your Word file locally, and the running time of the program was 6 seconds. The running time of deploying the program to Azure is basically 25 seconds, which is consistent with what you provided. Because the running time on Azure is generally longer than the running time locally, please test the running time of the project locally.
In addition, we have added a new engine method to convert Word to PDF (the sample code is as follows). I used this method to test on Azure, the running time of the program was reduced by about 10 seconds. Please use this method to test again on your side, and give us the feedback about your test results. If the new engine method still does not meet your needs, please provide us with a Word file containing more complex data for further investigation. Thanks in advance.
Code: Select all
 private static byte[] ConvertPdfToByteArray(Document document)
 {
     byte[] wordByteArray;
     using (MemoryStream ms1 = new MemoryStream())
     {
         //use the new engine method
         document.UseNewEngine = true;
         document.SaveToStream(ms1, FileFormat.PDF);
         //save to byte array
         wordByteArray = ms1.ToArray();
     }
     return wordByteArray;
 }

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1642
Joined: Wed Apr 07, 2021 2:50 am

Tue Jan 04, 2022 5:24 pm

I have another thread open as well where UpdateTableContent is taking much time than usual. I have created mimic console application where document creation is taking- 69707 msecs.
I did send whole console application as zip to support team and Lisa (from support team) . If possible you can have a look as well and let me know if anything else we can do to reduce the time for conversion to PDF.

Any help to reduce the time to generate pdf is appreciated.

Thanks

ChandraMaral
 
Posts: 6
Joined: Wed Dec 22, 2021 3:09 pm

Wed Jan 05, 2022 6:07 am

Hello,

We have received your email, and thanks for sharing more information!

I run your project on win10 environment directly, but it only took 39 seconds to convert. Here I attached the screenshots of the console message and my computer setting.
time.png
Capture.PNG


Since there are too many tables in your document, and calculate the tables when convert Word to PDF will spend lots of time. I just recommend that you can use New Engine method to convert, refer to the following code, and it takes shorter time to convert.

Code: Select all
        public static byte[] ConvertDocxToPdf(Stream wordStream)
            {
            Document document = new Document();
            document.LoadFromStream(wordStream , FileFormat.Docx2013);
            document.UseNewEngine = true;
            return ConvertPdfToByteArray(document);
            }


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.Doc