qpdf 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

qpdf 命令安装:


-bash/zsh: qpdf: command not found

#Windows (WSL2)
sudo apt-get update sudo apt-get install qpdf

#Debian
apt-get install qpdf

#Ubuntu
apt-get install qpdf

#Alpine
apk add qpdf

#Arch Linux
pacman -S qpdf

#Kali Linux
apt-get install qpdf

#CentOS
yum install qpdf

#Fedora
dnf install qpdf

#OS X
brew install qpdf

#Raspbian
apt-get install qpdf

#Dockerfile
dockerfile.run/qpdf

#Docker
docker run cmd.cat/qpdf qpdf

qpdf 命令补充说明:


QPDF 是一个程序,可以对 PDF 文件进行结构化,内容保留的转换。它可能被称为 pdf-to-pdf 之类的东西。它还为PDF制作软件的开发人员或只想查看PDF文件内部信息以了解其工作原理的人们提供了许多有用的功能。

使用 QPDF,可以将对象从一个 PDF 文件复制到另一个文件中,并可以操纵 PDF 文件中的页面列表。这样就可以合并和分割 PDF 文件。QPDF 库还使您可以从头开始创建 PDF 文件。在这种模式下,您负责提供文件的所有内容,而 QPDF 库负责处理对象的所有语法表示形式,交叉引用表的创建,以及(如果使用它们的话)对象流,加密,线性化,和其他语法细节。您仍然有责任自行生成 PDF 内容。

QPDF 的设计几乎没有外部依赖项,因此它故意非常轻巧。QPDF 不是 PDF 内容创建库,PDF 查看器或能够将 PDF 转换为其他格式的程序。特别是,QPDF 对 PDF 内容流的语义一无所知。如果您正在寻找可以做到的事情,那么应该去别处。但是,一旦有了有效的 PDF 文件,就可以使用 QPDF 来转换您原来的 PDF 创建无法处理的文件。例如,许多程序会生成简单的PDF文件,但无法对其进行密码保护,对其进行网络优化或执行该类型的其他转换。

qpdf 命令语法:


qpdf [ options ] infilename [ outfilename ]

qpdf 命令选项:


--help
Display command-line invocation help.

--version
Display the current version of qpdf.

--copyright
Show detailed copyright information.

--show-crypto
Show a list of available crypto providers, each on a line by itself. The default provider is always listed first. See Section 2.3, “Crypto Providers” for more information about crypto providers.

--completion-bash
Output a completion command you can eval to enable shell completion from bash.

--completion-zsh
Output a completion command you can eval to enable shell completion from zsh.

--password=password
Specifies a password for accessing encrypted files. Note that you can use @filename or @- as described above to put the password in a file or pass it via standard input so you can avoid specifying it on the command line.

--is-encrypted
Silently exit with status 0 if the file is encrypted or status 2 if the file is not encrypted. This is useful for shell scripts. Other options are ignored if this is given. This option is mutually exclusive with --requires-password. Both this option and --requires-password exit with status 2 for non-encrypted files.

--requires-password
Silently exit with status 0 if a password (other than as supplied) is required. Exit with status 2 if the file is not encrypted. Exit with status 3 if the file is encrypted but requires no password or the correct password has been supplied. This is useful for shell scripts. Note that any supplied password is used when opening the file. When used with a --password option, this option can be used to check the correctness of the password. In that case, an exit status of 3 means the file works with the supplied password. This option is mutually exclusive with --is-encrypted. Both this option and --is-encrypted exit with status 2 for non-encrypted files.

--verbose
Increase verbosity of output. For now, this just prints some indication of any file that it creates.

--progress
Indicate progress while writing files.

--no-warn
Suppress writing of warnings to stderr. If warnings were detected and suppressed, qpdf will still exit with exit code 3.

--linearize
Causes generation of a linearized (web-optimized) output file.

--replace-input
If specified, the output file name should be omitted. This option tells qpdf to replace the input file with the output. It does this by writing to infilename.~qpdf-temp# and, when done, overwriting the input file with the temporary file. If there were any warnings, the original input is saved as infilename.~qpdf-orig.

--copy-encryption=file
Encrypt the file using the same encryption parameters, including user and owner password, as the specified file. Use --encrypt-file-password to specify a password if one is needed to open this file. Note that copying the encryption parameters from a file also copies the first half of /ID from the file since this is part of the encryption parameters.

--encrypt-file-password=password
If the file specified with --copy-encryption requires a password, specify the password using this option. Note that only one of the user or owner password is required. Both passwords will be preserved since QPDF does not distinguish between the two passwords. It is possible to preserve encryption parameters, including the owner password, from a file even if you don't know the file's owner password.

--encrypt options --
Causes generation an encrypted output file. Please see Section 3.4, “Encryption Options” for details on how to specify encryption parameters.

--decrypt
Removes any encryption on the file. A password must be supplied if the file is password protected.

--password-is-hex-key
Overrides the usual computation/retrieval of the PDF file's encryption key from user/owner password with an explicit specification of the encryption key. When this option is specified, the argument to the --password option is interpreted as a hexadecimal-encoded key value. This only applies to the password used to open the main input file. It does not apply to other files opened by --pages or other options or to files being written.

Most users will never have a need for this option, and no standard viewers support this mode of operation, but it can be useful for forensic or investigatory purposes. For example, if a PDF file is encrypted with an unknown password, a brute-force attack using the key directly is sometimes more efficient than one using the password. Also, if a file is heavily damaged, it may be possible to derive the encryption key and recover parts of the file using it directly. To expose the encryption key used by an encrypted file that you can open normally, use the --show-encryption-key option.

--suppress-password-recovery
Ordinarily, qpdf attempts to automatically compensate for passwords specified in the wrong character encoding. This option suppresses that behavior. Under normal conditions, there are no reasons to use this option. See Section 3.10, “Unicode Passwords” for a discussion

--password-mode=mode
This option can be used to fine-tune how qpdf interprets Unicode (non-ASCII) password strings passed on the command line. With the exception of the hex-bytes mode, these only apply to passwords provided when encrypting files. The hex-bytes mode also applies to passwords specified for reading files. For additional discussion of the supported password modes and when you might want to use them, see Section 3.10, “Unicode Passwords”. The following modes are supported:

auto: Automatically determine whether the specified password is a properly encoded Unicode (UTF-8) string, and transcode it as required by the PDF spec based on the type encryption being applied. On Windows starting with version 8.4.0, and on almost all other modern platforms, incoming passwords will be properly encoded in UTF-8, so this is almost always what you want.

unicode: Tells qpdf that the incoming password is UTF-8, overriding whatever its automatic detection determines. The only difference between this mode and auto is that qpdf will fail with an error message if the password is not valid UTF-8 instead of falling back to bytes mode with a warning.

bytes: Interpret the password as a literal byte string. For non-Windows platforms, this is what versions of qpdf prior to 8.4.0 did. For Windows platforms, there is no way to specify strings of binary data on the command line directly, but you can use the @filename option to do it, in which case this option forces qpdf to respect the string of bytes as provided. This option will allow you to encrypt PDF files with passwords that will not be usable by other readers.

hex-bytes: Interpret the password as a hex-encoded string. This provides a way to pass binary data as a password on all platforms including Windows. As with bytes, this option may allow creation of files that can't be opened by other readers. This mode affects qpdf's interpretation of passwords specified for decrypting files as well as for encrypting them. It makes it possible to specify strings that are encoded in some manner other than the system's default encoding.

--rotate=[+|-]angle[:page-range]
Apply rotation to specified pages. The page-range portion of the option value has the same format as page ranges in Section 3.5, “Page Selection Options”. If the page range is omitted, the rotation is applied to all pages. The angle portion of the parameter may be either 90, 180, or 270. If preceded by + or -, the angle is added to or subtracted from the specified pages' original rotations. Otherwise the pages' rotations are set to the exact value. For example, the command qpdf in.pdf out.pdf --rotate=+90:2,4,6 --rotate=180:7-8 would rotate pages 2, 4, and 6 90 degrees clockwise from their original rotation and force the rotation of pages 7 through 9 to 180 degrees regardless of their original rotation, and the command qpdf in.pdf out.pdf --rotate=180 would rotate all pages by 180 degrees.

--keep-files-open=[yn]
This option controls whether qpdf keeps individual files open while merging. Prior to version 8.1.0, qpdf always kept all files open, but this meant that the number of files that could be merged was limited by the operating system's open file limit. Version 8.1.0 opened files as they were referenced and closed them after each read, but this caused a major performance impact. Version 8.2.0 optimized the performance but did so in a way that, for local file systems, there was a small but unavoidable performance hit, but for networked file systems, the performance impact could be very high. Starting with version 8.2.1, the default behavior is that files are kept open if no more than 200 files are specified, but that the behavior can be explicitly overridden with the --keep-files-open flag. If you are merging more than 200 files but less than the operating system's max open files limit, you may want to use --keep-files-open=y, especially if working over a networked file system. If you are using a local file system where the overhead is low and you might sometimes merge more than the OS limit's number of files from a script and are not worried about a few seconds additional processing time, you may want to specify --keep-files-open=n. The threshold for switching may be changed from the default 200 with the --keep-files-open-threshold option.

--keep-files-open-threshold=count
If specified, overrides the default value of 200 used as the threshold for qpdf deciding whether or not to keep files open. See --keep-files-open for details.

--pages options --
Select specific pages from one or more input files. See Section 3.5, “Page Selection Options” for details on how to do page selection (splitting and merging).

--collate
When specified, collate rather than concatenate pages from files specified with --pages. See Section 3.5, “Page Selection Options” for additional details.

--split-pages=[n]
Write each group of n pages to a separate output file. If n is not specified, create single pages. Output file names are generated as follows:

If the string %d appears in the output file name, it is replaced with a range of zero-padded page numbers starting from 1.

Otherwise, if the output file name ends in .pdf (case insensitive), a zero-padded page range, preceded by a dash, is inserted before the file extension.

Otherwise, the file name is appended with a zero-padded page range preceded by a dash.

Page ranges are a single number in the case of single-page groups or two numbers separated by a dash otherwise. For example, if infile.pdf has 12 pages

qpdf --split-pages infile.pdf %d-out would generate files 01-out through 12-out

qpdf --split-pages=2 infile.pdf outfile.pdf would generate files outfile-01-02.pdf through outfile-11-12.pdf

qpdf --split-pages infile.pdf something.else would generate files something.else-01 through something.else-12

Note that outlines, threads, and other global features of the original PDF file are not preserved. For each page of output, this option creates an empty PDF and copies a single page from the output into it. If you require the global data, you will have to run qpdf with the --pages option once for each file. Using --split-pages is much faster if you don't require the global data.

--overlay options --
Overlay pages from another file onto the output pages. See Section 3.6, “Overlay and Underlay Options” for details on overlay/underlay.

--underlay options --
Overlay pages from another file onto the output pages. See Section 3.6, “Overlay and Underlay Options” for details on overlay/underlay.

qpdf 命令实例:


qpdf 从 PDF 文件中提取第 1-3、56-10 页,并将其另存为:

qpdf --empty --pages input.pdf 1-3,5,6-10 -- output.pdf

qpdf 合并(连接)PDF 文件列表,并将结果另存为:

qpdf --empty --pages file1.pdf 1,6-8 --pages file2.pdf 3,4,5 -- output.pdf

qpdf 将每组 n 页写入给定文件名模式的单独输出文件:

qpdf --split-pages=n input.pdf out_%d.pdf

qpdf 以给定角度旋转 PDF 的某些页面:

qpdf --rotate=90:2,4,6 --rotate=180:7-8 input.pdf output.pdf

qpdf 从受密码保护的文件中删除密码:

qpdf --password=password --decrypt input.pdf output.pdf

qpdf 命令扩展阅读:




qpdf 命令评论