Search code examples
ghostscriptpostscript

Resize A4 PDF to SRA4 and center content


I'd like to be able to resize an A4 PDF to the slightly bigger SRA4 format, used by printing professionals. The content shouldn't be resized, but only centered. In other words, I'd like to add margins to my A4 document.

I managed more or less to do that with this Ghostscript (9.05) call:

gs -dPDFSETTINGS=/default -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite 
-sOutputFile=out.pdf -dDEVICEWIDTHPOINTS=637 -dDEVICEHEIGHTPOINTS=907 
-dFIXEDMEDIA in.pdf

The problem is that the A4 content is not centered in the SRA4 page, but is placed at the bottom left corner.

Any idea how to center the content?


Solution

  • I found a solution here, by using -c "<> setpagedevice", like so:

    gs -dPDFSETTINGS=/default -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite 
    -sOutputFile=out.pdf -dDEVICEWIDTHPOINTS=637 -dDEVICEHEIGHTPOINTS=907 
    -dFIXEDMEDIA -c "<</PageOffset [21 32]>> setpagedevice" -f in.pdf
    

    Content is perfectly centered in the SRA4 document.