I have pdf files created on Adobe InDesign, which contains several kinds of object.
I wish to "Remove everything except the largest art (background)" and save to a new file.
This can be achieved almost perfectly with combination of gs command options like this:
$ gs -q -o "${outfile}" -sDEVICE=pdfwrite -dFILTERTEXT -dFILTERVECTOR "${infile}"
However, occasionally there are several raster images which I'd like to filter by some criteria. The image I wish to keep, always have following properties that distinguish it from the unwanted ones:
- it is always the largest in data size
- it is always the largest by dimension
- it is always a 1bit binary images, sometimes compressed with CCITT g4 or LZW
Is there a way to filter certain images by criteria, by using gs command or any other tools perhaps?
This link guided me to using the filter options, but could not work out how I could extend the functionality further: How can I remove all images from a PDF?
The code runs on a Mac/Ubuntu envrironment.