4

I'm on Ubuntu 10.04 with imagemagick. I used this command:

convert myfile.pdf -density 300 file.jpg

This works well, but the JPGs are only about an inch high. How can I preserve the paper size in the conversion process?

1
  • It might be easier to give a good answer if you give more background, e.g. why you want to do the conversion you describe, what material you are working with and quality you need from results.
    – N.N.
    Oct 28, 2011 at 7:01

2 Answers 2

10

You can set the -density before you read the source pdf, so you can do

convert -density 300 myfile.pdf myfile.jpg

and it'll read the pdf at 300dpi, then render out the jpg at the original size of the pdf, whatever that was.

3

I don't know if Imagemagick can sense the correct height automatically. However if you can come up with the correct height in pixel you can set the height manually.

According to http://www.indigorose.com/forums/archive/index.php/t-13334.html an A4 paper has the height of 3508 pixels in 300 dpi so then you can do

convert myfile.pdf -density 300 -geometry x3508 file2.jpg

This command sets the width to 3508 pixels and preserves aspect radio. See http://www.imagemagick.org/script/command-line-processing.php#geometry for details on the -geometry argument.

3
  • Thank you! that works well. I'm using this to automate a scribus publishing project.
    – Trude
    Oct 31, 2011 at 13:36
  • 1
    I'm glad it works. If you find an answer helpful you should vote it up by clicking the upward pointing arrow to the left of the answer. Also, you should consider to accept the most helpful answer by marking it as the accepted answer by clicking on the check box outline to the left of the answer. See faq for details.
    – N.N.
    Oct 31, 2011 at 14:30
  • For better quality, you should set density BEFORE the input file name, like "convert -density 300 myfile.pdf file2.jpg". Then ImageMagick uses this resolution to rasterize the PDF. Otherwise it will rasterize the PDF at a default resolution (72 dpi) and the -geometry command scales up the already rasterized image. The -density command after the input file name only modifies the EXIF property of the output file, not its pixels. (As a bonus, if you specify -density before the input file name, you don't need -geometry any more to preserve the image size.)
    – Jaan
    Sep 23, 2014 at 12:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .