Specifying pages/frames to read - converting PDF

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
JohnT
Posts: 1
Joined: 2013-02-21T09:44:47-07:00
Authentication code: 6789

Specifying pages/frames to read - converting PDF

Post by JohnT »

Hi All,

interesting situation here. I have a few PDFs where random pages are inverted with white text on black background. I want to convert the entire document back to black text on white background, by specifying on the command line which pages to invert.

I found this useful blog post: http://blog.dillfrog.com/how-to-invert- ... agemagick/

It shows to specify frame/page numbers like so:

convert -density 300 -negate "in.pdf[24-28]" out.pdf

The problem is, there are pages I want to skip in the inversion process, but still have them in the final "out.pdf".

Is this possible? Can I specify only to invert pages 1 and 2 of a 10-page document, but still have a 10 page output file (with pages 3-10 untouched)?

I was thinking something such as this would be useful, using the caret to specify which pages to skip: convert -density 300 -negate "in.pdf[^0-23][24-28]" out.pdf
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Specifying pages/frames to read - converting PDF

Post by fmw42 »

I do not believe that you can do what you want. You will likely have to process it in two commands, one for the inverted pages and another for the non-inverted pages.

You can skip frames, but you only get output the frames you tell it to use.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Specifying pages/frames to read - converting PDF

Post by anthony »

Also as IM is using ghostscript to convert the pages to raster format it will convert ALL the pages first then extract the ones specified. It does not have a true understanding of the PDF format.

you are better off using PDF specific tools to extract the desired pages first, then use ImageMagick later.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply