How can I move page images in PDFs more left or right?

We have a bunch of scanned pages (about 600), for which each PDF viewer displays an image with zero margin on the right edge, but at a distance of about 2 inches to the left. (Presumably the wrong setting was used during the scan ...)

We want to print these pages, preferably as a booklet. Is there a way to transfer all the page images to the center and have these pages in a more pleasant way in this PDF format? Can Ghostscript do this? Is it possible to do this using any other method, for example, programmatically using some PDF processing library?

+7
pdf ghostscript
source share
2 answers

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

  • PostScript has a setpagedevice statement that takes a PageOffset parameter;
  • Ghostscript will process PostScript code snippets if you pass them with -c ... at the command line;
  • Ghostscript can evaluate and apply (some) PostScript code even for direct PDF => PDF conversions.

Now try this command line to move all images 1 inch (== 72pt) to the left:

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

( -dPDFSETTINGS=/prepress I inserted so as not to lose the image quality for scanning ...)

+8
source share

you can use iText to move, scale or crop pdf pages

you need to define a PdfReader for the source file and a document for your target file, then you iterate over the pages, if Reader, create a new page in the document and add the original page as a template to the new page (moving, scaling, etc., wherever you are wanted to)

  PdfReader reader = new PdfReader( input ); int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.getHeight(); float height = psize.getWidth(); Document document = new Document(new Rectangle(height, width)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( output )); document.open(); PdfContentByte cb = writer.getDirectContent(); int i = 0; while (i < n) { i++; document.newPage(); PdfImportedPage page = writer.getImportedPage(reader, i); cb.addTemplate(page, factor, 0, 0, factor, left, down); } document.close(); 
+1
source share

All Articles