QPDF(1) | User Commands | QPDF(1) |
qpdf - PDF transformation software
qpdf [ options ] infilename [ outfilename ]
The qpdf program is used to convert one PDF file to another equivalent PDF file. It is capable of performing a variety of transformations such as linearization (also known as web optimization or fast web viewing), encryption, and decryption of PDF files. It also has many options for inspecting or checking PDF files, some of which are useful primarily to PDF developers.
For a summary of qpdf's options, please run qpdf --help. A complete manual can be found at https://qpdf.readthedocs.io.
Read a PDF file, apply transformations or modifications, and write a new PDF file.
Usage: qpdf [infile] [options] [outfile]
OR qpdf --help[={topic|--option}]
Related Options:
Specify the name of a file whose contents are expected to contain a QPDFJob JSON file. Run qpdf --job-json-help for a description of the JSON input file format.
Meaning of exit codes:
Related Options:
Shell completion is supported with bash and zsh. Use eval $(qpdf --completion-bash) or eval $(qpdf --completion-zsh) to enable. The QPDF_EXECUTABLE environment variable overrides the path to qpdf that these commands output.
Related Options:
Help options provide some information about qpdf itself. Help options are only valid as the first and only command-line argument.
Related Options:
--help: provide general information and a list of topics --help=--option: provide help on a specific option --help=topic: provide help on a topic
General options control qpdf's behavior in ways that are not directly related to the operation it is performing.
Related Options:
Specify a password for an encrypted, password-protected file. Not needed for encrypted files without a password.
The first line of the specified file is used as the password. This is used in place of the --password option.
When qpdf needs to work with many files, as when merging large numbers of files, explicitly indicate whether files should be kept open. The default behavior is to determine this based on the number of files.
Set the threshold used by --keep-files-open, overriding the default value of 200.
Advanced control options control qpdf's behavior in ways that would normally never be needed by a user but that may be useful to developers or people investigating problems with specific files.
Related Options:
Fine-tune how qpdf controls encoding of Unicode passwords. Valid options are auto, bytes, hex-bytes, and unicode.
The options below tell qpdf to apply transformations that change the structure without changing the content.
Related Options:
Run qpdf --help=encryption for details.
Copy encryption details from the specified file instead of preserving the input file's encryption. Use --encryption-file-password to specify the encryption file's password.
If the file named in --copy-encryption requires a password, use this option to supply the password.
Setting --compress-streams=n prevents qpdf from compressing uncompressed streams. This can be useful if you are leaving some streams uncompressed intentionally.
When uncompressing streams, control which types of compression schemes should be uncompressed:
This option controls how streams are compressed in the output. It is less granular than the newer options, --compress-streams and --decode-level.
Parameters:
Set a compression level from 1 (least, fastest) to 9 (most, slowest) when compressing files with flate (used in zip and gzip), which is the default compression for most PDF files. You need --recompress-flate with this option if you want to change already compressed streams.
Normalize newlines to UNIX-style newlines in PDF content streams, which is useful for viewing them in a programmer's text editor across multiple platforms. This is also turned on by --qdf.
Control what qpdf does regarding object streams. Options:
Remove from a page's resource dictionary any resources that are not referenced in the page's contents. Parameters: "auto" (default), "yes", "no".
Don't externalize inline images smaller than this size. The default is 1,024. Use 0 for no minimum.
Force the PDF version of the output to be at least the specified version. The version number format is "major.minor[.extension-level]", which sets the version header to "major.minor" and the extension level, if specified, to "extension-level".
Force the output PDF file's PDF version header to be the specified value, even if the file uses features that may not be available in that version.
A full description of the page range syntax, with examples, can be found in the manual. In summary, a range is a comma-separated list of groups. A group is a number or a range of numbers separated by a dash. A group may be prepended by x to exclude its members from the previous group. A number may be one of
You can append :even or :odd to select every other page from the resulting set of pages, where :odd starts with the first page and :even starts with the second page. These are odd and even pages from the resulting set, not based on the original page numbers.
Modification options make systematic changes to certain parts of the PDF, causing the PDF to render differently from the original.
Related Options:
Run qpdf --help=page-selection for details.
Specify the file for the current page operation. This is used with --pages, --overlay, and --underlay and appears between the option and the terminating --. Run qpdf --help=page-selection for details.
Specify the page range for the current page operation with --pages. If omitted, all pages are selected. This is used with --pages and appears between --pages and --. Run qpdf --help=page-selection for details.
Collate rather than concatenate pages specified with --pages. With a numeric parameter, collate in groups of n. The default is 1. With comma-separated numeric parameters, take n from the first file, m from the second, etc. Run qpdf --help=page-selection for additional details.
This option causes qpdf to create separate output files for each page or group of pages rather than a single output file.
File names are generated from the specified output file as follows:
Page ranges are single page numbers for single-page groups or first-last for multi-page groups.
Overlay pages from another file on the output. Run qpdf --help=overlay-underlay for details.
Underlay pages from another file on the output. Run qpdf --help=overlay-underlay for details.
Push page annotations into the content streams. This may be necessary in some case when printing or splitting files. Parameters: "all", "print", "screen".
Rotate specified pages by multiples of 90 degrees specifying either absolute or relative angles. "angle" may be 0, 90, 180, or 270. You almost always want to use +angle or -angle rather than just angle, as discussed in the manual. Run qpdf --help=page-ranges for help with page ranges.
Don't optimize images whose width is below the specified value.
Don't optimize images whose height is below the specified value.
Don't optimize images whose area in pixels is below the specified value.
Set page labels (explicit page numbers) for the entire file. Each label-spec has the form
first-page:[type][/start[/prefix]]
where
The first label spec must have a first-page value of 1, indicating the first page of the document. If multiple page label specs are specified, they must be given in increasing order.
If multiple page label specs are specified, they must be given in increasing order.
A given page label spec causes pages to be numbered according to that scheme starting with first-page and continuing until the next label spec or the end of the document. If you want to omit numbering starting at a certain page, you can use first-page: as the spec.
Example: "1:r 5:D" would number the first four pages i through iv, then the remaining pages with Arabic numerals starting with 1 and continuing sequentially until the end of the document. For additional examples, please consult the manual.
Create encrypted files. Usage:
--encrypt [--user-password=user-password] [--owner-password=owner-password] --bits=key-length [options] --
OR
--encrypt user-password owner-password key-length [options] --
The first form, with flags for the passwords and bit length, was introduced in qpdf 11.7.0. Only the --bits option is is mandatory. This form allows you to use any text as the password. If passwords are specified, they must be given before the --bits option.
The second form has been in qpdf since the beginning and wil continue to be supported. Either or both of user-password and owner-password may be empty strings.
The key-length parameter must be either 40, 128, or 256. The user and/or owner password may be omitted. Omitting either password enables the PDF file to be opened without a password. Specifying the same value for the user and owner password and specifying an empty owner password are both considered insecure.
Encryption options are terminated by "--" by itself.
40-bit encryption is insecure, as is 128-bit encryption without AES. Use 256-bit encryption unless you have a specific reason to use an insecure format, such as testing or compatibility with very old viewers. You must use the --allow-weak-crypto to create encrypted files that use insecure cryptographic algorithms. The --allow-weak-crypto flag appears outside of --encrypt ... -- (before --encrypt or after --).
Available options vary by key length. Not all readers respect all restrictions. Different PDF readers respond differently to various combinations of options. Sometimes a PDF viewer may show you restrictions that differ from what you selected. This is probably not a bug in qpdf.
Options for 40-bit only:
--annotate=[y|n] restrict comments, filling forms, and signing
--extract=[y|n] restrict text/graphic extraction
--modify=[y|n] restrict document modification
--print=[y|n] restrict printing
Options for 128-bit or 256-bit:
--accessibility=[y|n] restrict accessibility (usually ignored)
--annotate=[y|n] restrict commenting/filling form fields
--assemble=[y|n] restrict document assembly
--extract=[y|n] restrict text/graphic extraction
--form=[y|n] restrict filling form fields
--modify-other=[y|n] restrict other modifications
--modify=modify-opt control modify access by level
--print=print-opt control printing access
--cleartext-metadata prevent encryption of metadata
For 128-bit only:
--use-aes=[y|n] indicates whether to use AES encryption
--force-V4 forces use of V=4 encryption handler
For 256-bit only:
--force-R5 forces use of deprecated R=5 encryption
--allow-insecure allow user password with empty owner password
Values for print-opt:
none disallow printing
low allow only low-resolution printing
full allow full printing
Values for modify-opt:
none allow no modifications
assembly allow document assembly only
form assembly + filling in form fields and signing
annotate form + commenting and modifying forms
all allow full document modification
Related Options:
Set the user password of the encrypted file.
Set the owner password of the encrypted file.
Specify the encryption key length. For best security, always use a key length of 256.
This option is ignored except with very old encryption formats. The current PDF specification does not allow restriction of document accessibility. This option is not available with 40-bit encryption.
Enable/disable modifying annotations including making comments and filling in form fields. For 128-bit and 256-bit encryption, this also enables editing, creating, and deleting form fields unless --modify-other=n or --modify=none is also specified.
Enable/disable document assembly (rotation and reordering of pages). This option is not available with 40-bit encryption.
Enable/disable text/graphic extraction for purposes other than accessibility.
Enable/disable whether filling form fields is allowed even if modification of annotations is disabled. This option is not available with 40-bit encryption.
Enable/disable modifications not controlled by --assemble, --annotate, or --form. --modify-other=n is implied by any of the other --modify options. This option is not available with 40-bit encryption.
For 40-bit files, modify-opt may only be y or n and controls all aspects of document modification.
For 128-bit and 256-bit encryption, modify-opt values allow enabling and disabling levels of restriction in a manner similar to how some PDF creation tools do it. modify-opt values map to other combinations of options as follows:
all: allow full modification (the default) annotate: --modify-other=n form: --modify-other=n --annotate=n assembly: --modify-other=n --annotate=n --form=n none: --modify-other=n --annotate=n --form=n --assemble=n
Control what kind of printing is allowed. For 40-bit encryption, print-opt may only be y or n and enables or disables all printing. For 128-bit and 256-bit encryption, print-opt may have the following values:
none: disallow printing low: allow low-resolution printing only full: allow full printing (the default)
Enables/disables use of the more secure AES encryption with 128-bit encryption. Specifying --use-aes=y forces the PDF version to be at least 1.6. This option is only available with 128-bit encryption. The default is "n" for compatibility reasons. Use 256-bit encryption instead.
Use the --pages option to select pages from multiple files. Usage:
qpdf in.pdf --pages --file=input-file [--range=page-range] [--password=password] [...] -- out.pdf
OR
qpdf in.pdf --pages input-file [--password=password] [page-range] [...] -- out.pdf
Between --pages and the -- that terminates pages option, repeat the following:
--file=filename [--range=page-range] [--password=password] [options]
For compatibility, the file and range can be specified positionally. qpdf versions prior to 11.9.0 require --password=password to immediately follow the filename. In the older syntax, repeat the following:
filename [--password=password] [page-range]
Document-level information, such as outlines, tags, etc., is taken from in.pdf and is preserved in out.pdf. You can use --empty in place of an input file to start from an empty file and just copy pages equally from all files. You can use "." as a shorthand for the primary input file (if not --empty). In the above example, "." would refer to in.pdf.
Use --password=password to specify the password for a password-protected input file. If the same input file is used more than once, you only need to supply the password the first time. If the page range is omitted, all pages are selected.
Run qpdf --help=page-ranges for help with page ranges.
Use --collate=n to cause pages to be collated in groups of n pages (default 1) instead of concatenating the input. Use --collate=i,j,k,... to take i from the first, then j from the second, then k from the third, then i from the first, etc.
Examples:
qpdf in.pdf --pages . a.pdf b.pdf 1-z:even -- out.pdf
qpdf --empty --pages a.pdf b.pdf --password=x z-1 c.pdf 3,6
More examples are in the manual.
These options allow pages from another file to be overlaid or underlaid on the primary output. Overlaid pages are drawn on top of the destination page and may obscure the page. Underlaid pages are drawn below the destination page. Usage:
{--overlay|--underlay} [--file=]file
[--password=password]
[--to=page-range]
[--from=[page-range]]
[--repeat=page-range]
--
Note the use of "--" by itself to terminate overlay/underlay options.
For overlay and underlay, a file and optional password are specified, along with a series of optional page ranges. The default behavior is that each page of the overlay or underlay file is imposed on the corresponding page of the primary output until it runs out of pages, and any extra pages are ignored. You can also give a page range with --repeat to cause those pages to be repeated after the original pages are exhausted.
This options are repeatable. Pages will be stacked in order of appearance: first underlays, then the original page, then overlays.
Run qpdf --help=page-ranges for help with page ranges.
Related Options:
Specify the range of pages in the primary output to apply overlay/underlay to. See qpdf --help=page-ranges for help with the page range syntax.
Specify pages from the overlay/underlay file that are applied to the destination pages. See qpdf --help=page-ranges for help with the page range syntax. The page range may be omitted if --repeat is used.
Specify pages from the overlay/underlay that are repeated after "from" pages have been exhausted. See qpdf --help=page-ranges for help with the page range syntax.
It is possible to list, add, or delete embedded files (also known as attachments) and to copy attachments from other files. See help on individual options for details. Run qpdf --help=add-attachment for additional details about adding attachments. See also --help=--list-attachments and --help=--show-attachment.
Related Options:
The --add-attachment flag and its options may be repeated to add multiple attachments. Run qpdf --help=add-attachment for details.
The --copy-attachments-from flag and its options may be repeated to copy attachments from multiple files. Run qpdf --help=copy-attachments for details.
Remove an embedded file using its key. Get the key with --list-attachments.
When a date is required, the date should conform to the PDF date format specification, which is "D:yyyymmddhhmmssz" where "z" is either literally upper case "Z" for UTC or a timezone offset in the form "-hh'mm'" or "+hh'mm'". Negative timezone offsets indicate time before UTC. Positive offsets indicate how far after. For example, US Eastern Standard Time (America/New_York) is "-05'00'", and Indian Standard Time (Asia/Calcutta) is "+05'30'".
Examples:
The options listed below appear between --add-attachment and its terminating "--".
Related Options:
Specify the key to use for the attachment in the embedded files table. It defaults to the last element (basename) of the attached file's filename.
Specify the filename to be used for the attachment. This is what is usually displayed to the user and is the name most graphical PDF viewers will use when saving a file. It defaults to the last element (basename) of the attached file's filename.
Specify the attachment's creation date in PDF format; defaults to the current time. Run qpdf --help=pdf-dates for information about the date format.
Specify the attachment's modification date in PDF format; defaults to the current time. Run qpdf --help=pdf-dates for information about the date format.
Specify the mime type for the attachment, such as text/plain, application/pdf, image/png, etc.
Supply descriptive text for the attachment, displayed by some PDF viewers.
The options listed below appear between --copy-attachments-from and its terminating "--".
To copy attachments from a password-protected file, use the --password option after the file name.
Related Options:
Prepend a prefix to each key; may be needed if there are duplicate attachment keys. This affects the key only, not the file name.
These options provide tools for inspecting PDF files. When any of the options in this section are specified, no output file may be given.
Related Options:
0: the file is encrypted 1: not used 2: the file is not encrypted
This can be used with password-protected files even if you don't know the password.
0: a password, other than as supplied, is required 1: not used 2: the file is not encrypted 3: the file is encrypted, and correct password (if any) has been supplied
Show the contents of the given object. This is especially useful for inspecting objects that are inside of object streams (also known as "compressed objects").
Write the contents of the specified attachment to standard output as binary data. Get the key with --list-attachments.
Show information about the PDF file in JSON format. Please see the JSON chapter in the qpdf manual for details.
Related Options:
Generate a JSON representation of the file. This is described in depth in the JSON section of the manual. "version" may be a specific version or "latest" (the default). Run qpdf --json-help for a description of the generated JSON object.
Describe the format of the JSON output by writing to standard output a JSON object with the same keys and with values containing descriptive text.
This option is repeatable. If given, only the specified top-level keys will be included in the JSON output. Otherwise, all keys will be included. With --json-output, when not given, only the "qpdf" key will appear in the output.
This option is repeatable. If given, only specified objects will be shown in the "objects" key of the JSON output. Otherwise, all objects will be shown.
When used with --json, this option controls whether streams in json output should be omitted, written inline (base64-encoded) or written to a file. If "file" is chosen, the file will be the name of the output file appended with -nnn where nnn is the object number. The prefix can be overridden with --json-stream-prefix. The default is "none", except when --json-output is specified, in which case the default is "inline".
When used with --json-stream-data=file, --json-stream-data=file-prefix sets the prefix for stream data files, overriding the default, which is to use the output file name. Whatever is given here will be appended with -nnn to create the name of the file that will contain the data for the stream stream in object nnn.
Implies --json=version. Changes default values for certain options so that the JSON output written is the most faithful representation of the original PDF and contains no additional JSON keys. See also --json-stream-data, --json-stream-prefix, and --decode-level.
Update a PDF file from a JSON file. Please see the "qpdf JSON" chapter of the manual for information about how to use this option.
The options below are useful when writing automated test code that includes files created by qpdf or when testing qpdf itself.
Related Options:
Write the first pass of linearization to the named file. The resulting file is not a valid PDF file. This option is useful only for debugging qpdf.
For a summary of qpdf's options, please run qpdf --help. A complete manual can be found at https://qpdf.readthedocs.io.
qpdf version 11.9.0 |