CommandLinePageLayout

From XPUB & Lens-Based wiki

A BASH script to combine two things on a single PDF page -- a python text file (code.py) and a PNG image (bami.png).

Uses cups-pdf which creates a print-to-file "virtual printer" (named PDF) that when printed to (using the standard program lpr), creates a PDF. Note how PDF's (by default) are placed in ~/PDF and are named like the original with "pdf" as extension.

#!/bin/bash
# sudo apt-get install cups-pdf

lpr code.py -P PDF
mv ~/PDF/code.pdf .

lpr bami.png -P PDF
cp ~/PDF/bami.pdf .

# join into one document
pdftk code.pdf bami.pdf cat output 2page.pdf

# print to 2-up
lpr -o number-up=2 2page.pdf -P PDF
# wait for printing to finish... (or estimate the time in this case...)
sleep 5
mv ~/PDF/2page.pdf final.pdf