2

I need an automation for PDFs that is a variant of multiple pages per sheet. In this case, I don't need a simple two-pages-per-sheet solution, that's easy. I need to take hand-written notes side by side to the pages. So, here it goes:

Given a PDF, I'd like to print it with two pages per sheet, however, one page must be blank, like this:

+-------+-------+
|  P.1  | white |
|       |       |
|       |       |
+-------+-------+

+-------+-------+
|  P.2  | white |
|       |       |
|       |       |
+-------+-------+

etc.

Has anyone an idea to write a script that can automate this?

PS. I know how to do this in LaTeX, but I'd like to avoid the big gun...

senseiwa
  • 2,369
  • 3
  • 24
  • 47

3 Answers3

3

If avoiding LaTeX does not mean avoiding usage of any tools that depend on it, then PDFJam (Debian package is texlive-extra-utils) could be of help, see q/a: Gluing (Imposition) PDF documents.

Otherwise you are probably better off with a little script that converts .pdf file pages to images and then merges them with a blank image, ImageMagick is able to do those things.

Community
  • 1
  • 1
unserializable
  • 106
  • 1
  • 5
2

With Ubuntu:

# install packages
sudo apt-get install enscript ghostscript pdfjam pdftk

source="source.pdf"
output="output.pdf"

# create ps with one blank page
echo -n | enscript -p blank.ps

# convert p2 to pdf
ps2pdf blank.ps blank.pdf

# get number of pages of $source
num=$(pdftk "$source" dump_data | grep -Po 'NumberOfPages: \K.*')

# create string with new page numbers
for ((i=1;i<=$num;i++)); do pages="$pages A$i-$i B1-1"; done

# create pdf with white pages
pdftk A="$source" B=blank.pdf cat $pages output tmp.pdf

# create pdf with two pages on one side
pdfjam tmp.pdf --nup 2x1 --landscape --outfile "$output"

# clean up
rm blank.ps blank.pdf tmp.pdf
Cyrus
  • 84,225
  • 14
  • 89
  • 153
1

I have a solution which does not print exactly the layout which you want, but prints the page centered in the landscape sheet, like so:

+---+-------+----+
|   |  P.1  |    |
|   |       |    |
|   |       |    |
+---+-------+----+

+---+-------+----+
|   |  P.2  |    |
|   |       |    |
|   |       |    |
+---+-------+----+

If you're goal is to create free space for hand annotations, this layout might be better since it lets you write the annotation closer to the printed text.

The following script relies on pdfjam which uses LaTeX under the hood. Probably adding a few more command line arguments for pdfjam would get exactly what you are looking for.

#!/bin/bash
if [ "$#" -ne 1 ]; then
    echo "usage: $0 PDF_filename..."
    echo
    echo "This script takes a PDF file as command line arguments,"
    echo "and generates a new, landscape-formatted PDF file, where every "
    echo "page has very large margins which may be useful for editorial notes"
    echo
    echo "Requires: pdfjam, which is installed by the apt-get package texlive-extra-utils"
    exit 1
fi
command -v pdfjam >/dev/null 2>&1 || { echo >&2 "I require pdfjam but it's not installed.  Do an apt install of texlive-extra-utils to get it on Ubuntu. Aborting."; exit 1; }
pdfjam --batch --nup 1x1 --suffix widemargin --landscape "$@"
algal
  • 27,584
  • 13
  • 78
  • 80