How to convert Word to PDF without compressing images using .NET

Hi Tahir @tahir.manzoor,

We have the same recquiremt as @guillaume.gerard had: “We need to be able to convert a word to PDF without compressing the images.How can we do it?

We are using Aspose Word v19.10 currently. Can you share how we can achieve the above goal?
Thank you!

@akozma

Following code example generates the PDF without compressing images.

Document doc = new Document(MyDir + "input.docx");
doc.Save(MyDir + "20.1.pdf");

The non-JPEG images will be ‘Flate’ compressed which is lossless and JPEG images will be saved to PDF as is.

Loss of Image Quality.zip (423.1 KB)

@tahir.manzoor
Tahir,
Based on your code suggestion I created this console app to test jpeg quality:

    static void Main(string[] args)
    {
        Console.WriteLine("Hello Aspose World to PDF!");
        License lic = new License();
        lic.SetLicense("Aspose.Words.lic");
        Console.WriteLine("Setting License.");
        Document doc = new Document("Y0096_MRK_IL_PDPFRM_Value19_C.docx");
        Console.WriteLine("Creating PDF");
        //var pdfOptions = new PdfSaveOptions
        //{
        //    ImageCompression = PdfImageCompression.Auto,
        //    JpegQuality = 100
        //};
        //doc.Save("Test_With_JpegOptiondocx.pdf", pdfOptions);

        doc.Save("Test_No_JpegOptiondocx.pdf");
    } 

I tested WITH and WITHOUT setting PdfSaveOptions. Here is the explanation for the different files:

  1. Logo_From_Word.jpg > This is the original image saved directly from the .docx document.
  2. Logo_From_AsposePDF.jpg > This images was saved from the PDF generated by the above code
  3. Logo_From_WordToPDFExport.jpg > This image was saved directly from the PDF generatade by MS Word’s Export to PDF command
  4. Logo_From_AsposePDFwithPdfOptions100.jpg > This image was saved from PDF generated by the above code with PdfSaveOptions uncommented

The result shows the following, please see attached LogoJpegComparision.jpg:

A. Aspose’s v19.10 doc.Save() does compresses and/or changes jpeg image quality
B. MS Word’s Export to PDF function compresses and/or changes jpeg image quality
C. Aspose’s v19.10 doc.Save() function with PdfSaveOptions.JpegQuality = 100 will produce the same compressed jpeg result as MS Word’s Export to PDF function

All 3 options, Aspose and MS Word cuts back the original image’s quality.

We would like to know if Aspose Word is able to generate PDF from Word .docx document without changing the quality of the jpeg image of the Word document and if yes, how.

I have attached the first page of the Word .docx document as well.

Please let me know if you need any other information from us.
Thank you!

PS: I realized that I did not include test with ImageCompression = PdfImageCompression.Jpeg, JpegQuality = 100. the result of this was identical with 2. Logo_From_AsposePDF.jpg, thus unfortunately it also had loss of quality.

@akozma

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19799. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

No problem. Thank you and looking forward to the updates.

@tahir.manzoor is there a URL I can go to check the status of this issue WORDSNET-19799 or I only will be notified here on this thread?

Also, would you be able to give us some estimation of time when this will be resolved? We have a production application which depends on this function and if it takes more time on your side to resolve than our customers can live without we may need to start finding a workaround for the issue.

Thank you!

@akozma

Our issue tracking system is not public. However, you can ask for update here in this thread.

We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies

Will do. Thanks

@akozma

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-19799) as ‘Not a Bug’.

You can use following code example to achieve your requirement.

Document doc = new Document("input.docx");
PdfSaveOptions pdfOptions = new PdfSaveOptions();
PdfOptions.DownsampleOptions.DownsampleImages = false;
doc.Save("no-compression.pdf", pdfOptions);

Thank you @tahir.manzoor
This solved the issue.
Best regards!

@akozma

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.