Convert PDF to JPG with +append

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
loru88
Posts: 4
Joined: 2012-02-24T02:18:35-07:00
Authentication code: 8675308

Convert PDF to JPG with +append

Post by loru88 »

Hello everyone
I'm new to imagemagick, and I need a little help.
I have a pdf, I want to convert it in jpg but I need to have a jpg file for every two consecutive pages

I have used this command to convert just two pages in a single jpg file with the page side by side

Code: Select all

convert pdf_file.pdf[0-1] -colorspace rgb -density 300 +append  two_pages.jpg
but what if I want to automate this operation for every two consecutive pages?
there is some kind of option to do this task? I tried with -tile 2x1 option but it doesn't work

if it isn't possibile I have to write my own script to do this task
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert PDF to JPG with +append

Post by fmw42 »

I think you have to write a short script to loop over your pages in the file and do them two at a time. I don't think there is a way to provide automatic skips in pages in IM over a series of pages.
loru88
Posts: 4
Joined: 2012-02-24T02:18:35-07:00
Authentication code: 8675308

Re: Convert PDF to JPG with +append

Post by loru88 »

I made by my self, the solution was easy.
the command to do this is is a simple -montage with the -convert option

Code: Select all

montage -density 300 album.pdf -mode Concatenate -tile 2x1 -quality 80 -resize 800 two_page.jpg
in this way each jpg is a pair of consecutive pdf's pages and they are very high quality and not much heavy

now I have another question: the first page in the pdf is the cover, so i want to exclude the first page and do that command on the other pages.
this command works, I found the number of pdf pages using identity command

Code: Select all

pdfpage=`identify -format %p -density 12 album.pdf`
montage -density 300 album.pdf[1-$pdfpage] -mode Concatenate -tile 2x1 -quality 80 -resize 800 test_%04d.jpg
but It is slow, and not elegant...

Someone know some kind of solution to exclude the first page only?
Is there a special command in Imagemagick or in the bash scripting language or some special wildcard?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert PDF to JPG with +append

Post by anthony »

That would be very slow as the PDF is converted twice.

Solution just read them all in. and delete the first (zeroth) image

Code: Select all

   montage -density 300 album.pdf -delete 0 ....
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
loru88
Posts: 4
Joined: 2012-02-24T02:18:35-07:00
Authentication code: 8675308

Re: Convert PDF to JPG with +append

Post by loru88 »

Thanks for the reply, but it doesn't work, it said there is an error:
montage: unrecognized option `-delete' @ error/montage.c/MontageImageCommand/867.

in fact the -delete option isn't listed in the montage option summary (http://www.imagemagick.org/script/montage.php)

I have tried also this command for exclude the first page with wildcard

Code: Select all

-density 300 album.pdf[^0] -mode Concatenate -tile 2x1 -quality 80 -resize 800 two_page.jpg
and it partially work: it return one jpg for each two pages (side by side) except the first but all the jpg are just grey images...
maybe this is a bug or I suppose the wildcard can't be used in this way...

For me is good also to have the first page of the pdf side by side with a blank page when it is converted in jpg, like a fill image
it could be possibile to do this?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert PDF to JPG with +append

Post by anthony »

Montage should allow the use of -delete.
If it doesn't then, it is a bug (or your IM is very very very old).

Montage should work exactly like convert, with just a few options (like -geometry and -frame) substituted.
However it is actually missing quite a few options, which have been added as people request them.

I have now added all the image list options (-delete, -insert, -reverse, -swap) that were missing from "montage" for the next release of IMv6 (when that happens). Version 6.7.5-8



ASIDE: I am currently working on IMv7 Shell/Script API, and such missing options between the various commands, other than the special exceptions for that specific command will not be possible! :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply