We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Support add/replace Grayscale Images in PDF

Hello,


I am encountering a problem with images in PDF.

In case of grayscale images, Aspose saves them as color images inside PDF files. This causes the PDF files increased in size.

For example, I extract the images from the attachment and save them as Jpeg files. Then, I replace the images inside the PDF file by Jpeg one. I end up with a PDF file with larger size. I also tried to use image quality parameter when replacing the images but it does not help.

I would like to ask if there is any way to add/replace images in grayscale form?

Thank you in advance

Hello Dung,


Thanks for contacting support.

dunghnguyen:
For example, I extract the images from the attachment and save them as Jpeg files. Then, I replace the images inside the PDF file by Jpeg one. I end up with a PDF file with larger size. I also tried to use image quality parameter when replacing the images but it does not help.

We will really appreciate if you please share a code snippet which you are trying to perform above mentioned functionality and explain “Jpeg one” a little more. It would help us to replicate the scenario in our environment and address it accordingly.

dunghnguyen:
In case of grayscale images, Aspose saves them as color images inside PDF files. This causes the PDF files increased in size.

In order to reduce/optimize the PDF document you need to use Optimize() method, provided by Aspose.Pdf for .NET. Please check following code snippet that I have used to optimize your PDF file and the size has been reduced from 3.6M to 3.0M. I have also attached an output for your reference.

Document pdf = new Document(dataDir + “CleanCode.pdf”);<o:p></o:p>

pdf.OptimizeResources(new Document.OptimizationOptions()

{

LinkDuplcateStreams = true,

RemoveUnusedObjects = true,

RemoveUnusedStreams = true,

CompressImages = true,

ImageQuality = 10

});

pdf.Save(dataDir + "CleanCode_optimized.pdf");


dunghnguyen:

I would like to ask if there is any way to add/replace images in grayscale form?


You may check following articles in API documentation regarding images (colored and grayscale) and optimizing PDF document. May be you can identify color/grayscale images inside PDF and then replace them.




Best Regards,

Hello,


If we set ImageQuality to 10, the quality of PDF page becomes very low.
We want to avoid this solution.
Instead, we would like to embed gray scale images to PDF in gray scale format so that the size is reduced.

Regards

Hi Dung,


Thanks for writing back.

dunghnguyen:
we would like to embed gray scale images to PDF in gray scale format so that the size is reduced.

As shared above, Aspose.Pdf supports converting colored PDF into Grayscale PDF and as far as converting images into Grayscale format concerned, you can use Aspose.Imaging for the purpose. Please visit “Convert image into Black and White or Grayscale” for more information.

Furthermore, I have tried to optimize your PDF document by converting it into Grayscale using Aspose.Pdf 17.4.0 and noticed that the generated output was of larger size than that of original document. Therefore for the sake of correction, I have logged a quality issue as PDFNET-42606 in our issue tracking system.

We will further look into the details of the issue and keep you updated on the status of its resolution. Please be patient and spare us a little time. We are sorry for the inconvenience,


PS: If you already have Grayscale images, you can simply add them inside PDF and for that you may check “Add image in existing PDF” in API documentation.

Hello,


Thanks for your reply.

That is exactly the problem I need your help.
After converting PDF document into Grayscale, the file size increases.

Looking forward to hearing you.
Thanks one more time.

Best regards,
Dung

Hi Dung,


Thanks for contacting support.

Now that the problem is logged in our issue tracking system, the product team will look into this matter as per their schedule and as soon as we have some definite updates regarding its resolution, we will let you know.

Please be patient and spare us little time.

Hello,

Do you have any update?
I am looking forward to seeing your response.

Thanks.

@dunghnguyen

Thanks for posting your inquiry.

I am afraid that earlier logged issue has not been resolved yet. Though we have intimated the relevant team about your concerns and as soon as we have some feedback from their side, we will update you. We greatly appreciate you patience and cooperation in this regard. Please spare us little time.

We are sorry for this inconvenience.


Best Regards,
Asad Ali