jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.37k stars 148 forks source link

QUESTION: replace images #205

Closed Syntamin closed 3 months ago

Syntamin commented 3 months ago

Hi,I want to achieve lossless compression of PDF size, for example, by extracting all images from the PDF and using pngquant to compress the images, then replacing the original images. In theory, can this library be used to achieve PDF size compression? Also, I haven't found an API to replace the original images.

jorisschellekens commented 3 months ago

Hi Syntamin,

Please keep in mind the Github issues are meant for bug reports and feature requests. If you have specific questions related to usage, please ask them using StackOverflow (such that the answer is more visible, and can be found by more people).

Anyway, related to your question: I would check out the class ImageFormatOptimization.

You see, in PDF, images can be displayed at a given size, and stored at a completely different size. So one way of performing image optimization is to scale down all the images (that are too large) such that they are the display format. And that's precisely what the aforementioned class does.

This would be a good entrypoint for you to explore borb for your usecase.

Kind regards, Joris Schellekens

Syntamin commented 3 months ago

Hi Joris Schellekens,

Thank you very much for your response. If I encounter any problems in the future, I will ask questions on StackOverflow. I will also try to use ImageFormatOptimization to achieve my goal. Thanks again!