5
2
Does there exist a commandline tool for Linux which allows me to extract all /Subtype /Image raster image objects from a PDF, allows me to process them using another 3rd party tool and then is able to reinsert them into the original PDF?
The Debian package poppler-utils brings the tool pdfimages which allows me to extract all images from a PDF but I can't easily re-insert them into the PDF after I changed them.
I wrote simple parsers for PDF before so my current take on this problem would be to
- run pdfclean (from the mupdf package) on the PDF to decompress all streams and thus make parsing easier
- parse the pdf with a simple parser (surely this will not be able to parse most PDF but as long as it works for my PDF I'm happy) and extract all images as bitmaps with the object id in their name
- do some foo on the images using a 3rd party program
- parse the original pdf again but this time replace the images inside with the modified ones, adapting the /Length and /Filter as necessary
- run pdfclean again to correct all offsets in the xref table
But maybe a tool which allows all this and is not limited to the capabilties of a simple parser written by me already exists?
If you say such a tool does not exist, then it is also okay to tell me a library which allows to extract and later replace images.
Works for my project with some adaptions: main point is that rasterized images use FlateDecode in my file. I guess in your files as well - that's the reason for importing zlib, am I right? – u_Ltd. – 2017-07-05T12:05:32.923
Indeed that is a leftover
import zlib
from when I used the code to work with FlateDecode images. If you like, feel free to suggest how the demo code could be extended to be more useful. – josch – 2017-07-05T15:57:26.620