On Thu, Jul 9, 2020 at 9:35 AM John Blinka <john.bli...@gmail.com> wrote:
>
> app-text/pdftk
>
> pdftk page-1.pdf page-2.pdf cat output both.pdf
>
> Lots of other useful tricks it can do with pdf files.
>

+1 for pdftk if you can stand java.  I'm sure there are some GUI-based
options that you might prefer, but pdftk is great for command line
use.

I'll go ahead and offer this script that takes as input a bunch of pdf
files, and it combines them all adding blank pages as needed to make
them all even.  This is used to generate a combined PDF suitable for
double-sided printing on a single-sided printer if I have a bunch of
PDFs I want to print in batch.

#!/bin/bash
for file in *.pdf
do
  #get the number of pages
  numberofpages=`pdftk "$file" dump_data | sed -e
'/NumberOfPages/!d;s/NumberOfPages: //'`
  echo -n "$file" 'has' $numberofpages 'pages, '

  uneven=$(($numberofpages % 2))
  if [ $uneven == 1 ]
  then
    echo 'which is uneven - added 1 more'
    tempfile=`mktemp`
    pdftk A="$file" B=/usr/local/share/blank.pdf cat A B1 output "$tempfile"
    mv $tempfile $file
  else
    echo 'which is even'
  fi
done

pdftk *.pdf cat output out.pdf



-- 
Rich

Reply via email to