-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_joined.awk
41 lines (34 loc) · 986 Bytes
/
prepare_joined.awk
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
BEGIN {
PdfLeft = ARGV[1]
PdfRight = ARGV[2]
print "Will join '" PdfLeft "' and '" PdfRight "'..."
"pdftk " PdfLeft " dumpdata | grep NumberOfPages" | getline
NumberOfPages = $2
print "Number of pages: " NumberOfPages
explodeToPages(PdfLeft)
explodeToPages(PdfRight)
cmd = "pdftk "
cleanup = "rm "
for (i=1; i<=NumberOfPages; i++) {
pdf2 = sprintf("%s-%d.pdf %s-%d.pdf ", PdfLeft, i, PdfRight, i)
cmd = cmd pdf2
cleanup = cleanup pdf2
}
cmd = cmd "cat output combined.pdf"
runOrError("Building combined.pdf", cmd)
runOrError("Cleanup", cleanup)
}
function explodeToPages(file) {
runOrError("Exploding to pages: '" file,
"pdftk '" file "' burst output '" file "-%d.pdf'")
}
function runOrError(msg, cmd) {
printf "%s...", msg
if (system(cmd) == 0) {
close(cmd)
print " done."
return
}
print "error running: " cmd >> "/dev/stderr"
exit 1
}