Best way to take thumbnails of PDF.

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
wpK

Best way to take thumbnails of PDF.

Post by wpK »

Hey all,

I'm currently trying to take a PDF file, create images for each page in two different sizes with decent quality. I'm using GhostScript and Mogrify right now which seems to be doing pretty well but I'm wondering if there is anything I could be doing to "improve" it.

I have a file that is located in /tmp/ that has a random name and ends with the .tmp extension. So lets say the original PDF file is /tmp/8967867897687.tmp, I'd run this:

Code: Select all

/usr/bin/gs -sDEVICE=png256 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dDOINTERPOLATE -sOutputFile=/tmp/8967867897687.tmp.%d.xlarge -dSAFER -dBATCH -dNOPAUSE -r200% /tmp/8967867897687.tmp
After that runs, I then run Mogrify twice to generate a large and a small version:

Code: Select all

/usr/bin/mogrify -resize 600x -depth 8 -format large.png /tmp/8967867897687.tmp.*.xlarge

Code: Select all

/usr/bin/mogrify -resize 145x -depth 8 -format small.png /tmp/8967867897687.tmp.*.large.png
As you can see I did a kind of "hack" with Mogrify to allow me to re-size from the large to a new format, and then resizing the new images again without ever replacing the older ones. The one downside to this is you then have the files with names of:

Code: Select all

/tmp/8967867897687.tmp.1.large.small.png
/tmp/8967867897687.tmp.2.large.png
/tmp/8967867897687.tmp.2.xlarge
/tmp/8967867897687.tmp.1.large.png
/tmp/8967867897687.tmp.1.xlarge
/tmp/8967867897687.tmp.2.large.small.png
Note: The PDF file in this example is only 2 pages, but the number of pages vary.

Filenames don't matter at all since these are just temporary and I'll be renaming them when transferring them later on. The application I'm writing is in Java and I'm running these commands from Java.

Is this the correct way to do it? Is there anyway to make it any faster without losing image quality? Would it be faster to just run a loop and call convert for each page/thumbnail instead of mogrify?

Any suggestions / improvements would be greatly appreciated. Thanks in advanced.
Post Reply