PHP Converting PDF's to images -dUseCropBox
I'm trying to convert a PDF to an image and I need to make sure that the -dUseCropBox parameter is specified for when calling Ghostscript. Can this be done?
convert "/var/www/vhosts/site.co.uk/httpdocs/uploads/source_pdf/PP4SDpdf.pdf" -resize 500X500 "/var/www/vhosts/site.co.uk/httpdocs/uploads/image_pdf/SaturdayTest.jpg"
It works well but just need to get the Ghostscript par开发者_如何转开发ameter in.
Is it acceptable for you to run Ghostscript directly (instead of having convert
call it anyway) ?
I ask, because convert
does not do the PDF => JPEG conversion by itself. It calls Ghostscript as its 'delegate' to do the job. So for convert
to work you need to have access to a functional Ghostscript installation on that system anyway... .
But how to add custom parameters to convert
s commandline to pass them through to Ghostscript's commandline isn't easy to figure out. Ghostscript's commandline isn't exactly easy either, but at least it is fully documented at a well-known place (see Use.htm, Devices.htm and Ps2pdf.htm there).
Here is a command that would convert your input PDF to a series of JPEGs (one file for each PDF page). I'm assuming Windows -- for Linux just replace the ^
by \
and gswin32c.exe
by gs
:
gswin32c.exe ^
-o "d:/path with spaces/to/output/dir/input_page_%03d.jpeg ^
-sDEVICE=jpeg ^
-dJPEQ=95 ^
-r720 ^
-g5000x5000 ^
-dUseCropBox=true ^
"d:/path/to/input.pdf"
Explanation:
-dJPEGQ
sets the JPEG quality. Accepts integer values in the range0..100
. Higher values create bigger files... (Ghostscript's default for JPEGQ is set to 75.)-r720
sets a (rather high) resolution of 720dpi. Higher values create bigger files... (Ghostscript's default for its jpeg output device would be 72dpi.)-g5000x5000
gives the file dimension in pixels. (Note: when decreasing the-r...
value you MUST also accordingly decrease the-g...
value to keep the same dimension in userspace inches or mm.)
You could also add -dPDFFitPage=true
if that is useful for you.
The switch for imagemagick (the convert-command) is:
-define pdf:use-cropbox=true
see http://www.imagemagick.org/Usage/formats/#ps_reading
精彩评论