pdf to jpg, resolution

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
coulon

pdf to jpg, resolution

Post by coulon »

When I type convert stuff.pdf stuff.jpg I am not pleased with the resolution of the .jpg image.
convert -verbose stuff.pdf says: Geometry 1500x1982, Resolution=72x72, Print size: 20.8333x27.5278. The resolution is obviously wrong: a simple calculation gives 183.

Can Imagemagick guess the resolution of my .pdf input image correctly? I can see the pixels of this image when I zoom with Acrobat Reader and I would like each pixel of the jpg image to correspond to one pixel of the .pdf image. This doesn't seem to be true even by saying -density 183.
Last edited by coulon on 2010-07-01T23:55:27-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to eps, resolution

Post by snibgo »

Try a density setting, eg:
convert -density 500 stuff.pdf stuff.jpg

1500/72 = 20.8333
1982/72 = 27.5277
Where do you get 183 from?

PDF is a vector format (that might also contain bitmap images). A PDF file doesn't really have a resolution (but any embedded bitmaps do, and they can be different from each other).
snibgo's IM pages: im.snibgo.com
coulon

Re: pdf to eps, resolution

Post by coulon »

snibgo wrote:Try a density setting, eg:convert -density 500 stuff.pdf stuff.jpg
Sure I don't lose any information like this, but the .jpf is huge! 21MB! Usually a 1500x2000 jpg image is less than 1MB.
snibgo wrote:1500/72 = 20.8333 1982/72 = 27.5277 Where do you get 183 from?
Sorry I thought the 20.8333 and 27.5277 were centimeters! Now I understand that 72*2.54=182.88.
snibgo wrote:PDF is a vector format (that might also contain bitmap images). A PDF file doesn't really have a resolution (but any embedded bitmaps do, and they can be different from each other).
So I think I must research the right -density compromise by trial and error. I'm sure the source pdf was obtained by converting a scanned image. I believe choosing a density multiple of 72 would provide better results. Is this true? Are densities other than the common 150,300,600 etc. possible?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to eps, resolution

Post by snibgo »

Yes, my "500" was just an example, of course. You might get better quality from a multiple of 72. Any density is possible.

If the pdf has been created from a single raster (bitmap) image, ImageMagic might restore it to the original dimensions. I suppose it depends on whether the original conversion has created suitable metadata.

The roundtrip with ImageMagick is generally lossless, that is:

convert i1.png temp.pdf
convert temp.png i2.png

will give an image in i2.png that is identical to i1.png.
snibgo's IM pages: im.snibgo.com
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: pdf to eps, resolution

Post by Drarakel »

As snibgo said, any density is possible. (It's true that images are often embedded with common densities like 150 or 300dpi - but you can't rely on that.)
For 'simple' PDFs, there are some ways to obtain a 'right' density value (apart from "trial and error" :wink:) - also with the help of some (free) tools.
Can you provide the PDF with which you have problems?
coulon

Re: pdf to eps, resolution

Post by coulon »

Drarakel wrote:Can you provide the PDF with which you have problems?
AFAIK you can't attach a PDF into a message to this forum. It would need about 30 lines to explain
how I obtained it. What do you suggest to "provide" this .pdf?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: pdf to eps, resolution

Post by fmw42 »

AFAIK you can't attach a PDF into a message to this forum. It would need about 30 lines to explain
how I obtained it. What do you suggest to "provide" this .pdf?
You have to post your file somewhere else and then you can post a link here to where it resides.

I have used

convert -density 288 image.pdf -resize 25% image.png

288 = 4 * 72dpi and so you need to resize by 1/4 = 25% to get back to the same size. This is called supersampling. You can use other densities, but just resize by the inverse multiplier. However, the larger you make the density, the longer it will take to process.

If output to jpg, then you need to add -quality and set that appropriately before the output image
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: pdf to eps, resolution

Post by Drarakel »

It's always easier to give specific hints when one has an example file - that's why I was asking for your PDF.
There's no tool that gives you an ideal density value for all files with one click (at least not that I know of). Of course, it's also debatable what an 'ideal density value' means in PDFs.
But with simple PDFs, you could try an alternative PDF viewer that allows you to see the size of the embedded images (for example with Perfect PDF Reader - if you're on Windows). That should be an improvement compared to estimating the pixels size in Adobe Reader. :wink:
coulon

Re: pdf to eps, resolution

Post by coulon »

fmw42 wrote:I have used convert -density 288 image.pdf -resize 25% image.png
288 = 4 * 72dpi and so you need to resize by 1/4 = 25% to get back to the same size. This is called supersampling.
You can use other densities, but just resize by the inverse multiplier. However, the larger you make the density, the longer it will take to process.
Thanks, this gives a pretty good result.
Post Reply