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

Free Support Forum - aspose.com

PDF Size when adding image

Hi


I’m replacing an image in a PDF file with another image. When I remove the image, the PDF is 10KB in size, but when I replace the old image with a new 8KB .png file, the PDF file grow to 40KB.

Is there a way to reduce the image size “inside” the PDF?

Any reason why the PDF grow by a factor of 4 when the image file is added and not by 8KB?

Any help would be appreciated.

Kind Regards
DJ

Hello DJ,


Thanks for contacting support.

Usually when you add images inside PDF document with Aspose.Pdf for .NET, the API does not compromise on image quality and to retain that image quality, it also keeps graphics state of image stored. Nevertheless you can optimize a PDF document using OptimizeResources() method of Document Class, which will compress images using CompressImages and ImageQuality. Please check following code snippet to optimize PDF resources.

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

pdf.OptimizeResources(new Document.OptimizationOptions()

{

LinkDuplcateStreams = true,

RemoveUnusedObjects = true,

RemoveUnusedStreams = true,

CompressImages = true,

ImageQuality = 10

});

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



You may also check "Optimize PDF Document" in our API documentation, for more information. In case if you still face any issue, please share some more details i.e sample input document, sample image, sample code snippet which you are using to add image, so that we can try to test the scenario in our environment and address it accordingly.


Best Regards,