0

Some time I ago I found that that you can use postscript to make changes to pdf documents with Ghostscript. Available examples make the same changes to every page:

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

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

See also: Cropping a PDF using Ghostscript 9.01

But how could I set different offsets for different pages, without splitting up the pdf into separate files? For example move some pages to the right and some to the left.

I know of a way of doing this using pdftex but I was hoping to avoid this dependancy.

MJ Walsh
  • 593
  • 6
  • 11

1 Answers1

0

Well basically this is a PostScript question, because Ghostscript's PDF interpreter is (currently) written in PostScript so you can make changes to the PostScript graphics state which will affect the PDF interpreter, and take advantage of PostScript's language features to do programmatic tasks.

To do different things on each page you need to use a BeginPage or EndPage procedure. BeginPage is called at the start of every page, before the program is interpreted, and EndPage is called when the page is complete (ie on execution of a showpage).

You'll need a BeginPage procedure to modify the page setup before the page execution runs. This will be called with a count of the number of pages transmitted so far, so you can use that to make decisions about what you want to do.

NB the current PDF interpreter executes a setpagedevice on every page, because each page of a PDF can be a different size. This means some experimentation will be required to achieve your aims.

KenS
  • 30,202
  • 3
  • 34
  • 51