“pdftk” is a command line tool which have a rich functions to edit PDF file.
The command line tool can edit pdf files even you do not launch a heavy application. In addition, the command line tool can be used in scripts, batch files. This enables you to edit PDFs in a short time, without human errors.
pdftk is released for Windows, Mac, and Linux.
Download page
PDFtk - The PDF Toolkit
pdftk path is set after pdftk installation. You can call pdftk in any directory.
Combine PDF files
Joint pdf1.pdf and pdf2.pdf, then generate combined.pdf.
1 2 |
pdftk pdf1.pdf pdf2.pdf cat output combined.pdf |
Insert a page
Insert “insert.pdf” after 2nd page of pdf_original.pdf and generate output.pdf
1 2 |
pdftk A=pdf_original.pdf B=insert.pdf cat A1-2 B A3-end output output.pdf |
A blank page pdf is needed when you want to insert a blank.
Remove a page
Generate output.pdf without the 3rd page of pdf_original.pdf
1 2 |
pdftk pdf_original.pdf cat 1-2 4-end output output.pdf |
There is no option to remove a page in the original pdf file. Only a way is generating a new pdf with specific pages.
Swap pages
Swap 2nd page and 3rd page in pdf_original.pdf and generate output.pdf
1 2 |
pdftk pdf_original.pdf cat 1 3 2 4-end output output.pdf |
Rotate a page
Rotate the 1st page of pdf_original.pdf 90 degrees and generate output.pdf
1 2 |
pdftk pdf_original.pdf cat 1right 2-end output output.pdf |
pdftk supports the following options for rotation. The right numbers are degrees.
north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down
Adding background, watermark
Add watermark.pdf as background of original.pdf and generate output.pdf
1 2 |
pdftk pdf_original.pdf background watermark.pdf output output.pdf |
Add watermark.pdf as watermark (front) of original.pdf and generate output.pdf
1 2 |
pdftk pdf_original.pdf stamp watermark.pdf output output.pdf |
Watermark must be prepared as PDF beforehand.
Remove password
1 2 |
pdftk protected.pdf input_pw testpass output unlocked.pdf |
The password is specified as an argument for input_pw. A pdf file without password is generated.
Split pages into each pdf file
pdftk pdf_original.pdf burst output bursted_pdf%02d.pdf
Insert blank pages
A pdf file which has only blank page is required beforehand. This pdf page is inserted to another file.
Extract text
pdftotext is required.
Convert to image
pdfimages is required.
Add page numbers
A pdf file which has only page numbers is required beforehand. These pages are added as background or stamp to another file.