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.

Thu Mar 30, 2023 12:44 pm

Hi

We are using Spire.Doc 11.1.0 to convert docx files to pdf with the following code:

Code: Select all
    public static void ConvertWordToPdf(string wordFilePath, string pdfFilePath, bool pdfACompliant = false)
    {
      var document = new Document();
      document.LoadFromFile(wordFilePath);
      document.UpdateTableOfContents();
      if (pdfACompliant)
      {
        var toPdf = new ToPdfParameterList();
        toPdf.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;
        document.SaveToFile(pdfFilePath, toPdf);
      }
      else
      {
        document.SaveToFile(pdfFilePath, FileFormat.PDF);
      }
    }


The file is about 900 pages long and almost exclusively consists of text. The PDF file that results from above code, is about 18 MB. However, if you open the original file in Word and save it as a PDF with the option optimize for file size, the file is only about 5.6 MB.

I found out, that by opening the file generated by Spire.doc with Spire.pdf, setting the compression level to best and, way more importantly, setting IncrementalUpdate to false, I can reduce the file size to about 11.2 MB.

Code: Select all
    static public void MakePdfSmaller(string pdfFile)
    {
      var document = new PdfDocument(pdfFile);
      document.FileInfo.IncrementalUpdate = false;
      document.CompressionLevel = PdfCompressionLevel.Best;

      document.SaveToFile(pdfFile + " small.pdf");
      document.Close();
    }


But that's still twice as large as the file Word produces. Is there a way to reduce the file size further?
Compressing the image doesn't help, that only saves about 20 kB and results in really bad image quality.

I can share the corresponding files, but they are too large to upload here.

chsoft
 
Posts: 4
Joined: Thu Dec 07, 2017 9:54 am

Fri Mar 31, 2023 10:34 am

Hi,

Thanks for your feedback.
Could you please provide us with your test document to help us do a further investigation? you can send it to us via email (support@e-iceblue.com), also, you can upload to GoogleDrive or OneDrive and share the download link with us. Thanks for your assistance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Wed Apr 12, 2023 6:52 am

Hi

I sent the files by mail over a week ago. Any news on this?

chsoft
 
Posts: 4
Joined: Thu Dec 07, 2017 9:54 am

Wed Apr 12, 2023 7:51 am

Hi,

Thanks for your inquiry.
I have replied to you via email on April 3rd at 6:20 PM, here is a screenshot of my reply email
email.png

Please check your junk mail folder to see if my email was marked as spam.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Thu Apr 13, 2023 9:38 am

Urgh, sorry, I didn't notice that your email was sorted as spam.

And yes, updating Spire.Doc from 11.1 to 11.4 results in much much smaller PDF files. Perfect, thank you very much.

chsoft
 
Posts: 4
Joined: Thu Dec 07, 2017 9:54 am

Thu Apr 13, 2023 9:53 am

Hi,

Thanks for your feedback.
Glad to hear that your issue was solved, please do not hesitate to reach out to us if you have any further questions or concerns.

Have a nice day! :D

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc