#!/bin/sh #Convert PDFs to show a specific number of input pages per output page #Uses pdflatex with pdfpages package #Will not accept filenames starting with a dash #Warning: is vulnerable to LaTeX injection attack and does no checking filenum=0 #LaTeX header LaTeXDoc="\documentclass[letterpaper]{article} \usepackage[letterpaper,pdftex]{geometry} \usepackage{pdfpages} \begin{document} " #Parameter defaults pages="-" nup="1x2" angle="90" error="" command="$0" #Get temporary working space tempdir="`mktemp`" tempfile="$tempdir/a.tex" rm "$tempdir" mkdir "$tempdir" while [ -z "$error" -a "$#" -gt 0 ] do param="$1" shift case "$param" in "-1") nup="1x1" angle="0" ;; "-2") nup="1x2" angle="90" ;; "-4") nup="2x2" angle="0" ;; "-6") nup="2x3" angle="0" ;; "--nup") nup="$1" shift ;; "--angle") angle="$1" shift ;; "--pages") pages="$1" shift ;; -*) error="Unknown parameter \"${param}\"" ;; #Default is the filename *) filename="$param" if [ \! -f "$filename" ] then error="Cannot find file \"$filename\"." else cp "$filename" "${tempdir}/$((++filenum)).pdf" LaTeXDoc="${LaTeXDoc} \includepdf[pages=$pages, nup=$nup, angle=$angle, frame=false, fitpaper=false, trim=0 0 0 0, delta=0 0, offset=0 0, scale=1.0, turn=true, noautoscale=false, column=false, columnstrict=false, openright=false]{${filenum}.pdf}" fi ;; esac done if [ "$filenum" = 0 ] then error="You must specify a PDF file." fi if [ -n "$error" ] then echo "${error} pdfnup puts multiple pages of PDFs together on a page into a file named out.pdf. Proper usage: pdfnup [-(1|2|4|6)] [--nup x] [--angle ] [--pages ] [[more options...] [...]] Examples: $command -2 data.pdf #Put 2 per page $command --nup 1x2 --angle 90 --pages - data.pdf #Equivalent to -2 $command -4 --pages 3-7 data.pdf #2x2 per page of pages 3-7 $command -1 data.pdf #Put 1 on letter paper $command -1 1.pdf 2.pdf #Concatenate 1 and 2 $command -2 1.pdf -4 2.pdf #Put 2x1 of 1 followed by 2x2 of 2 $command -1 1.pdf 2.pdf ; #Combine 1.pdf and 2.pdf as mv out.pdf in.pdf ; #2x1 without skipping pages $command -2 in.pdf #in between PDFs " > /dev/stderr exit 1 fi LaTeXDoc="${LaTeXDoc} \end{document}" echo "$LaTeXDoc" > "$tempfile" pushd "$tempdir" > /dev/null pdflatex "$tempfile" < /dev/null > /dev/null 2> /dev/null if [ "$?" \!= 0 ] then error="Error processing PDF" fi popd > /dev/null mv "$tempdir"/a.pdf out.pdf if [ "$?" \!= 0 ] then error="Can't move file" fi rm -r "$tempdir" if [ -n "$error" ] then echo "$error" exit 1 fi echo "out.pdf created"