6

I am using ImageMagick to convert PDF files into images. However, some of the PDF's have multiple pages, which is proving to be a real problem.

My local convert is below.

exec("\"C:\\Program Files (x86)\\ImageMagick-6.8.5-Q16\\convert.exe\" -density 300 -quality 75 \"{$path}{$filename}{$ext}[$page]\" \"{$targetFile}\"");

If i remove [$page] from the exec it works but creates an image per page, which isn't what I want.

I have been searching for a while now and i've ran out of hope and ideas. Is there any way I can get all of the new images into one final image, or convert the PDF straight into one image? Any help would be greatly appreciated, cheers.

Pooshonk
  • 1,284
  • 2
  • 22
  • 49
  • 1
    As an option - make separate images as you do, then merge them via imagemagic into one image file. –  Jun 07 '13 at 13:21
  • Yeah I just used montage to get all pages as images into one image. Thank you :) – Pooshonk Jun 07 '13 at 14:55

1 Answers1

6

Check out the -append and +append options.

-append appends the images vertically, and +append appends them horizontally.

Usage (http://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagick):

According to that link, the output from a multi-page pdf convert would be ${targetFile}-0.png, ${targetFile}-1.png, ${targetFile}-n.png, etc. Once you have converted the pdf into multiple images, use the -append or +append option:

convert ${targetFile}-* -append single_image.png

To put it all together, try something like this (you may have to play with it a bit; I haven't used Imagemagick from the Windows' shell):

// convert pages of pdf

exec("\"C:\\Program Files (x86)\\ImageMagick-6.8.5-Q16\\convert.exe\" -density 300 -quality 75 \"{$path}{$filename}{$ext}\" \"{$targetFile}\"");

// then append them

exec("\"C:\\Program Files (x86)\\ImageMagick-6.8.5-Q16\\convert.exe\" \"{$targetFile}-*\" -append "${someName}\"");

More resources:

http://www.imagemagick.org/script/command-line-options.php#append

http://www.imagemagick.org/Usage/layers/

salsbury
  • 2,777
  • 1
  • 19
  • 22
  • 1
    I managed to fix it myself. I counted all pages, converted them all to images and used montage to put all of the new image into one. This however looks like the next thing i was going to try. I'll accept this one, thank you – Pooshonk Jun 07 '13 at 14:54