Convert PDF to PNG using ImageMagick

PdfPdf GenerationImagemagick

Pdf Problem Overview


using ImageMagick, what command should i use to convert a PDF to PNG? I need highest quality, smallest file size. this is what I have so far (very slow by the way):

convert -density 300 -depth 8 -quality 85 a.pdf a.png

Looking at what Gmail does when a user "view" a PDF, the quality is awesome and the file size very minimal. The DPI is just 96 (I have to set a density of 300 to get anything decent). Anyone know how GMail does it? Thanks.

Pdf Solutions


Solution 1 - Pdf

Reducing the image size before output results in something that looks sharper, in my case:

convert -density 300 a.pdf -resize 25% a.png

Solution 2 - Pdf

when you set the density to 96, doesn't it look good?

when i tried it i saw that saving as jpg resulted with better quality, but larger file size

Solution 3 - Pdf

convert -density 192 input.pdf -quality 100 -alpha remove output.png

for pdf text document is good enough. -density 192 double 96dpi, higher just make bigger image and file size -quality 100 somehow this give slightly smaller file size -alpha remove to remove png transparent background

Solution 4 - Pdf

To get high quality, one should do "supersampling" in Imagemagick. Convert at a high density, but then resize down as needed (nominal enough to compensate for the high density).

convert -density 288 input.pdf -resize 25% output.png


288=72*4 (72 dpi is default density, so 4x)
25%=1/4

So the 1/4 compensates for the 4x.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStackOverflowNewbieView Question on Stackoverflow
Solution 1 - PdfAlastairView Answer on Stackoverflow
Solution 2 - PdfAvi PintoView Answer on Stackoverflow
Solution 3 - PdfA. GoView Answer on Stackoverflow
Solution 4 - Pdffmw42View Answer on Stackoverflow