Reputation: 7132
I want to extract the first page of a PDF as PNG to do some image processing on it with this command:
$ gs -q -dNOPAUSE -dBATCH -dEPSCrop -sDEVICE=pngalpha -dLastPage=1 -sOutputFile='test.png' 'test2.pdf'
It works well for most PDFs but it adds a transparent margin on this one: http://ubuntuone.com/23676W4TJPyX6W2pkp5guG
Gimp
does it as expected (no margin), convert
has the same issue, -sDEVICE=jpeg
also.
Is there any way to avoid it ?
Upvotes: 2
Views: 2434
Reputation: 31139
Ghostscript doesn't add margins, and it certainly doesn't add transparent ones. THe problem is not with Ghostscript, its with your PDF file. You file contains:
/MediaBox [0 0 595 842] /CropBox [27.5 61.0 567.5 781.0]
Ghostscript uses the MediaBox, other viewers may or may not use the CropBox. If you read the GS documentation you will find the -dUseCropBox switch which directs GS to use the CropBox of a PDF file instead of the MediaBox when setting the media size.
-dEPSCrop isn't going to do anything at all with a PDF file.
Upvotes: 5
Reputation: 7132
For the record, If anyone runs into the same issue, I just found the proper switch: -dUseCropBox
. The final command is now:
$ gs -q -dUseCropBox -dNOPAUSE -dBATCH -sDEVICE=pngalpha -dLastPage=1 -sOutputFile='test.png' 'test2.pdf'
Upvotes: 2