Need help making PDF into*best* format image

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
Posts: 2
Joined: 2014-05-04T18:43:18-07:00
Authentication code: 6789

Need help making PDF into*best* format image

Post by jonathanjohnson100 » 2018-07-13T17:02:27-07:00

I want to convert PDF to the best image format possible.

I've got ImageMagick + ghostscript.
I run this command: magick convert -verbose -density 150 -trim a.pdf -quality 100 -flatten -sharpen a.jpg

I found this on a google search.
This is 'OK'. Not happy with the print output of the JPG.

Just wondering... maybe I can convert to PNG - would that be any better?

ASIDE: The reason why I want to make PDF into image, is so that I can print the PDF wherever I want.
I get a PDF output. The content takes 1/4 of the page and is on the top left. I want to print this 1/4 page wherever I want - like in the top right or bottom right or left. Has anyone got a better suggestion? :)

I've been using online PDF converters. These do a better job than the output I get on ImageMagick.

User avatar
Posts: 23441
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help making PDF into*best* format image

Post by fmw42 » 2018-07-13T17:57:54-07:00

JPEG may not be the best if using a PDF that has graphics in it. For best quality, you should save to some non-lossy compressed format such as PNG. Is your PDF in color? Also for best quality use a larger density and resize down again. For Imagemagick 7, do not combine magick and convert. Use only magick. Order is important in IM 7. Trim after the PDF has been rasterized.

Code: Select all

magick -verbose -density 300 a.pdf -trim +repage -flatten -resize 50% -sharpen a.png
If you know you only need the top right or bottom right 1/4, you can skip the -trim and just use a gravity based crop.

Code: Select all

magick -verbose -density 300 a.pdf -gravity northeast -crop 25x25+0+0% +repage -flatten -resize 50% -sharpen a.png
You may want to specify a -sharpen amount such as -sharpen 0x1. Always use radius=0 and vary sigma to let IM decide how big to make the radius. Also you may want to use -unsharp in place of -sharpen.

You might do better by not using -sharpen or -unsharp as that could add artifacts.

If your PDF contains a raster image and not just vector data, you might be better off just extracting the image from the PDF using pdf2image rather than GS/Imagemagick.


Post Reply