PDFTK(1) | General Commands Manual | PDFTK(1) |
pdftk - A handy tool for manipulating PDF
pdftk <input PDF files | - | PROMPT>
[ input_pw <input PDF owner passwords | PROMPT> ]
[ <operation> <operation arguments> ]
[ output <output filename | - | PROMPT> ]
[ encrypt_40bit | encrypt_128bit ]
[ allow <permissions> ]
[ owner_pw <owner password | PROMPT> ]
[ user_pw <user password | PROMPT> ]
[ flatten ] [ need_appearances ]
[ compress | uncompress ]
[ keep_first_id | keep_final_id ] [ drop_xfa ] [
drop_xmp ]
[ verbose ] [ dont_ask | do_ask ]
Where:
<operation> may be empty, or:
[ cat | shuffle | burst | rotate |
generate_fdf | fill_form |
background | multibackground |
stamp | multistamp |
dump_data | dump_data_utf8 |
dump_data_fields | dump_data_fields_utf8 |
dump_data_annots |
update_info | update_info_utf8 |
attach_files | unpack_files ]
For Complete Help: pdftk --help
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)
A summary of options is included below.
<input PDF handle>=<input PDF filename>
Handles are often omitted. They are useful when specifying PDF passwords or page ranges, later.
For example: A=input1.pdf QT=input2.pdf M=input3.pdf
<input PDF handle>=<input PDF file owner password>
If handles are not given, then passwords are associated with input files by order.
Most pdftk features require that encrypted input PDF are accompanied by the ~owner~ password. If the input PDF has no owner password, then the user password must be given, instead. If the input PDF has no passwords, then no password should be given.
When running in do_ask mode, pdftk will prompt you for a password if the supplied password is incorrect or none was given.
If this optional argument is omitted, then pdftk runs in 'filter' mode. Filter mode takes only one PDF input and creates a new PDF after applying all of the output options, like encryption and compression.
<input PDF handle>[<begin page number>[-<end page number>[<qualifier>]]][<page rotation>]
Where the handle identifies one of the input PDF files, and the beginning and ending page numbers are one-based references to pages in the PDF file. The qualifier can be even or odd, and the page rotation can be north, south, east, west, left, right, or down.
If a PDF handle is given but no pages are specified, then the entire PDF is used. If no pages are specified for any of the input PDFs, then the input PDFs' bookmarks are also merged and included in the output.
If the handle is omitted from the page range, then the pages are taken from the first input PDF.
The even qualifier causes pdftk to use only the even-numbered PDF pages, so 1-6even yields pages 2, 4 and 6 in that order. 6-1even yields pages 6, 4 and 2 in that order.
The odd qualifier works similarly to the even.
The page rotation setting can cause pdftk to rotate pages and documents. Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page's rotation.
If no arguments are passed to cat, then pdftk combines all input PDFs in the order they were given to create the output.
NOTES:
* <end page number> may be less than <begin page
number>.
* The keyword end may be used to reference the final page of a
document instead of a page number.
* Reference a single page by omitting the ending page number.
* The handle may be used alone to represent the entire PDF document, e.g.,
B1-end is the same as B.
* You can reference page numbers in reverse order by prefixing them with
the letter r. For example, page r1 is the last page of the
document, r2 is the next-to-last page of the document, and rend is the
first page of the document. You can use this prefix in ranges, too, for
example r3-r1 is the last three pages of a PDF.
Page Range Examples without Handles:
1-endeast - rotate entire document 90 degrees
5 11 20 - take single pages from input PDF
5-25oddwest - take odd pages in range, rotate 90 degrees
6-1 - reverse pages in range from input PDF
Page Range Examples Using Handles:
Say A=in1.pdf B=in2.pdf, then:
A1-21 - take range from in1.pdf
Bend-1odd - take all odd pages from in2.pdf in reverse order
A72 - take a single page from in1.pdf
A1-21 Beven A72 - assemble pages from both in1.pdf and in2.pdf
Awest - rotate entire in1.pdf document 90 degrees
B - use all of in2.pdf
A2-30evenleft - take the even pages from the range, remove 90
degrees from each page's rotation
A A - catenate in1.pdf with in1.pdf
Aevenwest Aoddeast - apply rotations to even pages, odd pages from
in1.pdf
Awest Bwest Bdown - catenate rotated documents
pdftk in.pdf burst owner_pw foopass
[<begin page number>[-<end page number>[<qualifier>]]][<page rotation>]
The qualifier can be even or odd, and the page rotation can be north, south, east, west, left, right, or down.
Each option sets the page rotation as follows (in degrees): north: 0, east: 90, south: 180, west: 270, left: -90, right: +90, down: +180. left, right, and down make relative adjustments to a page's rotation.
The given order of the pages doesn't change the page order in the output.
pdftk form.pdf fill_form data.fdf output form.filled.pdf
If the input FDF file includes Rich Text formatted data in addition to plain text, then the Rich Text data is packed into the form fields as well as the plain text. Pdftk also sets a flag that cues Reader/Acrobat to generate new field appearances based on the Rich Text data. So when the user opens the PDF, the viewer will create the Rich Text appearance on the spot. If the user's PDF viewer does not support Rich Text, then the user will see the plain text data instead. If you flatten this form before Acrobat has a chance to create (and save) new field appearances, then the plain text field data is what you'll see.
Also see the flatten and need_appearances options.
pdftk in.pdf background back.pdf output out.pdf
Pdftk uses only the first page from the background PDF and applies it to every page of the input PDF. This page is scaled and rotated as needed to fit the input page. You can use - to pass a background PDF into pdftk via stdin.
If the input PDF does not have a transparent background (such as a PDF created from page scans) then the resulting background won't be visible -- use the stamp operation instead.
This operation does not change the metadata stored in the PDF's XMP stream, if it has one. (For this reason you should include a ModDate entry in your updated info with a current date/timestamp, format: D:YYYYMMDDHHmmSS, e.g. D:201307241346 -- omitted data after YYYY revert to default values.)
For example:
pdftk in.pdf update_info in.info output out.pdf
pdftk in.pdf attach_files table1.html table2.html to_page 6 output out.pdf
pdftk report.pdf unpack_files output ~/atts/
or, interactively:
pdftk report.pdf unpack_files output PROMPT
The permissions section may include one or more of the following features:
This option is only useful when running pdftk on a single input PDF. When assembling a PDF from multiple inputs using pdftk, any XFA data in the input is automatically omitted.
Alternatively, you might prefer to remove the XMP stream from the PDF altogether -- that's what this option does. Note that objects inside the PDF might have their own, separate XMP metadata streams, and that drop_xmp does not remove those. It only removes the PDF's document-level XMP stream.
When running in dont_ask mode, pdftk will over-write files with its output without notice.
This is a port of pdftk to java. See
https://gitlab.com/marcvinyals/pdftk
The original program can be found at www.pdftk.com
Original author of pdftk is Sid Steward (sid.steward at pdflabs dot com).
May 11, 2018 |