#StackBounty: #pdf #ghostscript #pdftk #postscript "Place" Letter Sized PDF to Larger pdf at specific position

Bounty: 50

Lulu is a print on-demand service. Part of the creation process is to upload a cover. The “cover” is 1 page that has the dimensions 17.25 inches wide by 11.25 inches high. There is a 0.125 “bleed area” on all edges that will be cut off after printing. Excluding the bleed, the left 8.5 inches is the back cover and the right 8.5 inches is the front cover. See the image below for a visual aide.

I have a 1 page pdf called cover-page.pdf on letter paper that I want to use as the front cover.

$ pdfinfo cover-page.pdf | grep Size
Page size:      612 x 792 pts (letter)

Using only open source command line tools, I want to create a new file, cover.pdf, from cover-page.pdf per the specification above by “placing” it in the right side of cover template.

Lulu Cover

I have investigated using pdftk, ImageMagick, and ghostscript. After reading the commands available for pdftk, that appears to be the wrong tool. I tried using ImageMagick and crafted the following:

 convert cover-page.pdf 
   -background white -gravity SouthEast -extent 1233x801 
   -background white -gravity None -extent 1242x810 

This worked, but it uses raster transformations.

The last thing I looked into was Ghostscript. I am the least confident in my ghostscript abilities, but I did make some progress. I managed to create a blank pdf with the correct dimensions using gs -sDEVICE=pdfwrite -o cover.pdf -dDEVICEWIDTHPOINTS=1242 -dDEVICEHEIGHTPOINTS=810. However, as soon as I add -dPDFFitPage -f cover-page.pdf to process the file, the page size becomes 810 x 1048.24 and the page rotates. I assume this is to “fit” the aspect ratio of cover-page.pdf. So, my final (unsuccessful) command is:

  -sDEVICE=pdfwrite -o cover.pdf 
  -dPDFFitPage -f cover-page.pdf

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.