Poor pdf to png quality - - how to improve?

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
User avatar
michelle
Posts: 31
Joined: 2011-08-24T06:45:50-07:00
Authentication code: 8675308

Poor pdf to png quality - - how to improve?

Post by michelle »

Hello there, I am converting pdf's to png's and I've noticed that :-

1. the visual quality of the .png is a downgrade from the orginal pdf. If I specify a density of say 600x600, there is no improvement. Is it possible to somehow produce a better quality .png from my pdf?

2. the .png seems to be smaller than the pdf although i did not specify any resizing. Just wondering why this is?

A screen shot of all images at 100% size along with the exact commands I used and IM version is here: http://www.michellepace.com/pics/poor-p ... aility.png . The identify command on 1.pdf yeilds:
1.pdf PDF 600x842 600x842+0+0 16-bit Bilevel DirectClass 1.516MB 0.016u 0:00.003

Thanks, Michelle
Last edited by michelle on 2011-08-27T02:16:56-07:00, edited 1 time in total.
User avatar
michelle
Posts: 31
Joined: 2011-08-24T06:45:50-07:00
Authentication code: 8675308

Re: Poor pdf to png quality - - how to improve?

Post by michelle »

Goodness. I got it. It matters where you put the -density option for it to work. Put it before the name of the file you want to convert. As for the resizing, it seems ImageMagic does resize as my png is much bigger. No matter, I scale it down to an @area of 1500000 because I like that size.

The Working Command: convert -density 300 "1.pdf" -scale @1500000 "1.png.scale=@1500000.png"

The result: http://www.michellepace.com/pics/densit ... -works.png

PS ...i dont know why, but .tif files don't seem to like the denisity function. .tif files which IM was handling with no problem before I used -density were suddely causing IM to crash after adding -density into my command. So I just use it for pdf files.
cheers, michelle

Image
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Poor pdf to png quality - - how to improve?

Post by whugemann »

Yes, it definitively matters where you place the -density option.

I may be wrong, but your original PDF looks like a scan to me, i.e. a raster image wrapped in a PDF. these can be extracted losslessly with pdfimages from xpdf, see http://www.imagemagick.org/Usage/windows/#auxiliary.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Poor pdf to png quality - - how to improve?

Post by fmw42 »

It does matter especially with vector formats that have no density defined. So you must set it before reading.

see
http://www.imagemagick.org/Usage/basics/#why

also if you want to increase the quality, you can use a supersampling technique. You set the density, say 4 times larger than nominal (72 dpi), thus -density 288 before reading the pdf. Then after reading it, you resize down by a factor of 4 or 25%

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

The downside is that it will run slower because you are making the image 16x bigger to start.
Bas
Posts: 1
Joined: 2012-05-19T14:42:47-07:00
Authentication code: 13

Re: Poor pdf to png quality - - how to improve?

Post by Bas »

Thank you very much,
I've lost 2 days struggling against IM because every time i convert a pdf image IM produced a low definition and low size JPG, PNG, ...
I've found only your post searching with google.
Thank a lot!
mmlenz
Posts: 23
Joined: 2012-05-30T08:08:21-07:00
Authentication code: 13

Re: Poor pdf to png quality - - how to improve?

Post by mmlenz »

I've seen a few people mention pdfimages from xpdf (its actually part of poppler-utils now). I am NOT seeing it extracting a lossless copy of the image. Looking at the image in the PDF it is still better quality than the resulting image it extracts. Why I have no idea.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Poor pdf to png quality - - how to improve?

Post by anthony »

mmlenz wrote:I've seen a few people mention pdfimages from xpdf (its actually part of poppler-utils now). I am NOT seeing it extracting a lossless copy of the image. Looking at the image in the PDF it is still better quality than the resulting image it extracts. Why I have no idea.
Under fedora 16, the poppler-utils provides many PDF handling utilities, BUT does not include xpdf, which is a separate package. I have not however checked if the packages have dependencies with each other.


The problem is that PDF has no 'scale' or 'resolution'. It is a vector image file format.
However images which may be wrapped in a PDF, are raster, and thus does have a 'preferred resolution'.

To extract them you need to see the PDF at exactly the right resolution to scale the internal image to its preferred resolution. Note these may NOT be the same, as the PDf may internally 'scale' the image when drawing it on the 'page', though typically they are the same.

The better way is to somehow directly extract the raster image data from PDF using some utility.
The "pdfimage" utility (or perhaps others) from the above packages should allow you to do this.
But wether it actually extracts the raw data, or just 'draws' it, I have no idea.

I have also heard about other people extracting actual file formats (like JPEG, by looking for the image header 'magick') from PDF files. Though that assumes the file in the PDF is stored as an actual image! (should actually be quite common these days).

WARNING: PDF and Postscript is actually a restricted computer 'drawing' language in and of itself. this means it can contain a program which makes the simple extraction of a raw raster image from the format practically impossible! This may or may not be in use as a copyright protection scheme. Though I have not seen such a use, I know it is possible, and I have done this enough to know if it is actually in use.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply