forked from geromueller/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreparePDFComment
59 lines (50 loc) · 1.89 KB
/
preparePDFComment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#This is a small script modifying page $2 such as it has double size with the right column empty for comments. It makes use of pdftk and pdfjam. The Outputfile may not be the same as the inputfile
PDFPATH=$1
PAGE=$2
OUTFILE=$3
function modifyPDF {
PDFPATH=$1
PAGE=$2
OUTFILE=$3
#three alternatives for extracting the page which has to be edited and adding an empty page
#pdftk $PDFPATH cat $PAGE output /tmp/editpage.pdf
#pdfjam /tmp/editpage.pdf '1,{}' --outfile /tmp/editpage.pdf
#pdfjam --quiet $PDFPATH "'$PAGE,{}'" --outfile /tmp/editpage.pdf
#pdfjam --quiet --landscape --nup 2x1 /tmp/editpage.pdf --outfile /tmp/editpageA3.pdf
pdfjam --quiet --landscape --nup 2x1 $PDFPATH $PAGE,{} --outfile /tmp/editpageA3.pdf
NPAGES=$(pdftk $PDFPATH dump_data | /bin/grep -i NumberOfPages | sed 's/[^0-9]*//')
if [ $PAGE == "1" ]
then
pdftk A=$PDFPATH B=/tmp/editpageA3.pdf cat B A2-end output $OUTFILE
elif [ $PAGE == $NPAGES ]
then
pdftk A=$PDFPATH B=/tmp/editpageA3.pdf cat A1-$(($NPAGES-1)) B output $OUTFILE
else
pdftk A=$PDFPATH B=/tmp/editpageA3.pdf cat "A1-$(($PAGE-1))" B "A$(($PAGE+1))-end" output $OUTFILE
fi
rm /tmp/editpageA3.pdf
}
function modifyAll {
PDFPATH=$1
OUTFILE=$2
PAGES=""
NPAGES=$(pdftk $PDFPATH dump_data | /bin/grep -i NumberOfPages | sed 's/[^0-9]*//')
for ((i=1; i<=$NPAGES; i++))
do
PAGES=${PAGES}"$i"",{},"
done
# Remove last character
PAGES=${PAGES%?}
pdfjam --quiet --landscape --nup 2x1 $PDFPATH $PAGES --outfile $OUTFILE
}
if [ -z "$OUTFILE" ]
then
OUTFILE="comments.pdf"
fi
if [ "$PAGE" = "all" ]
then
modifyAll $PDFPATH $OUTFILE
else
modifyPDF $PDFPATH $PAGE $OUTFILE
fi