views:

340

answers:

2

I've been using ghostscript to convert my single figure plots rendered in PDF to png:

gswin32c -sDEVICE=png16m -r300x300 -sOutputFile=junk.png -dBATCH -dNOPAUSE Figure_001-a.pdf

This works in the sense I get a png out and it contians the plot. But it contains a huge amount of white space as well (an example source image: http://cdsweb.cern.ch/record/1258681/files/Figure_001-a.pdf). If you view it in Acrobat you'll note there is no white space around the plot. If you use the above command line you'll find the plot is only about 1/3 of the space.

When doing the same thing with an eps file I run into the same problem. However, there is the command-line parameter -dEPSCrop that one can pass to get the PS rendering engine to pay attention to the BoundingBox.

I need the similar argument for rendering PDF's. I was not able to find it in docs (nor even the EPSCrop, actually).

A: 

Have you tried using pdfcrop using pdftex (comes with texlive for example) or (not tried yet) the python script pdfcrop?

I have a similar workflow using the first tool mentioned.

Patrick
A: 

There are various options to control which "media size" Ghostscript renders a given input:

-dPDFFitPage
-dUseTrimBox
-dUseCropBox

With PDFFitPage Ghostscript will render to the current page device size (usually the default page size). With UseTrimBox it will use the TrimBox (and it will at the same time set the PageSize to that value). With UseCropBox it will use the CropBox (and it will at the same time set the PageSize to that value). By default (give no parameter), Ghostscript will render using the MediaBox.

For your example, it looks like adding "-dUseCropBox" will do the job you're expecting.

Note, you can additionally control the overall size of your output by using "-sPAPERSIZE" (select amongst all pre-defined values Ghostscript knows) or (for more flexibility) use "-dDEVICEWIDTHPOINTS=NNN -dDEVICEHEIGHTPOINTS=NNN".

pipitas