1 |
On Thu, Jul 9, 2020 at 9:35 AM John Blinka <john.blinka@×××××.com> wrote: |
2 |
> |
3 |
> app-text/pdftk |
4 |
> |
5 |
> pdftk page-1.pdf page-2.pdf cat output both.pdf |
6 |
> |
7 |
> Lots of other useful tricks it can do with pdf files. |
8 |
> |
9 |
|
10 |
+1 for pdftk if you can stand java. I'm sure there are some GUI-based |
11 |
options that you might prefer, but pdftk is great for command line |
12 |
use. |
13 |
|
14 |
I'll go ahead and offer this script that takes as input a bunch of pdf |
15 |
files, and it combines them all adding blank pages as needed to make |
16 |
them all even. This is used to generate a combined PDF suitable for |
17 |
double-sided printing on a single-sided printer if I have a bunch of |
18 |
PDFs I want to print in batch. |
19 |
|
20 |
#!/bin/bash |
21 |
for file in *.pdf |
22 |
do |
23 |
#get the number of pages |
24 |
numberofpages=`pdftk "$file" dump_data | sed -e |
25 |
'/NumberOfPages/!d;s/NumberOfPages: //'` |
26 |
echo -n "$file" 'has' $numberofpages 'pages, ' |
27 |
|
28 |
uneven=$(($numberofpages % 2)) |
29 |
if [ $uneven == 1 ] |
30 |
then |
31 |
echo 'which is uneven - added 1 more' |
32 |
tempfile=`mktemp` |
33 |
pdftk A="$file" B=/usr/local/share/blank.pdf cat A B1 output "$tempfile" |
34 |
mv $tempfile $file |
35 |
else |
36 |
echo 'which is even' |
37 |
fi |
38 |
done |
39 |
|
40 |
pdftk *.pdf cat output out.pdf |
41 |
|
42 |
|
43 |
|
44 |
-- |
45 |
Rich |