How can I shift page images in PDF files more to the left or to the right?

simplybest55 picture simplybest55 · Aug 10, 2010 · Viewed 8k times · Source

We have a bunch of scanned pages (about 600) for which every PDF viewer displays the image with zero margin on the right edge, but about 2 inch margin on the left. (Presumably while scanning, there was a wrong setting used...)

We want to print these pages, preferably as a booklet. Is there a way to permanently shift all page images towards the center and have the PDF display these pages also in a more pleasing way? Can Ghostscript do that? Can one do this with some other method, such as programatically with the help of some PDF processing library?

Answer

Kurt Pfeifle picture Kurt Pfeifle · Aug 14, 2010

If you don't want to write your own program code (as Nikolaus suggested), but use a Ghostscript commandline instead, you need to know 3 things:

  1. PostScript has a setpagedevice operator that takes a PageOffset parameter;
  2. Ghostscript will process snippets of PostScript code if you pass them with -c ... on the commandline;
  3. Ghostscript can evaluate and apply (some) PostScript code even for direct PDF=>PDF conversions.

Now try this commandline to shift all page images by 1 inch (==72pt) to the left:

gswin32c.exe ^
  -sDEVICE=pdfwrite ^
  -o c:/path/to/output/pdf-shifted-by-1-inch-to-left.pdf ^
  -dPDFSETTINGS=/prepress ^
  -c "<</PageOffset [-72 0]>> setpagedevice" ^
  -f c:/path/to/input/pdf-original.pdf

(The -dPDFSETTINGS=/prepress I put in in order to not loose any picture quality of the scans...)