Page 1 of 1

convert pdf2png forcing page size

Posted: 2007-10-24T05:26:08-07:00
by bowa
i am using the following to automatically generate thumbnails from uploaded pdfs.

Code: Select all

convert -resize 200x200 myfile.pdf[0-10] thumb-%05d.png
but i don't really have control over what the pagesize is of the uploaded pfs.
is there a way to pass on (to gs i guess) what the page size of the 'printer' is ? In my case i would like to see the thumbs as if the pdf was printed on a A4 portrait page. (210x297mm). (that would lead to thumbs that are 141x200pixels)

So if the pdf would have a bigger page size, it would be scaled to 'best fit' on the A4 page.

(and as an extra, if possible, to have landscape pages rotated to portrait ones, but if this is not possible in one go, i ll do it later in the code)

thanks for your ideas!

Re: convert pdf2png forcing page size

Posted: 2007-10-24T10:09:40-07:00
by Bonzo
There are controls over the resize see this page http://www.imagemagick.com/www/command- ... tml#resize I think you should be able to do what you want from there.

I think rotating the landscape to portrate would have to be done outside ImageMagick.

Note you read the image in first then convert it so:

Code: Select all

convert myfile.pdf[0-10] -resize 200x200 thumb-%05d.png

Re: convert pdf2png forcing page size

Posted: 2007-10-24T23:20:36-07:00
by bowa
euhm ... i am already using resize, but that doesn't change the 'canvas'. say i have a pdf that is 3000x4000

then i would like an A4 proportioned png (141x200) or (200x141).

if i just do resize 200x200 then the 3000x4000 would lead to 150x200, which is too wide, so basicly it should resize to 141x200 or 200x141 depending on the orientation of pdf ? landscape or portrait

is there any way to do this ?

Re: convert pdf2png forcing page size

Posted: 2007-10-30T19:25:22-07:00
by anthony
If you want all images to be portrait there is a -rotate control that only rotates if an image is longer than wider. From IM examples
The "-rotate" operator also understands two extra flags. If a '>' symbol is added to the rotate argument (before or after the number), then the image will only be rotated if the image is wider than it is taller. The result is that this flag will only rotate 'landscape' (wide) style images into 'portrait' (tall) style images.

The other flag '<' does the opposite, only rotate images that are taller than it is wide.