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.