HummusJS icon indicating copy to clipboard operation
HummusJS copied to clipboard

Compressing PDF images

Open dresende opened this issue 8 years ago • 2 comments

Hi!

First of all, many .. many thanks for this library! Second, give us documentation! 😸

I'm trying to use the library to do one "simple" thing: compress digitalised documents, which are just A4 pages with a single major image. I just want to open the PDF, somehow compress the images to a certain DPI and then save a new file (and compare the difference).

I'm not sure if this is somehow easy or not. I'm open to suggestions. I don't know if the .end() can do this automatically or if I need to somehow extract the images, make the reduction and replace them. I don't care, but I can't find any detailed documentation about what options and methods there are 😢

dresende avatar Mar 06 '17 22:03 dresende

well, here's hummus documentation section, you can start from there - https://github.com/galkahana/HummusJS/wiki

There is also the blog, which has some howtos that you can use as more documentation - http://pdfhummus.com/How-To

When you go into implementing stuff that's not on the library high level methods, you will want a handy link to the PDF reference manual, i hold one here - http://pdfhummus.com/Downloads

As for the issue at hand, .end() doesn't do extra compression. if you want to compress images then the path to go is to recreate the PDF with replace images, as you suggested.

I could think of several tactics to do that. iterarting the objects (via the pages/forms resources dicts) and finiding image xobjects could be a way to find the images. then extracting the images raw data, the compressing them, then either putting them back via modification or creating a new PDF copy. if you do modify make sure to use hummus.recrypt explained here which creates a version of a pdf without incremental updates (otherwise you keep carrying the images in the PDF file).

galkahana avatar Mar 18 '17 11:03 galkahana