Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fit to page size in ghostscript (with a possibly corrupt input)

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.

like image 478
keflavich Avatar asked Nov 15 '11 18:11

keflavich


1 Answers

-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.

like image 164
KenS Avatar answered Dec 10 '22 07:12

KenS