Create a script to print a PDF booklet (nice for papers)
February 21, 2010 6 Comments
After a considerable time without posts I’m back with a script that I’ve been using to print papers and other documents in book format with two pages side-by-side, which it is being very useful!
#!/bin/bash # usage: pdf2book # acroread settings: # [x] auto rotate and center # [x] choose paper source by pdf page size # [x] use custom paper size when needed # [x] portrait FILE=$(echo $1 | sed 's/.pdf//') echo "$ pdfcrop $FILE.pdf --margins 12" pdfcrop $FILE.pdf --margins 12 echo "$ pdftops $FILE-crop.pdf" pdftops $FILE-crop.pdf echo "$ psbook $FILE-crop.ps book-$FILE.ps" psbook $FILE-crop.ps book-$FILE.ps echo "ps2pdf book-$FILE.ps book-$FILE.pdf" ps2pdf book-$FILE.ps book-$FILE.pdf echo "$ pdfnup book-$FILE.pdf --nup 2x1" pdfnup book-$FILE.pdf --nup 2x1 echo "pdftk book-$FILE-2x1.pdf cat 1-endE output ready-$FILE.pdf" pdftk book-$FILE-2x1.pdf cat 1-endE output ready-$FILE.pdf echo "$FILE-crop.pdf $FILE-crop.ps book-$FILE.ps book-$FILE.pdf book-$FILE-2x1.pdf" rm $FILE-crop.pdf $FILE-crop.ps book-$FILE.ps book-$FILE.pdf book-$FILE-2x1.pdf
Basically, it first cut the blank space in the margins of the pdf using pdfcrop (which cames with pdftk), convert it to ps using pdftops (instead of pdf2ps, I’m not sure but this algorithm seems better), then it change the order of pages (put the last and the first in the page 1, the penultimate and the second in page 2 and so) with psbook (which cames with psutils package), convert back to pdf using ps2pdf, rotate 90º to print it as a portrait (standard to lpr) with pdftk and finishes removing the temporary files.
I couldn’t perform it using page-crunch, a nice tip you have posted before to print multiple pages per sheet. There is a book flag there but it put the PDF in sequential order two side per page (If I have done it right).