[Linux-disciples] Merging two .pdf or .docs for duplex printing
Dylan Thurston
dpt at math.columbia.edu
Fri Oct 17 21:22:53 EDT 2008
On Fri, Oct 17, 2008 at 07:06:20PM -0500, Karl Sokol wrote:
> Sure, if you're willing.
>
> The beginning is obvious.
> "pdftk" = run the program
> "A=doc-a.pdf B=doc-b.pdf" = defining/labeling A and B
> "cat" = combine A and B
>
> From that point, the conventions mostly escape me.
The command again:
pdftk A=doc-a.pdf B=doc-b.pdf cat `for (( i=1; i <= 100; i=i+1 )); do printf "A%d B1 " $i; done` output combined.pdf
Enclosing a command in backquotes (`) means to run the command and
insert the text in the command line. Thus,
% for (( i=1; i <= 100; i=i+1 )); do printf "A%d B1 " $i; done
produces
A1 B1 A2 B1 A3 B1 A4 B1 A5 B1 A6 B1 A7 B1 A8 B1 A9 B1 A10 B1 A11 B1 A12 B1 A13 B1 A14 B1 A15 B1 A16 B1 A17 B1 A18 B1 A19 B1 A20 B1 A21 B1 A22 B1 A23 B1 A24 B1 A25 B1 A26 B1 A27 B1 A28 B1 A29 B1 A30 B1 A31 B1 A32 B1 A33 B1 A34 B1 A35 B1 A36 B1 A37 B1 A38 B1 A39 B1 A40 B1 A41 B1 A42 B1 A43 B1 A44 B1 A45 B1 A46 B1 A47 B1 A48 B1 A49 B1 A50 B1 A51 B1 A52 B1 A53 B1 A54 B1 A55 B1 A56 B1 A57 B1 A58 B1 A59 B1 A60 B1 A61 B1 A62 B1 A63 B1 A64 B1 A65 B1 A66 B1 A67 B1 A68 B1 A69 B1 A70 B1 A71 B1 A72 B1 A73 B1 A74 B1 A75 B1 A76 B1 A77 B1 A78 B1 A79 B1 A80 B1 A81 B1 A82 B1 A83 B1 A84 B1 A85 B1 A86 B1 A87 B1 A88 B1 A89 B1 A90 B1 A91 B1 A92 B1 A93 B1 A94 B1 A95 B1 A96 B1 A97 B1 A98 B1 A99 B1 A100 B1
as output, and this is then put into the command, so we have
pdftk A=doc-a.pdf B=doc-b.pdf cat A1 B1 A2 B1 A3 B1 ... output combined.pdf
meaning take the pages from files A and B, as indicated, and put the
output in combined.pdf.
Now let's unpack the for loop:
for (( i=1; i <= 100; i=i+1 )); do printf "A%d B1 " $i; done
This executes the body ('printf "A%d B1 " $i') repeatedly, starting
off by setting 'i=1', repeating while 'i <= 100', and setting i to i+1
each step.
Finally, 'printf "A%d B1 " $i' prints out the string in the first
argument, with the %d replaced by the second argument.
Best,
Dylan
More information about the Linux-disciples
mailing list