Qpdf : コマンドラインのPDFツール

TOP > Qpdf ツール


TT 2016 - Race Week - PokerStars Senior TT (15)

 

概要

Qpdf とはPDF にパスワードと詳細レベルのセキュリティ設定が出来るコマンドラインのソフトです。
PDF のマージや分割、画像の圧縮、PDF ファイルの内部構造の表示や点検操作、JSON形式への出力も出来ます。

PDF開発者に対してはPDF内部の高度な技術情報を提供します。

PDF文書を開く時に必要なユーザーパスワードが設定されていても操作できるのも大きな特徴です。よって使用には注意が必要です。

一般的なPDF編集ソフトでは無いので次のような編集機能はありません。
しおりの処理、ヘッダーとフッダーの編集、文字列の検索、コンテンツ内容の変更、印刷など。

注記:

  • 未確認、未検証の情報となっている場合も多々あります。ご注意ください。
  • Windows 版での使用を前提にした説明になります。

 

詳細

  1. フリー。 ライセンスは Version 2.0 of the Artistic License
  2. 最適化(リニアライズ:Web用最適化)機能
  3. パスワードによる詳細レベルでのセキュリティ設定機能
  4. マージ、分割機能、注釈、JSON出力
  5. 71頁のPDF+Html 解説書(英語)を同封
    詳しく(=難しく)書かれています。

 

ダウンロード

Qpdf 公式サイトが示す場所からダウンロードします。

最初にココをクリックして、以下を表示します。そして最新バージョンの 8.4.2 部分をクリックします。※以下の画像は8.1.0の旧バージョン。

Ver 8.4.2 について:
「ファイルを開くために使用されるWindowsコードのバッファオーバーランの修正」のみです。機能的な変更は有りません。よって、内容は 8.4.1 のままです。

Qpdf Windows 版のダウンロード

以下が表示されます。qpdf-8.4.2-bin-msvc32.zip (2019/5/20 時点)をクリックしてダウンロードします。※以下の画像は8.1.0の旧バージョン。

Qpdf Windows 版のダウンロード

MinGWでビルドした qpdf-8.4.2-bin-mingw32.zip も利用できます。共に64ビット版(~64.zip)も有ります。

 

インストール

ダウンロードしたzipファイル を解凍して適当なフォルダに入れるだけです。

実行はWindows の環境変数のPathを設定して使うか、フルパスを指定してQpdf.exe を起動します。

出来るだけインストール先フォルダに半角の空白文字を入らない様にしてください。コマンドラインでフルパスを指定する時に半角の空白が有ると動作に支障が出る場合が有るからです。

 

日本語の扱い

言語ファイル関連は存在しないので2バイト文字(日本語)には未対応と思われます。しかし、2バイト文字対応を必要とする処理が見当たらないので問題は無いでしょう。

 

マニュアル

オンラインマニュアル(英語)が公開されています。

  • PDF 71頁、ダウンロード可能
  • HTML

 

Copylight の内容

1 >qpdf -copyright 2 qpdf version 8.4.2 3 4 Copyright (c) 2005-2019 Jay Berkenbilt 5 QPDF is licensed under the Apache License, Version 2.0 (the "License"); 6 not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16 17 Versions of qpdf prior to version 7 were released under the terms 18 of version 2.0 of the Artistic License. At your option, you may 19 continue to consider qpdf to be licensed under those terms. Please 20 see the manual for additional information. 21 22 >


 Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
 

Help の内容

1 >qpdf -help 2 Usage: qpdf [ options ] { infilename | --empty } [ outfilename ] 3 4 An option summary appears below. Please see the documentation for details. 5 6 If @filename appears anywhere in the command-line, each line of filename 7 will be interpreted as an argument. No interpolation is done. Line 8 terminators are stripped. @- can be specified to read from standard input. 9 10 Note that when contradictory options are provided, whichever options are 11 provided last take precedence. 12 13 14 Basic Options 15 ------------- 16 17 --version show version of qpdf 18 --copyright show qpdf's copyright and license information 19 --help show command-line argument help 20 --completion-bash output a bash complete command you can eval 21 --completion-zsh output a zsh complete command you can eval 22 --password=password specify a password for accessing encrypted files 23 --verbose provide additional informational output 24 --progress give progress indicators while writing output 25 --no-warn suppress warnings 26 --linearize generated a linearized (web optimized) file 27 --copy-encryption=file copy encryption parameters from specified file 28 --encryption-file-password=password 29 password used to open the file from which encryption 30 parameters are being copied 31 --encrypt options -- generate an encrypted file 32 --decrypt remove any encryption on the file 33 --password-is-hex-key treat primary password option as a hex-encoded key 34 --suppress-password-recovery 35 do not attempt recovering from password string 36 encoding errors 37 --password-mode=mode control qpdf's encoding of passwords 38 --pages options -- select specific pages from one or more files 39 --collate causes files specified in --pages to be collated 40 rather than concatenated 41 --rotate=[+|-]angle[:page-range] 42 rotate each specified page 90, 180, or 270 degrees; 43 rotate all pages if no page range is given 44 --split-pages=[n] write each output page to a separate file 45 --overlay options -- overlay pages from another file 46 --underlay options -- underlay pages from another file 47 48 Note that you can use the @filename or @- syntax for any argument at any 49 point in the command. This provides a good way to specify a password without 50 having to explicitly put it on the command line. 51 52 If none of --copy-encryption, --encrypt or --decrypt are given, qpdf will 53 preserve any encryption data associated with a file. 54 55 Note that when copying encryption parameters from another file, all 56 parameters will be copied, including both user and owner passwords, even 57 if the user password is used to open the other file. This works even if 58 the owner password is not known. 59 60 The --password-is-hex-key option overrides the normal computation of 61 encryption keys. It only applies to the password used to open the main 62 file. This option is not ordinarily useful but can be helpful for forensic 63 or investigatory purposes. See manual for further discussion. 64 65 The --rotate flag can be used to specify pages to rotate pages either 66 90, 180, or 270 degrees. The page range is specified in the same 67 format as with the --pages option, described below. Repeat the option 68 to rotate multiple groups of pages. If the angle is preceded by + or -, 69 it is added to or subtracted from the original rotation. Otherwise, the 70 rotation angle is set explicitly to the given value. 71 72 If --split-pages is specified, each page is written to a separate output 73 file. File names are generated as follows: 74 * If the string %d appears in the output file name, it is replaced with a 75 zero-padded page range starting from 1 76 * Otherwise, if the output file name ends in .pdf (case insensitive), a 77 zero-padded page range, preceded by a dash, is inserted before the file 78 extension 79 * Otherwise, the file name is appended with a zero-padded page range 80 preceded by a dash. 81 Page ranges are single page numbers for single-page groups or first-last 82 for multipage groups. 83 84 85 Encryption Options 86 ------------------ 87 88 --encrypt user-password owner-password key-length flags -- 89 90 Note that -- terminates parsing of encryption flags. 91 92 Either or both of the user password and the owner password may be 93 empty strings. 94 95 key-length may be 40, 128, or 256 96 97 Additional flags are dependent upon key length. 98 99 If 40: 100 101 --print=[yn] allow printing 102 --modify=[yn] allow document modification 103 --extract=[yn] allow text/graphic extraction 104 --annotate=[yn] allow comments and form fill-in and signing 105 106 If 128: 107 108 --accessibility=[yn] allow accessibility to visually impaired 109 --extract=[yn] allow other text/graphic extraction 110 --print=print-opt control printing access 111 --assemble=[yn] allow document assembly 112 --annotate=[yn] allow commenting/filling form fields 113 --form=[yn] allow filling form fields 114 --modify-other=[yn] allow other modifications 115 --modify=modify-opt control modify access (old way) 116 --cleartext-metadata prevents encryption of metadata 117 --use-aes=[yn] indicates whether to use AES encryption 118 --force-V4 forces use of V=4 encryption handler 119 120 If 256, options are the same as 128 with these exceptions: 121 --force-V4 this option is not available with 256-bit keys 122 --use-aes this option is always on with 256-bit keys 123 --force-R5 forces use of deprecated R=5 encryption 124 125 print-opt may be: 126 127 full allow full printing 128 low allow only low-resolution printing 129 none disallow printing 130 131 modify-opt may be: 132 133 all allow full document modification 134 annotate allow comment authoring and form operations 135 form allow form field fill-in and signing 136 assembly allow document assembly only 137 none allow no modifications 138 139 The default for each permission option is to be fully permissive. Please 140 refer to the manual for more details on the modify options. 141 142 Specifying cleartext-metadata forces the PDF version to at least 1.5. 143 Specifying use of AES forces the PDF version to at least 1.6. These 144 options are both off by default. 145 146 The --force-V4 flag forces the V=4 encryption handler introduced in PDF 1.5 147 to be used even if not otherwise needed. This option is primarily useful 148 for testing qpdf and has no other practical use. 149 150 151 Password Modes 152 ---------------------- 153 154 The --password-mode controls how qpdf interprets passwords supplied 155 on the command-line. qpdf's default behavior is correct in almost all 156 cases, but you can fine-tune with this option. 157 158 bytes: use the password literally as supplied 159 hex-bytes: interpret the password as a hex-encoded byte string 160 unicode: interpret the password as a UTF-8 encoded string 161 auto: attempt to infer the encoding and adjust as needed 162 163 This is a complex topic. See the manual for a complete discussion. 164 165 166 Page Selection Options 167 ---------------------- 168 169 These options allow pages to be selected from one or more PDF files. 170 Whatever file is given as the primary input file is used as the 171 starting point, but its pages are replaced with pages as specified. 172 173 --keep-files-open=[yn] 174 --keep-files-open-threshold=count 175 --pages file [ --password=password ] [ page-range ] ... -- 176 177 For each file that pages should be taken from, specify the file, a 178 password needed to open the file (if any), and a page range. The 179 password needs to be given only once per file. If any of the input 180 files are the same as the primary input file or the file used to copy 181 encryption parameters (if specified), you do not need to repeat the 182 password here. The same file can be repeated multiple times. The 183 filename "." may be used to refer to the current input file. All 184 non-page data (info, outlines, page numbers, etc. are taken from the 185 primary input file. To discard this, use --empty as the primary 186 input. 187 188 By default, when more than 200 distinct files are specified, qpdf will 189 close each file when not being referenced. With 200 files or fewer, all 190 files will be kept open at the same time. This behavior can be overridden 191 by specifying --keep-files-open=[yn]. Closing and opening files can have 192 very high overhead on certain file systems, especially networked file 193 systems. The threshold of 200 can be modified with 194 --keep-files-open-threshold 195 196 The page range is a set of numbers separated by commas, ranges of 197 numbers separated dashes, or combinations of those. The character 198 "z" represents the last page. A number preceded by an "r" indicates 199 to count from the end, so "r3-r1" would be the last three pages of the 200 document. Pages can appear in any order. Ranges can appear with a 201 high number followed by a low number, which causes the pages to appear in 202 reverse. Repeating a number will cause an error, but the manual discusses 203 a workaround should you really want to include the same page twice. 204 205 If the page range is omitted, the range of 1-z is assumed. qpdf decides 206 that the page range is omitted if the range argument is either -- or a 207 valid file name and not a valid range. 208 209 The usual behavior of --pages is to add all pages from the first file, 210 then all pages from the second file, and so on. If the --collate option 211 is specified, then pages are collated instead. In other words, qpdf takes 212 the first page from the first file, the first page from the second file, 213 and so on until it runs out of files; then it takes the second page from 214 each file, etc. When a file runs out of pages, it is skipped until all 215 specified pages are taken from all files. 216 217 See the manual for examples and a discussion of additional subtleties. 218 219 220 Overlay and Underlay Options 221 ------------------------------- 222 223 These options allow pages from another file to be overlaid or underlaid 224 on the primary output. Overlaid pages are drawn on top of the destination 225 page and may obscure the page. Underlaid pages are drawn below the 226 destination page. 227 228 {--overlay | --underlay } file 229 [ --password=password ] 230 [ --to=page-range ] 231 [ --from=[page-range] ] 232 [ --repeat=page-range ] 233 -- 234 235 For overlay and underlay, a file and optional password are specified, along 236 with a series of optional page ranges. The default behavior is that each 237 page of the overlay or underlay file is imposed on the corresponding page 238 of the primary output until it runs out of pages, and any extra pages are 239 ignored. The page range options all take page ranges in the same form as 240 the --pages option. They have the following meanings: 241 242 --to: the pages in the primary output to which overlay/underlay is 243 applied 244 --from: the pages from the overlay/underlay file that are used 245 --repeat: pages from the overlay/underlay that are repeated after 246 any "from" pages have been exhausted 247 248 249 Advanced Parsing Options 250 ------------------------------- 251 252 These options control aspects of how qpdf reads PDF files. Mostly these are 253 of use to people who are working with damaged files. There is little reason 254 to use these options unless you are trying to solve specific problems. 255 256 --suppress-recovery prevents qpdf from attempting to recover damaged files 257 --ignore-xref-streams tells qpdf to ignore any cross-reference streams 258 259 260 Advanced Transformation Options 261 ------------------------------- 262 263 These transformation options control fine points of how qpdf creates 264 the output file. Mostly these are of use only to people who are very 265 familiar with the PDF file format or who are PDF developers. 266 267 --stream-data=option controls transformation of stream data (below) 268 --compress-streams=[yn] controls whether to compress streams on output 269 --decode-level=option controls how to filter streams from the input 270 --normalize-content=[yn] enables or disables normalization of content streams 271 --object-streams=mode controls handing of object streams 272 --preserve-unreferenced preserve unreferenced objects 273 --preserve-unreferenced-resources 274 preserve unreferenced page resources 275 --newline-before-endstream always put a newline before endstream 276 --coalesce-contents force all pages' content to be a single stream 277 --flatten-annotations=option 278 incorporate rendering of annotations into page 279 contents including those for interactive form 280 fields; may also want --generate-appearances 281 --generate-appearances generate appearance streams for form fields 282 --optimize-images compress images with DCT (JPEG) when advantageous 283 --oi-min-width=w do not optimize images whose width is below w; 284 default is 128. Use 0 to mean no minimum 285 --oi-min-height=h do not optimize images whose height is below h 286 default is 128. Use 0 to mean no minimum 287 --oi-min-area=a do not optimize images whose pixel count is below a 288 default is 16,384. Use 0 to mean no minimum 289 --externalize-inline-images convert inline images to regular images; by 290 default, images of at least 1,024 bytes are 291 externalized 292 --ii-min-bytes=bytes specify minimum size of inline images to be 293 converted to regular images 294 --keep-inline-images exclude inline images from image optimization 295 --remove-page-labels remove any page labels present in the output file 296 --qdf turns on "QDF mode" (below) 297 --linearize-pass1=file write intermediate pass of linearized file 298 for debugging 299 --min-version=version sets the minimum PDF version of the output file 300 --force-version=version forces this to be the PDF version of the output file 301 302 Options for --flatten-annotations are all, print, or screen. If the option 303 is print, only annotations marked as print are included. If the option is 304 screen, options marked as "no view" are excluded. Otherwise, annotations 305 are flattened regardless of the presence of print or NoView flags. It is 306 common for PDF files to have a flag set that appearance streams need to be 307 regenerated. This happens when someone changes a form value with software 308 that does not know how to render the new value. qpdf will not flatten form 309 fields in files like this. If you get this warning, you have two choices: 310 either use qpdf's --generate-appearances flag to tell qpdf to go ahead and 311 regenerate appearances, or use some other tool to generate the appearances. 312 qpdf does a pretty good job with most forms when only ASCII and "Windows 313 ANSI" characters are used in form field values, but if your form fields 314 contain other characters, rich text, or are other than left justified, you 315 will get better results first saving with other software. 316 317 Version numbers may be expressed as major.minor.extension-level, so 1.7.3 318 means PDF version 1.7 at extension level 3. 319 320 Values for stream data options: 321 322 compress recompress stream data when possible (default) 323 preserve leave all stream data as is 324 uncompress uncompress stream data when possible 325 326 Values for object stream mode: 327 328 preserve preserve original object streams (default) 329 disable don't write any object streams 330 generate use object streams wherever possible 331 332 When --compress-streams=n is specified, this overrides the default behavior 333 of qpdf, which is to attempt compress uncompressed streams. Setting 334 stream data mode to uncompress or preserve has the same effect. 335 336 The --decode-level parameter may be set to one of the following values: 337 none do not decode streams 338 generalized decode streams compressed with generalized filters 339 including LZW, Flate, and the ASCII encoding filters. 340 specialized additionally decode streams with non-lossy specialized 341 filters including RunLength 342 all additionally decode streams with lossy filters 343 including DCT (JPEG) 344 345 In qdf mode, by default, content normalization is turned on, and the 346 stream data mode is set to uncompress. QDF mode does not support 347 linearized files. The --linearize flag disables qdf mode. 348 349 Setting the minimum PDF version of the output file may raise the version 350 but will never lower it. Forcing the PDF version of the output file may 351 set the PDF version to a lower value than actually allowed by the file's 352 contents. You should only do this if you have no other possible way to 353 open the file or if you know that the file definitely doesn't include 354 features not supported later versions. 355 356 Testing, Inspection, and Debugging Options 357 ------------------------------------------ 358 359 These options can be useful for digging into PDF files or for use in 360 automated test suites for software that uses the qpdf library. 361 362 --deterministic-id generate deterministic /ID 363 --static-id generate static /ID: FOR TESTING ONLY! 364 --static-aes-iv use a static initialization vector for AES-CBC 365 This is option is not secure! FOR TESTING ONLY! 366 --no-original-object-ids suppress original object ID comments in qdf mode 367 --show-encryption quickly show encryption parameters 368 --show-encryption-key when showing encryption, reveal the actual key 369 --check-linearization check file integrity and linearization status 370 --show-linearization check and show all linearization data 371 --show-xref show the contents of the cross-reference table 372 --show-object=trailer|obj[,gen] 373 show the contents of the given object 374 --raw-stream-data show raw stream data instead of object contents 375 --filtered-stream-data show filtered stream data instead of object contents 376 --show-npages print the number of pages in the file 377 --show-pages shows the object/generation number for each page 378 --with-images also shows the object IDs for images on each page 379 --check check file structure + encryption, linearization 380 --json generate a json representation of the file 381 --json-help describe the format of the json representation 382 --json-key=key repeatable; prune json structure to include only 383 specified keys. If absent, all keys are shown 384 --json-object=trailer|[obj,gen] 385 repeatable; include only specified objects in the 386 "objects" section of the json. If absent, all 387 objects are shown 388 389 The json representation generated by qpdf is designed to facilitate 390 processing of qpdf from other programming languages that have a hard 391 time calling C++ APIs. Run qpdf --json-help for details on the format. 392 The manual has more in-depth information about the json representation 393 and certain compatibility guarantees that qpdf provides. 394 395 The --raw-stream-data and --filtered-stream-data options are ignored 396 unless --show-object is given. Either of these options will cause the 397 stream data to be written to standard output. 398 399 If --filtered-stream-data is given and --normalize-content=y is also 400 given, qpdf will attempt to normalize the stream data as if it is a 401 page content stream. This attempt will be made even if it is not a 402 page content stream, in which case it will produce unusable results. 403 404 Ordinarily, qpdf exits with a status of 0 on success or a status of 2 405 if any errors occurred. If there were warnings but not errors, qpdf 406 exits with a status of 3. If warnings would have been issued but --no-warn 407 was given, an exit status of 3 is still used. 408 409 >


 Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
 

呼び出し形式(1)

コマンドラインでの基本形式です。

qpdf [ options ] { infilename | --empty } [ outfilename ]

1つの半角空白文字で区切りと見ます。

  • qpdf : qpdf.exe の事です。Windowsの環境変数のPATHが通ってない場合はフルパスでの指定が必要です。
  • options : 1つ以上のオプションです。通常は各オプションの前に2つのハイフン「--」が付きます。2つのハイフンでオプションの始まりと判断してるみたいです。また、2つのハイフンの前後が空白「 -- 」の場合はオプションの終了を意味します。
  • infilename : 入力ファイルです。
    代わりにパラメータ --empty を使用する事もできます。--empty はゼロ頁のダミー入力PDFファイルとして使用できます。
  • outfilename : 出力ファイルです。ほとんどのオプションは出力ファイルを必要とします。
    テストや検査には必要無いです。

 

呼び出し形式(2)

JSON処理は、以下の基本形式に変わります。

qpdf [options] infile outfile

  • qpdf : qpdf.exe の事です。
  • options : オプションです。
  • infile : 入力のPDFファイルです。
  • outfile : 出力ファイルです。

 

Basic Options : 基本オプション

一般的に使用されるオプションです。

--version

バージョン情報を表示します。

--copyright

著作権とバージョン情報を表示します。

--help

引数などを解説したヘルプを画面に表示します。かなりの量です。

--completion-bash

bashからシェル補完を有効にする為の補完コマンドを出力します。
詳細はココ(英語)を参照。

--completion-zsh

zshからシェル補完を有効にする為の補完コマンドを出力します。
詳細はココ(英語)を参照。

--password=password

PDF文書を開く時に入力が必要になるユーザーパスワードが設定されたファイルにアクセスするためのパスワードを指定します。password 部分にパスワードの文字列を指定します。

--verbose

付加的な情報出力を(PDF)出力します。

>qpdf --verbose copy1.pdf info.pdf
qpdf: wrote file info.pdf

※7.0.0 からの新機能で、使い方は不明です。

--progress

処理中の進捗インジケータを表示します。

--no-warn

標準エラー(stderr)へ警告を書き込みません。 警告が検出されて、--no-warn が指定された場合は、Qpdfは終了コード3で終了します。

--linearize

Web用に最適化(リニアライズ)します。PDF全体を圧縮する最適化では無く、Web用に表示速度を上げる為だけの最適化で有ることに注意してください。通常はこのWeb用最適化のことを「リニアライズ」と言います。

例:ユーザーパスワードが「abc」のin-ps.pdf をWeb用に最適化します。出力はout-ps.pdf です。out-ps.pdf には同じユーザーパスワード設定がされます。

>qpdf --password=abc --linearize in-ps.pdf out-ps.pdf

--copy-encryption=file

指定されたファイルから暗号化パラメータをコピーします。ここで言う「暗号化パラメータ」は文書プロパティのセキュリティに設定されている内容の事です。

例:in.pdf をWeb用最適化し、更に test-ps.pdf からセキュリティ設定だけをコピーして out.pdf に出力します。

>qpdf --linearize --copy-encryption=test-ps.pdf in.pdf out.pdf

--encryption-file-password=password

--copy-encryption=file file にユーザーパスワードが掛かっている時にその password をここで指定します。

例:in.pdf をWeb用最適化し、更に test-ps.pdf からセキュリティ設定をコピーして out.pdf に出力します。なお、test-ps.pdf には(文書を開く)ユーザーパスワードが設定されてるのでその値「abc」を「--encryption-file-password=abc」オプションで指定します。当然ですが出力した out.pdf にも同じユーザーパスワードの設定がコピーされます。

>qpdf --linearize --copy-encryption=test-ps.pdf --encryption-file-password=abc in.pdf out.pdf

--encrypt options --

文書プロパティのセキュリティに関する設定を行います。
このオプションの詳細はこの後の「暗号化オプション」を参照してください。

--decrypt

オーナーパスワードによる保護(文書プロパティのセキュリティ設定)を解除します。入力ファイルに対しての直接のパスワード解除は出来ません。必ず出力ファイルを指定します。

例:in-ps.pdf のセキュリティ設定を解除して、out-nops.pdf に出力します。

>qpdf --decrypt in-ps.pdf out-nops.pdf

--password-is-hex-key

プライマリパスワードオプションを16進数のキーとして扱います。
※プライマリパスワード(primary password)に関する情報が見当たらない。

--suppress-password-recovery

パスワード文字列のエンコードエラーからの回復を試みない。

--password-mode=mode

コマンドラインで指定されるパスワードをどのように解釈するかを制御します。

  • auto:自動判別し、エンコーディングは自動調整
  • bytes:そのままで使用
  • hex-bytes:16進エンコードのバイト文字列として解釈
  • unicode:UTF-8エンコード文字列として解釈

Qpdfではこの事を「Password Modes/パスワードモード」と言っています。

--pages options --

PDFの分割、マージを指定するオプションです。
このオプションの詳細はこの後の「ページ選択オプション」を参照してください。

--collate

マージ時に頁を連結しての処理はしないで、1頁ずつ取り出して処理します。
このオプションの詳細はこの後の「ページ選択オプション」を参照してください。

--rotate=[+|-]angle:page-range

指定したページを90、180、または270度に回転します。

--split-pages=[n]

n ページ単位で別々のPDFファイルに書き出します。n=1の時は1頁1PDF単位、n=2の時は2頁単位で1PDF出力します。

>qpdf --split-pages=2 test3.pdf out1.pdf

出力ファイル名の後にページ番号を付加されます。

out1-01-02.pdf out1-03-04.pdf out1-05-06.pdf out1-07-08.pdf out1-09-10.pdf

 

Overlay and Underlay Options:オーバーレイとアンダーレイのオプション

Acrobatの「スタンプ」機能の事です。

--overlay options --

options に従って、他のPDFファイルのページを入力PDFのページの上に貼り付けます。

--underlay options --

options に従って、他のPDFファイルのページを入力PDFのページの下に貼り付けます 。

options の形式と内容:

{--overlay | --underlay } file
      [ --password=password ]
      [ --to=page-range ]
      [ --from=[page-range] ]
      [ --repeat=page-range ]
      --

  • file:"--from" で使用されるファイル名
  • --password:"file" が暗号化されている場合のパスワード
  • --to:オーバーレイ/アンダーレイされる出力先のページ番号。
    未指定時は全てのページに適応される。
  • --from:オーバーレイ/アンダーレイに使用されるファイルのページ番号。未指定時は全てのページが適応される。
  • --repeat:上記の "--from" ページが使い果たされた後に繰り返されるページ番号。先頭から一定範囲のページを繰り返したい場合は "--from=" を指定。

例1:o.pdfの最初の3ページをa.pdfの最初の3ページにオーバーレイし、次にo.pdfのページ5をa.pdfのページ4および5にオーバーレイします。 残りのa.pdfのページはそのまま残します。結果をb.pdfへ出力します。※a.pdfは未変更

>qpdf --overlay o.pdf --to=1-5 --from=1-3 --repeat=5 -- a.pdf b.pdf

例2:a.pdfのすべての奇数ページにfooter.pdfのページ1をアンダーレイし、a.pdfのすべての偶数出力ページにfooter.pdfのページ2をアンダーレイします。結果をb.pdfへ出力します。※a.pdfは未変更

>qpdf --underlay footer.pdf --from= --repeat=1,2 -- a.pdf b.pdf

 

Encryption Options:暗号化オプション

PDFファイルのセキュリティ関連を変更します。Qpdf ではこの事を「ファイルの暗号化パラメータの変更」と言っています。

「--encrypt」オプションの形式

qpdf --encrypt user-password owner-password key-length flags -- infilename outfilename

  • --encrypt : --encrypt オプションの開始を意味します
  • user-password : ユーザーパスワードを指定します
    (文書を開くパスワード)PDFファイルを開く時に制限を掛けるパスワードです。
  • owner-password : オーナーパスワードを指定します
    (権限パスワード)PDFに印刷、更新、コピー等の許可を設定するパスワードです。
  • key-length : キーの長さで40, 128, 256 のいずれかを指定
  • flags : これは上記のkey-length の値によって変わります
  • -- : 最後のハイフン2つ「--」で --encrypt オプションの終了を意味します

ユーザーパスワードとオーナーパスワードのいずれかまたは両方が空の文字列であってもよいです。その時は「""」の様に指定します。

注意:ユーザーパスワードとオーナーパスワードの文字数について。
参照:PDFのパスワードは32文字まで

flags

key-length の値(40 , 128 , 256)で flags 部分の内容が変わります。

  • key-length= 40 の時
    • --print=[yn] : 印刷を許可
    • --modify=[yn] : 文書の変更を許可
    • --extract=[yn] : テキスト/グラフィックの抽出を許可
    • --annotate=[yn] : コメントとフォーム記入と署名を許可
  • key-length= 128 の時
    • --accessibility=[yn] : 視覚障害者へのアクセスを許可
    • --extract=[yn] : テキスト/グラフィックの抽出を許可
    • --print=print-opt : 印刷アクセスを制御 (下記参照)
    • --assemble=[yn]:文書の組み立て(ページの回転と並べ替え)を許可
    • --annotate=[yn]:コメントとフォームへの記入と署名を許可
    • --form=[yn]:フォームフィールドの入力を許可
    • --modify-other=[yn]:--assemble、--annotate、および--formオプションによって個別に制御されるものを除き、すべての文書編集を許可
    • --modify=modify-opt : 変更アクセスを制御 (下記参照)
    • --cleartext-metadata : メタデータの暗号化を防ぐ
    • --use-aes=[yn] : AES 暗号化を使用するかどうかを示す
    • --force-V4 : V=4暗号化ハンドラの使用を強いる
  • key-length= 256 の時
    • --accessibility=[yn] : 視覚障害者へのアクセスを許可
    • --extract=[yn] : テキスト/グラフィックの抽出を許可
    • --print=print-opt : 印刷アクセスを制御 (下記参照)
    • --modify=modify-opt : 変更アクセスを制御 (下記参照)
    • --cleartext-metadata : メタデータの暗号化を防ぐ
    • --use-aes=y : AES 暗号化の使用は256ビットキーでは常にオン
    • --force-V4 : 256ビットでは利用不可
    • --force-R5 : 非推奨のR=5暗号化の使用を強いる

print-opt

--print=print-opt オプションで使えるprint-opt の値です。

  • full : 完全な印刷が可能
    高解像度の印刷を意味してると
  • low : 低解像度の印刷のみを許可
  • none : 印刷を許可しない

modify-opt

--modify=modify-opt オプションで使えるmodify-opt の値です。

  • all : 完全な文書の変更を許可
  • annotate : コメント作成およびフォームの操作を許可
  • form : フォームフィールドの入力と署名を許可
  • assembly : 文書のアセンブリのみを許可
  • none : 変更を許可しない

--cleartext-metadata オプションの補足

「--cleartext-metadata : メタデータの暗号化を防ぐ」オプションを指定するにはPDFバージョン=1.5 以上が必要です。デフォルトはオフです。

--use-aes=y オプションの補足

「--use-aes=y : AES 暗号化を使用」オプションを指定するにはPDFバージョン=1.6 以上が必要です。デフォルトはオフです。

--force-V4 オプションの補足

使用するしないに関わらず、PDFバージョン=1.5 以上が必要です。

暗号化オプションの使用例

ユーザパスワードは無しで「 "" 」、オーナーパスワードは「abc」、キーの長さ「40」、印刷不可「 --print=n 」、抽出もコピーも不可「 --extract=n 」にします。オプションは最後に「--」だけで閉じます。入力は in.pdf 、出力は out.pdf です。

>qpdf --encrypt "" abc 40 --print=n --extract=n -- in.pdf out.pdf

Qpdf 暗号化オプションの使用例

間違ってオーナーパスワードを空白「""」にした時は、「--print=n : 印刷不可」、「抽出もコピー不可: --extract=n 」のオプションなどは指定しても無視されます。エラーにはなりません。(注意

 

Page Selection Options:ページ選択オプション

--keep-files-open=[yn]

デフォルトで Qpdf は200個以上のファイルが指定されていると、参照されてないファイルを閉じます。200個以下では同時に全てを開いたままにします。--keep-files-open オプションで開いたままを有効「=y」、無効「=n」に出来ます。ファイルの開いて閉じる動作は特定のファイルシステム、特にネットワークファイルシステムでは非常に高いオーバーヘッドが生じることがあります。これで制御します。※詳細な動作は未検証。

qpdf infilename --pages file [ --password=password ] [ page-range ] ... -- outfilename

ページの分割とマージの指定です。「--pages」で始まり、最後は「--」だけで終了する部分を指定します。infilename を指定するとそのPDFの文書プロパティやメタデータなどの非ページデータをoutfilename 作成時に使用します。使用したくない場合は infilename に--empty を指定します。

注記:infilename に入力PDFも--empty も指定しないと実行エラーになります。

>qpdf --pages in.pdf 1-3 in.pdf 10-11 --out.pdf
 
qpdf: insufficient arguments to --pages
 
Usage: qpdf [options] infile outfile
For detailed help, run qpdf --help

--keep-files-open-threshold=count

--keep-files-openのしきい値200を--keep-files-open-thresholdで変更できます。

 

ページ番号の指定方法とその並び

  • 1,4,6 : 1頁と4頁と6頁の順
  • 5-10 : 5頁から10頁の並び
    10頁のPDFなら「 5,6,7,8,9,10 」と同じ意味。
  • 9-2 : 9頁から2頁の逆順の並び
    10頁のPDFなら「 9,8,7,6,5,4,3,2 」と同じ意味。
  • z-1 : 最後の頁から1頁の逆順の並び。
    「z」は最終ページの意味。
    5頁のPDFなら「 5,4,3,2,1 」と同じ意味。
  • 省略 : 1-z の指定と同じ。全頁です。
  • r3-r1:最終頁の前3頁目から最終頁までの3頁
    「r」は文書の最後から数えるの意味。
    5頁のPDFなら「 3-5 」又は「 3,4,5 」と同じ意味。
  • r1-r3:最終頁から最終頁の前3頁目までの3頁
    5頁のPDFなら「 5-3 」又は「 5,4,3 」と同じ意味。

マージ

マージのサンプルです。入力ファイルを色で分けています。

例:in-A.pdf の1頁から3頁の後に、in-B.pdf の2頁から3頁を結合して、out.pdf へ出力します。最初に --empty が指定されているので、文書のタイトルなどのメタデータやプロパティの非ページデータはout.pdf へ出力しません。

>qpdf --empty --pages in-A.pdf 1-3 in-B.pdf 2-3 -- out.pdf

例:同じファイルを複数回使えます。1頁から3頁、その後に10頁から逆に5頁までをマージしてout.pdf へ出力します。

>qpdf --empty --pages in-A.pdf 1-3 in-A.pdf 10-5 -- out.pdf

例:ユーザーパスワード付きのPDFの場合はファイルの後に「--password=password」オプションを追加します。

>qpdf --empty --pages in-A.pdf 1-3 in-C.pdf --password=abcdefg 10-5 -- out.pdf

例:同じ入力ファイルが複数有り、パスワード時の場合は最初のだけ「--password=password」オプションを追加します。なお出力ファイル out.pdf のタイトルなどのメタデータと文書のプロパティ等の非ページデータは in-A.pdf のがコピーされます。

>qpdf in-A.pdf --pages in-C.pdf --password=abcdefg 1-3 in-C.pdf? 10-5 -- out.pdf

高度なマージ

以下の図で説明します。

a.pdf が3頁、b.pdfが2頁とします。通常のマージは

>qpdf --empty --pages a.pdf b.pdf -- out.pdf

で、a.pdf の全頁の後にb.pdfの全頁が追加されます。

頁の順に集めたい時に --collate オプションを前に追加します。

>qpdf --collate --empty --pages a.pdf b.pdf -- out.pdf

分割

実際は上記マージの変形です。入力PDFファイルを1つだけにします。

例:in.pdf の1頁から3頁を抽出して out.pdf へ出力します。この時に --empty が指定されてるので文書のプロパティやメタ情報の非ページデータはout.pdf には出力されません。

>qpdf --empty --pages in.pdf 1-3 -- out.pdf

例:例:in-A.pdf の1頁から3頁を抽出して out.pdf へ出力します。この時にin-B.pdf? の文書のプロパティやメタ情報の非ページデータのみがout.pdf には出力されます。in-A.pdf の非ページデータはコピーされません。

>qpdf in-B.pdf --pages in-A.pdf 1-3 -- out.pdf

注意事項

入力PDFのしおりと添付ファイルは out.pdf に出力されません。これはテスト結果から出した情報です。

 

Advanced Parsing Options:高度な解析オプション

qpdfがPDFファイルを読み取る方法の側面を制御します。破損したファイルを扱っている人には役に立ちます。

--suppress-recovery

Qpdf が破損したファイルを回復しようとする試みを防ぎます。

--ignore-xref-streams

Qpdf が任意の相互参照(クロスリファレンス)ストリームを無視するように指示します。

 

Advanced Transformation Options:高度な変換オプション

ここからの変換オプションは Qpdf が出力ファイルを作成する方法についての細かい部分をコントロールします。主にPDFファイル形式に精通しているか、PDF関連の開発者である人々に有効な情報です。

--stream-data=option

ストリームデータの変換を制御します。以下はoption の値です。

  • compress : 可能な場合はストリームデータを再圧縮 (デフォルト)
  • preserve : すべてのストリームデータをそのままで残します
  • uncompress : 可能な場合はストリーム データを解凍します

--compress-streams=[yn]

出力時にストリームを圧縮するかどうかを制御します。

  • y:圧縮する。
  • n:何もしない。

※7.0.0のテストで圧縮効果は確認できなかった。

--decode-level=option

ストリームのフィルタリングする方法を制御します。Optionは

  • none : デコードしない。
  • generalized : LZW、Flate、およびASCIIエンコーディングフィルタを含む一般化されたフィルタで圧縮されたストリームをデコードします。
  • specialized :?RunLengthを含む可逆特殊フィルターでストリームをデコードします。
  • all : DCT(JPEG)などの非可逆フィルタでストリームをデコードします。

--normalize-content=[yn]

コンテンツストリームの正規化を有効または無効にします。

--object-streams=mode

オブジェクトストリームの処理を制御します。以下はmode の値です。

  • preserve : 元のオブジェクト ストリーム (既定値) を維持
  • disable : 任意のオブジェクトストリームを書かない
  • generate : 可能な限りオブジェクトストリームを使用

--preserve-unreferenced

参照されていないオブジェクトを保存します。

--newline-before-endstream

終了ストリーム (endstream) の前に改行を入れます。

--preserve-unreferenced-resources

未参照のページリソースを保存します。

--newline-before-endstream

終了ストリーム (endstream) の前に常に改行を入れます。

--coalesce-contents

全てのページのコンテンツを強制的に単一のストリームにします。

--flatten-annotations=option

フォームフィールドなどの注釈を統合します。optionは以下を指定します。

  • all:非表示または非表示としてマークされていない全ての注釈を含める。
  • print:印刷のみ表示としてマークされた注釈のみ含める。
  • screen:画面に表示されないようにするための注釈は省略する。

※使い方が分からない。ので説明もイマイチ。

--generate-appearances

フォームフィールドの外観ストリームを生成する

--optimize-images

DCT(JPEG)で画像を圧縮する

--oi-min-width=w

幅が w 以下の画像は最適化しません。 デフォルトは128です。最小値を指定しないときは w に 0 をセットします。

--oi-min-height=h

高さが h 以下の画像は最適化しません。デフォルトは128です。

--oi-min-area=a

ピクセル数がデフォルトの16,384未満の画像は最適化しません。最小値を指定しないときは a に 0 をセットします。

--externalize-inline-images

インライン画像を通常の画像に変換します。 デフォルトでは、1,024バイト以上の画像は外部化されています。

インライン画像:1つのHTMLファイルに画像も埋め込むことが出来ます。PDFもPDFファイル内に画像を埋め込むことが出来ます。その画像の事です。

※考えた結果にならない。コマンドが悪いのか。例「qpdf in.pdf --externalize-inline-images -- out.pdf」

--ii-min-bytes=bytes

通常の画像に変換するインライン画像の最小サイズを指定します。

※動作で結果は確認できなかった。

--keep-inline-images

画像の最適化からインライン画像を除外します。

--remove-page-labels

出力ファイルにあるページラベルをすべて削除します。

--qdf

QDFモードをオンにします。詳細は下記の「QDFモード」を参照してください。

--linearize-pass1=file

デバッグ用にリニアライズ(Web用の最適化)されたファイルの中間パスを書き込みます。

--min-version=version

出力ファイルに最小のPDF バージョンを設定します。versionの説明はこの後で。

PDFの出力ファイルに最小のPDFバージョンを設定すると、後でPDFバージョンを上げることができますが、それを下げることは(基本的に)ありません。

--force-version=version

出力ファイルのPDF バージョンを強制で設定します。

上記2つのオプションの version で指定するPDF バージョンの指定方法は

  • 1.6:PDFバージョン1.6
  • 1.7.3:PDFバージョン1.7の拡張レベル(Adobe Extension Level)3

※PDF バージョンについてはコチラ「PDF のバージョンとは」も参照。

PDFの出力ファイルのPDFバージョンで強制設定の機能を利用すると、実際にファイルの内容から許可されているよりも低い値にPDFバージョンを設定することができます。ファイルは間違いなくPDFバージョンでサポートされていない機能が含まれていないことがわかっている場合のみ、またはファイルを開くのに他の可能な方法を持っていない場合にのみ、これを行ってください。

 

QDFモード

デフォルトでは、コンテンツ正規化がオンになり、ストリームデータを解凍するように設定されています。つまりPDFの中身をテキストエディタで開くことが出来るようになります(メモ帳は無理かも)。この時にオーナーパスワードで設定されたセキュリティ設定(印刷の許可、変更の許可等)は解除されます。

例:in.pdf を入力してテキストエディタで開くことが出来る qdf ファイルにout.qdf を出力します。

>qpdf --qdf in.pdf out.qdf

この後でPDF独自の内部の位置情報が壊れるはずなので、以下で修正します。なお、以下のfix-qdf ファイルはPeralがOSにインストールされてないと動作しません。

>fix-qdf < out.qdf > out-A.pdf

QDFモードはデフォルトでコンテンツの正規化がオンです。ストリームデータモードは圧縮解除に設定されます。QDFモードは線形化ファイルをサポートしません。--linearizeフラグはQDFモードを無効にします。

 

試験、検査、およびデバッグ・オプション

これ以降の操作ではPDF文書を開く時に必要なユーザーパスワードは不要です。ユーザーパスワードが設定されていても、意識しなくて処理が出来ます。Qpdf の大きな特徴の1つです。

--deterministic-id

deterministic(確定的) /IDを生成します。

--static-id

静的 /IDを生成します。テストだけのために!

--static-aes-iv

AES-CBCのための静的な初期化ベクトルを使用します。これはセキュリティで保護されていないオプションです!テスト専用!

--no-original-object-ids

「qdf モード」で元のオブジェクトID のコメントを非表示します。

--show-encryption

暗号化パラメーターを表示します。

>qpdf.exe passwordcopy.pdf --show-encryption
R = 4
P = -3904
User password =
extract for accessibility: not allowed
extract for any purpose: not allowed
print low resolution: not allowed
print high resolution: not allowed
modify document assembly: not allowed
modify forms: not allowed
modify annotations: not allowed
modify other: not allowed
modify anything: not allowed
stream encryption method: AESv2
string encryption method: AESv2
file encryption method: AESv2
 
>

--show-encryption-key

暗号化を表示する場合は実際の鍵を明らかにします。

--check-linearization

ファイルの整合性とリニアライズ(Web用最適化)の状態を確認します。

--show-linearization

リニアライズ(Web最適化)データのチェックと表示をします。

--show-xref

相互参照(クロスリファレンス)表の内容を表示します。

--show-object=trailer | obj[,gen]

指定されたオブジェクトの内容を表示します。

--raw-stream-data

オブジェクトのコンテンツの代わりに生ストリーム データを表示します。

--filtered-stream-data

オブジェクトコンテンツではなくフィルター選択されたストリームデータを表示します。

--show-npages

ファイル内のページ数を表示します。

--show-pages

各ページのオブジェクト/世代番号を表示します。

--with-images

各ページ上の画像のためのオブジェクトIDを表示します。

--check

ファイル構造 + 暗号化、リニアライズ(Web用最適化)をチェックします。

 

JSON

PDFファイル内の非コンテンツデータのJSON表現を生成できます。ストリームのコンテンツを除くPDFファイル内のすべてのオブジェクトのJSON形式のダンプが含まれています。JSON表現は与えられたPDFファイルの構造を詳細に見ることを非常に容易にします。

Qpdfライブラリを直接呼び出すこともリンクすることもできない言語で、PDFファイルを操作するための方法が提供できます。 ストリームデータは、他のQpdfコマンドラインオプションを使用してPDFファイルから抽出できることに注意してください。

Qpdfによって生成されたJSON表現は、C ++ APIの呼び出しに苦労している他のプログラミング言語からのQpdfの処理を容易にするように設計されています。フォーマットの詳細については Qpdf --json-help を実行してください。

詳細はコチラ(英語)を参照してください。

※Qpdf バージョン8.3.0以降での新機能。

--json

JSON表現を生成します。

>qpdf --json a.pdf > a.json

--json-help

JSON表現のフォーマットの詳細を表示するヘルプです。

1 >qpdf --json-help 2 The json block below contains the same structure with the same keys as the 3 json generated by qpdf. In the block below, the values are descriptions of 4 the meanings of those entries. The specific contract guaranteed by qpdf in 5 its json representation is explained in more detail in the manual. You can 6 specify a subset of top-level keys when you invoke qpdf, but the "version" 7 and "parameters" keys will always be present. 8 9 { 10 "acroform": { 11 "fields": [ 12 { 13 "alternativename": "alternative name of field -- this is the one usually shown to users", 14 "annotation": { 15 "annotationflags": "annotation flags from /F -- see pdf_annotation_flag_e in qpdf/Constants.h", 16 "appearancestate": "appearance state -- can be used to determine value for checkboxes and radio buttons", 17 "object": "reference to the annotation object" 18 }, 19 "choices": "for choices fields, the list of choices presented to the user", 20 "defaultvalue": "default value of field", 21 "fieldflags": "form field flags from /Ff -- see pdf_form_field_flag_e in qpdf/Constants.h", 22 "fieldtype": "field type", 23 "fullname": "full name of field", 24 "ischeckbox": "whether field is a checkbox", 25 "ischoice": "whether field is a list, combo, or dropdown", 26 "isradiobutton": "whether field is a radio button -- buttons in a single group share a parent", 27 "istext": "whether field is a text field", 28 "mappingname": "mapping name of field", 29 "object": "reference to this form field", 30 "pageposfrom1": "position of containing page numbered from 1", 31 "parent": "reference to this field's parent", 32 "partialname": "partial name of field", 33 "quadding": "field quadding -- number indicating left, center, or right", 34 "value": "value of field" 35 } 36 ], 37 "hasacroform": "whether the document has interactive forms", 38 "needappearances": "whether the form fields' appearance streams need to be regenerated" 39 }, 40 "objects": "dictionary of original objects; keys are 'trailer' or 'n n R'", 41 "outlines": [ 42 { 43 "dest": "outline destination dictionary", 44 "destpageposfrom1": "position of destination page in document numbered from 1; null if not known", 45 "kids": "array of descendent outlines", 46 "object": "reference to this outline", 47 "open": "whether the outline is displayed expanded", 48 "title": "outline title" 49 } 50 ], 51 "pagelabels": [ 52 { 53 "index": "starting page position starting from zero", 54 "label": "page label dictionary" 55 } 56 ], 57 "pages": [ 58 { 59 "contents": [ 60 "reference to each content stream" 61 ], 62 "images": [ 63 { 64 "bitspercomponent": "bits per component", 65 "colorspace": "color space", 66 "decodeparms": [ 67 "decode parameters for image data" 68 ], 69 "filter": [ 70 "filters applied to image data" 71 ], 72 "filterable": "whether image data can be decoded using the decode level qpdf was invoked with", 73 "height": "image height", 74 "name": "name of image in XObject table", 75 "object": "reference to image stream", 76 "width": "image width" 77 } 78 ], 79 "label": "page label dictionary, or null if none", 80 "object": "reference to original page object", 81 "outlines": [ 82 { 83 "dest": "outline destination dictionary", 84 "object": "reference to outline that targets this page", 85 "title": "outline title" 86 } 87 ], 88 "pageposfrom1": "position of page in document numbering from 1" 89 } 90 ], 91 "parameters": { 92 "decodelevel": "decode level used to determine stream filterability" 93 }, 94 "version": "JSON format serial number; increased for non-compatible changes" 95 } 96 97 >


 Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
 

--json-key=key

指定された key のみを含むようにJSON構造を整理します。存在しない場合は全てのキーが表示されます。

ただし、間違ったキーを入力すると

>qpdf --json-key=abc a.pdf a-abc.json

qpdf: --json-key must be given as --json-key={acroform,objects,outlines,pagelabels,pages}

Usage: qpdf [options] infile outfile

For detailed help, run qpdf --help
>qpdf --json-key=pagelabels a.pdf a-pagelabels.json

keyは「acroform , objects , outlines , pagelabels , pages」の中から選ぶみたいです。

--json-object=trailer|[obj,gen]

指定されたオブジェクトのみをJSONの "objects"セクションに含めます。存在しない場合は全てのオブジェクトが表示されます。

 

注釈

一般的な注釈の追加や更新ではなく、非常に特殊な処理が提供しています。

サイト管理者が内容を理解できる状態には至っていません。詳細はコチラ(PDF 英語)を御覧ください。

※バージョン 8.3.0 からの新機能。これに関する情報はマニュアル以外は存在しません。

 

終了コード

ヘルプやマニュアルには記述は無いですが、ChangeLog に記載があるのでそれを紹介します。

  • 0 : 正常終了
  • 2 : エラー
  • 3 : 警告 (エラーは無しの場合)

 

Qpdf を使ったVBA関数

特定の処理をQpdf で行うVBA関数です。サンプル付きです。

申し訳ないですが Qpdfのバージョンアップに以下のサンプルが追いついていません。関数内の引数でエラーになる場合も有ります。

  1. Qpdf? : PDFにセキュリティを設定するVBA関数
  2. Qpdf? : PDFのセキュリティ設定を取得するVBA関数
  3. Qpdf? : PDFのパスワードとセキュリティ設定を解除するVBA関数
  4. Qpdf? : PDFにパスワードとセキュリティ設定をコピーするVBA関数

 

Qpdf を起動するサンプル

上記以外の処理をQpdf でさせるサンプルです。オプション等の設定、エラーの判定は全て自分で行う必要が有ります。

実際にコマンドラインを実行するVBA関数「 RunCommandLineEX 」はコチラをご使用ください。

例:IN.pdf のリニアライズ(Web最適化)チェックを行います。

DownloadcLine-qpdfDemo.xls

1 Option Explicit 2 3 Const gDebugMode = True 4 5 ' コマンドラインを起動するメイン・デモ 6 7 Sub Main_Demo() 8 9 Dim i As Long 10 Dim bRet As Boolean 11 Dim strOutFile1() As String 12 Dim strOutFile2() As String 13 14 '引数で使う変数 15 Dim strCmd As String 16 Dim strOutFile(1) As String 17 Dim strErr As String 18 Dim strWorkFolder As String 19 Dim lRetCode As Long 20 Dim lErrCount As Long 21 Dim lErrCode(2) As Long 22 23 '終了コードのセット 24 lErrCode(0) = 0 'Success 25 lErrCode(1) = 2 'Errors 26 lErrCode(2) = 3 'Warnings 27 lErrCount = 2 'Ubound(lErrCode) 28 strCmd = "I:\Tools\Run\Qpdf-6.0.0\bin\qpdf.exe " & _ 29 "--show-linearization " & _ 30 "I:\Tools\Run\Qpdf-6.0.0\bin\IN9.pdf" 31 32 'コマンドラインの実行 33 bRet = RunCommandLineEX(strCmd, strWorkFolder, _ 34 lErrCount, lErrCode, _ 35 strOutFile, strErr, lRetCode) 36 37 If gDebugMode Then 38 '実行結果の表示 39 Debug.Print "bRet=" & bRet 40 Debug.Print "lRetCode=" & lRetCode 41 strOutFile1 = Split(strOutFile(0), vbCrLf) 42 strOutFile2 = Split(strOutFile(1), vbCrLf) 43 Debug.Print "strErr=" & strErr 44 For i = 0 To UBound(strOutFile1) 45 Debug.Print "msg1 i(" & i & ")="; strOutFile1(i) 46 Next i 47 For i = 0 To UBound(strOutFile2) 48 Debug.Print "msg2 i(" & i & ")="; strOutFile2(i) 49 Next i 50 End If 51 MsgBox "End " & Now 52 End Sub 53 54 55 Public Function RunCommandLineEX() As Boolean 56 57 'ここはVBA関数「 RunCommandLineEX 」をご利用ください。 58 59 End Function


 Highlight:プログラミング言語のソースコードを構文で色分け (GUI編)
 

備考

  • PDF全体を圧縮する最適化と、Web用の最適化は異なります。Web用の最適化はブラウザで最初のページの表示速度を上げるための最適化を意味します。圧縮ではありません。このWeb用の最適化を「リニアライズ」と通常は言います。
  • ユーザーパスワードとオーナーパスワードの違い。
    ユーザーパスワードとは、PDF文書を開く時に必要なパスワード。
    オーナーパスワードとは、PDF文書に印刷は不可、変更の不可、コピーの不可などのセキュリティを設定する時に必要なパスワードです。
  • --decrypt で文書プロパティのセキュリティ設定を解除して、別のPDFで出力できます。入力PDFファイルの解除は出来ません。
  • zlib-flate.exe は qpdf.exe から使用されるツールみたいです。付属PDF説明書にもzlib-flate.exe に関する説明は存在しません。

 

 

< TOPへ戻る >

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


★ 文章での質問は難しいですよネ。でも、早く解決して、家に帰りたい。


SAMURAI Plugin

コメントをする時は出来れば以下もお願いします。

  • OS名 バージョン
  • Acrobat バージョン
  • ツール(Excel等) バージョン
コメントにサンプルコードを入れる時はコードを全て全角文字列にしてください。コチラで半角に戻します。それでもエラーが回避できない時はコメント下さい。個別に対処します。



お仕事で当サイトを見ている方へ
考え込んだら、ご質問下さい。
一緒に解決策を考えましょう。

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください