An Open Access Peon

07 September 2007

Setting the output page size with ps2pdf

Ghostscript's ps2pdf utility converts Postscript format files into Adobe PDF. One drawback with this utility is that, by default, it always outputs in Ghostscript's default page size, regardless of the postscript document's page layout. This is probably sensible if the document is destined for printing, but at the moment PDF is also the best cross-platform way to express large spaces of graphics (in this case directed-tree graphs).

I've managed to get around this - mostly - as follows:

  1. Use ImageMagick's identify to get the Postscript document dimensions:
    $ identify test.ps
    test.ps PS 609x1528 609x1528+0+0 PseudoClass 256c 909kb 0.020u 0:01

  2. Execute ps2pdf with the -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS arguments
    $ ps2pdf -dDEVICEWIDTHPOINTS=679 -dDEVICEHEIGHTPOINTS=1598 test.ps test.pdf
What I haven't been able to work out is how to suppress the margins in the resulting PDF. To avoid the Postscript document being cropped I added 70 points to the width and height.