IT automation and programming tips

Jidouka.work

Mac Windows

Editing PDF file by pdftk

投稿日:

“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.

Insert a page

Insert “insert.pdf” after 2nd page of pdf_original.pdf and generate 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

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

Rotate a page

Rotate the 1st page of pdf_original.pdf 90 degrees and generate 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

Add watermark.pdf as watermark (front) of original.pdf and generate output.pdf

Watermark must be prepared as PDF beforehand.

Remove password

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.


-Mac, Windows
-,

Copyright© Jidouka.work , 2024 All Rights Reserved.