MLUG: Re: [MLUG] how to convert pdf to image (e.g., jpg or png)?
Re: [MLUG] how to convert pdf to image (e.g., jpg or png)?
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Wed, 14 Mar 2007, Mark A. Haidekker wrote:

For this purpose, I use Ghostscript. Here is a little shell script that facilitates things. First, print to a PostScript file, then call gsconv soandso.ps:

#!/bin/sh
echo Conversion of $1 to file plot.ppm
gs -sDEVICE=ppm -r300 -sOutputFile=~/plot.ppm $1

Nice! So what I needed was jpg, which is doable. I compared results with png16m, but jpg was better in this application (files 1/5th the size with no noticable loss of quality). Here's how I'd rewrite that line of the script:


gs -sDEVICE=jpeg -r100 -sOutputFile=${1}.jpg ${1}.pdf

Now, there is still one problem. Instead of just doing the first page, that method tries to do additional pages and I have to hit Ctrl-C to stop it after the first page has completed. If I tell it to stop after one page, I still have to hit return and go to a "GS>" prompt. It also puts out some unneeded messages to stdout. So...

-dLastPage=1  Makes it stop after one page.

 -q     Quiet startup: suppress normal startup messages, and also do the
        equivalent of -dQUIET.

 -dBATCH
        Causes Ghostscript to exit after processing all files  named  on
        the  command  line, rather than prompting for further PostScript
        commands.

 -dNOPAUSE
        Disables the prompt and pause at the end of each page. This  may
        be  desirable  in converting documents or for applications where
        another program is driving Ghostscript.

Using all those neat tricks I end up with something that does exactly what I want, which is this:

gs -q -dBATCH -dNOPAUSE -dLastPage=1 -sDEVICE=jpeg -r100 -sOutputFile=${1}.jpg ${1}.pdf

The Sci Am covers are 812x1075 with -r100.

Thanks a million!  That's a very nice solution.

Mike

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members