I'm trying to use the command line program convert
to take a PDF into an image (JPEG or PNG). Here is one of the PDFs that I'm trying to convert.
I want the program to trim off the excess white-space and return a high enough quality image that the superscripts can be read with ease.
This is my current best attempt. As you can see, the trimming works fine, I just need to sharpen up the resolution quite a bit. This is the command I'm using:
convert -trim 24.pdf -resize 500% -quality 100 -sharpen 0x1.0 24-11.jpg
I've tried to make the following conscious decisions:
-sharpen
(I've tried a range of values)Any suggestions please on getting the resolution of the image in the final PNG/JPEG higher would be greatly appreciated!
Open your PDF in Adobe Acrobat Pro and choose file. Export it to the new file format by going to the right pane and choosing “Export PDF” tool. Or, go to the menu and select “File” > “Export to” > “Image.” Choose image format type (e.g., JPG file, TIFF, etc.).
It appears that the following works:
convert \ -verbose \ -density 150 \ -trim \ test.pdf \ -quality 100 \ -flatten \ -sharpen 0x1.0 \ 24-18.jpg
It results in the left image. Compare this to the result of my original command (the image on the right):
(To really see and appreciate the differences between the two, right-click on each and select "Open Image in New Tab...".)
Also keep the following facts in mind:
So, no need to resize; add the -density
flag. The density value 150 is weird -- trying a range of values results in a worse looking image in both directions!
Personally I like this.
convert -density 300 -trim test.pdf -quality 100 test.jpg
It's a little over twice the file size, but it looks better to me.
-density 300
sets the dpi that the PDF is rendered at.
-trim
removes any edge pixels that are the same color as the corner pixels.
-quality 100
sets the JPEG compression quality to the highest quality.
Things like -sharpen
don't work well with text because they undo things your font rendering system did to make it more legible.
If you actually want it blown up use resize here and possibly a larger dpi value of something like targetDPI * scalingFactor
That will render the PDF at the resolution/size you intend.
Descriptions of the parameters on imagemagick.org are here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With