Comment 9 for bug 168708

Revision history for this message
chrysn (chrysn) wrote : Re: embedded jpg exported to eps&pdf as non-jpg

as the eps export workaround didn't work for me, i created another workaround, which works by exporting the bloated pdf first and then replacing the images with their pre-compressed jpeg versions.

the attached script is written in an extreme quick-and-dirty fashion. it takes a pdf file and several jpeg files as arguments, reads the jpegs, hashes them (in an ultra-primitive way) and then walks through the pdf file, tries to read the big images, hashes them too, and if it matches, uses imagemagick's convert tool to convert the jpg to pdf (which it does as it is supposed to be, saving the dct image). then it extracts the pdf chunk from the converted jpg and pastes it into the main pdf, replacing the old image.

there are countless ways how this approach could fail (grayscale jpg, imagemagick changing the names it uses inside the pdf, features of pdf i don't know), but it us usable as a workaround and typically reduces output sizes by a factor of ten.