pdftk
is a command like tool to manipulate (merge, extract, encrypt, etc) pdf files. On Ubuntu you can install from it from the repositories, like:
sudo apt install pdftk
Extract pages from a long pdf
Take long.pdf
and cut out pages 5-14 to output_pp5_14.pdf
.
pdftk long.pdf cat 5-14 output_pp5_14.pdf`
Merge two or more files
You should list each files to add, use cat output
option and name your new merged file.
pdftk file1.pdf file2.pdf cat output newfile_merged.pdf
To merge all pdf in a folder, you can use *
(wildcard) instead of listing each files.
Other
man pdftk
: “If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents. Use it to:
* Merge PDF Documents or Collate PDF Page Scans
* Split PDF Pages into a New Document
* Rotate PDF Documents or Pages
* Decrypt Input as Necessary (Password Required)
* Encrypt Output as Desired
* Fill PDF Forms with X/FDF Data and/or Flatten Forms
* Generate FDF Data Stencils from PDF Forms
* Apply a Background Watermark or a Foreground Stamp
* Report PDF Metrics, Bookmarks and Metadata
* Add/Update PDF Bookmarks or Metadata
* Attach Files to PDF Pages or the PDF Document
* Unpack PDF Attachments
* Burst a PDF Document into Single Pages
* Uncompress and Re-Compress Page Streams
* Repair Corrupted PDF (Where Possible)
Alternatives to pdftk
For page extraction
qpdf
- a CLI tool- any desktop pdf reader that can print to a file, such as
ocular
.
For merging files
pdfunite
- a CLI program (It is part of thepoppler-utils
package)
Credits:
- Make Tech Easier: How to Combine Multiple PDF Files With pdftk
- ask ubuntu: How can I extract a page range / a part of a PDF?