6

I'm trying to use ghostscript to convert a .ps file to a series of .png files, largely because I don't have a tolerable ps viewer.

This is the command I've used:

gs -dBATCH -dEPSCrop -dEPSFitPage -sDEVICE=png16m -r300  -dNOPAUSE -sOutputFile=neptune_111115_ob1-2_13pca_boloplots_%d.png neptune_111115_ob1-2_13pca_boloplots.ps 

(the .ps file is a multi-page postscript).

The outputs are partly off the page. I'd like the images to fit inside the page.

I can include example files, but they're pretty large - is there any particular part of the .ps file that would be helpful?

My suspicion is that the .ps file is specifying the bounding box incorrectly, but hacking the BB values didn't have any effect. The .ps file is written by IDL (ittvis' Interactive Data Language). I've also tried the above command without the -dEPS* commands without luck.

keflavich
  • 18,278
  • 20
  • 86
  • 118

1 Answers1

13

-dEPSCrop and -dEPSFitPage are mutually exclusive:

  • One crops the EPS to the BoundingBox specified in the comments.
  • The other scales up the EPS from the %%BoundingBox specified in the PS file's internal comments to fit the current media.

You can't really use both at the same time.

The file can't be an EPS file anyway, because you can't have multiple pages in an EPS file. So actually neither switch will have any effect (as you've discovered).

Either the PostScript requests a media size using setpage or setpagedevice, or it just uses whatever the currently set media is. My guess is that its just using the current media. Try setting -sPAPERSIZE=a4 and -sPAPERSIZE=letter.

If that works then the program does not request a media size. If it has no effect, then set -dFIXEDMEDIA in addition which will ignore subsequent requests to change the media size.

That should allow you to specify the correct media size, if you don't know what the media size should be then you can use the Ghostscript -sDEVICE=bbox device to find out.

Lastly, Ghostscript has a rudimentary display device which you can use to view the rendered output without first going to a PNG.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thanks Ken, didn't know exactly what the EPS commands did. However, I've tried both papersizes and fixedmedia with no luck. The gs viewer also shows the figures partly off the page. – keflavich Nov 16 '11 at 16:06
  • I'd need to see the file to comment further, but I can't see how it can evade the FIXEDMEDIA switch. You need to set both by the way, and set the PAPERSIZE first. What version of Ghostscript are you using ? – KenS Nov 17 '11 at 15:20