pdftk
Published on Aug 26, 2012 by Sachin.
pdftk
can be an excellent tool for manupilating PDFs if you know
some handy commands
Note: I prefer Ghostscript(gs
) over pdftk
. Please refer this post to see gs
commands examples.
Merge pages
Suppose I have some PDF pages like
1: front.pdf toc.pdf 2: auth_colo.pdf part1.pdf 3: chap01.pdf chap02.pdf 4: part2.pdf chap03.pdf 5: chap04.pdf chap05.pdf 6: part3.pdf app_A.pdf 7: app_B.pdf index.pdf
If I want to merge all the pdf’s into a single book(file), my command would be
pdftk front.pdf toc.pdf auth_colo.pdf part1.pdf chap01.pdf...index.pdf cat output my_full_book.pdf
this will create a pdf file in the same order specified. \.pdf*
may also work if I don’t care about page ordering. Remember that
my_full_book.pdf
is output file name and cat output
are output
flags.
Removing a page
Suppose I want to remove page number 3 then my command would be
pdftk my_full_book.pdf cat 1-2 4-end output full_book_with_page2-removed.pdf
In the above example, I skipped page number(s) which I want to remove, in this case, page-3. The above command means, I want pages to be included from 1 to 2, I don’t want page number 3, so skip it, then start from page 4 till the end.
The syntax goes like this
pdftk PDF_FILE cat FROM-TO FROM-end output NEW_PDF_FILE_NAME
Rotating pages
If I want to rotate the first page at 90 degrees right, then
pdftk my_full_book.pdf cat 1R 2-end output page1_turned_right.pdf
In the same way if I want to rotate all odd pages from range 1 to 25 to 180 degrees, then
pdftk my_full_book.pdf cat 1-25oddD 26-end output odd_pages_down_book.pdf
Extract specific page(s)
Exact page 4 & 5
pdftk lkn.pdf cat 4 5 output page4and5.pdf
Extract page 9
pdftk lkn.pdf cat 9 output page9.pdf
Split pages as individual file
pdftk page4and5.pdf burst
Output file will be pg_0001.pdf
, pg_0002.pdf
…
Reference
For more info on pdftk
, visit its manual pages by typing
man pdftk