Pdftk notes

From raju

combine multiple files into a single pdf

combine two files

    pdftk file1.pdf file2.pdf cat output combined.pdf
    

combine N files

    pdftk file1.pdf file2.pdf ... fileN.pdf cat output combined.pdf
    

Wildcards can also be used

    pdftk *.pdf cat output combined.pdf
    

dummy


To replace pg-16 of a pdf with another pdf. Assume that the later consists of only one single page.

pdftk A=initial.pdf B=insertAsPg16.pdf cat A1-15 B1 A17-end output final.pdf

Tested using

% pdftk --version

pdftk 2.01 a Handy Tool for Manipulating PDF Documents
Copyright (C) 2003-13, Sid Steward - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Grab the first two pages in a pdf and reverse the order

pdftk A=inverted.pdf cat A2 A1 output corrected.pdf


To get pages 11-19 (inclusive on both sides) of a pdf file

pdftk A=in.pdf cat A11-19 output out.pdf

Tested using

% pdftk --version

pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


To extract all the odd pages of a pdf file

pdftk A=all_pages.pdf cat A1-endodd output oddpages.pdf

Tested using

% pdftk --version

pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


The filenames should use absolute paths instead of '~'. For example

% pdftk A=~/books/thinkpython.pdf cat A44 output indentation.pdf

fails with

Error: Unable to find file.
Error: Failed to open PDF file: 
   ~/books/thinkpython.pdf
Errors encountered.  No output created.
Done.  Input errors, so no output created.

but the command below succeeds.

% pdftk A=/home/rajulocal/books/thinkpython.pdf cat A44 output indentation.pdf

Tested using

% pdftk --version

pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

encrypt a pdf with password

pdftk in.pdf output out.pdf user_pw foo

Ref:- http://askubuntu.com/questions/258848/is-there-a-tool-that-can-add-a-password-to-a-pdf-file

Note:- I was unable to encrypt a pdf file using Adobe Reader X1 Version 11.0.13 . I could not find the "Tools pane" described in http://www.adobe.com/content/dam/Adobe/en/products/acrobat/pdfs/adobe-acrobat-xi-protect-pdf-file-with-permissions-tutorial-ue.pdf. I also tried File -> Properties -> Security after opening the file. However all the options in that window are greyed out. So I can't add a password from there as well. I was told that Adobe Standard can do this but it costs money whereas pdftk is free. In the end, using pdftk was a no brainer.

store a pdf without password

    pdftk secured.pdf input_pw foopass output unsecured.pdf
    

external links