Commit 91367239fd55f7c4996ed6158405ea10573ae3cb
1 parent
adccedc0
Add --show-npages option to qpdf
Showing
5 changed files
with
36 additions
and
1 deletions
ChangeLog
| 1 | 1 | 2013-07-07 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | |
| 3 | + * qpdf: add --show-npages command-line option, which causes the | |
| 4 | + number of pages in the input file to be printed on a line by | |
| 5 | + itself. | |
| 6 | + | |
| 3 | 7 | * qpdf: allow omission of range in --pages. If range is omitted |
| 4 | 8 | such that an argument that is supposed to be a range is an invalid |
| 5 | 9 | range and a valid file name, the range of 1-z is assumed. This | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -1090,6 +1090,17 @@ outfile.pdf</option> |
| 1090 | 1090 | </listitem> |
| 1091 | 1091 | </varlistentry> |
| 1092 | 1092 | <varlistentry> |
| 1093 | + <term><option>-show-npages</option></term> | |
| 1094 | + <listitem> | |
| 1095 | + <para> | |
| 1096 | + Prints the number of pages in the input file on a line by | |
| 1097 | + itself. Since the number of pages appears by itself on a | |
| 1098 | + line, this option can be useful for scripting if you need to | |
| 1099 | + know the number of pages in a file. | |
| 1100 | + </para> | |
| 1101 | + </listitem> | |
| 1102 | + </varlistentry> | |
| 1103 | + <varlistentry> | |
| 1093 | 1104 | <term><option>-show-pages</option></term> |
| 1094 | 1105 | <listitem> |
| 1095 | 1106 | <para> | ... | ... |
qpdf/qpdf.cc
| ... | ... | @@ -248,6 +248,7 @@ automated test suites for software that uses the qpdf library.\n\ |
| 248 | 248 | --show-object=obj[,gen] show the contents of the given object\n\ |
| 249 | 249 | --raw-stream-data show raw stream data instead of object contents\n\ |
| 250 | 250 | --filtered-stream-data show filtered stream data instead of object contents\n\ |
| 251 | +--show-npages print the number of pages in the file\n\ | |
| 251 | 252 | --show-pages shows the object/generation number for each page\n\ |
| 252 | 253 | --with-images also shows the object IDs for images on each page\n\ |
| 253 | 254 | --check check file structure + encryption, linearization\n\ |
| ... | ... | @@ -1029,6 +1030,7 @@ int main(int argc, char* argv[]) |
| 1029 | 1030 | std::string min_version; |
| 1030 | 1031 | std::string force_version; |
| 1031 | 1032 | |
| 1033 | + bool show_npages = false; | |
| 1032 | 1034 | bool static_id = false; |
| 1033 | 1035 | bool static_aes_iv = false; |
| 1034 | 1036 | bool suppress_original_object_id = false; |
| ... | ... | @@ -1284,6 +1286,11 @@ int main(int argc, char* argv[]) |
| 1284 | 1286 | { |
| 1285 | 1287 | show_filtered_stream_data = true; |
| 1286 | 1288 | } |
| 1289 | + else if (strcmp(arg, "show-npages") == 0) | |
| 1290 | + { | |
| 1291 | + show_npages = true; | |
| 1292 | + require_outfile = false; | |
| 1293 | + } | |
| 1287 | 1294 | else if (strcmp(arg, "show-pages") == 0) |
| 1288 | 1295 | { |
| 1289 | 1296 | show_pages = true; |
| ... | ... | @@ -1352,6 +1359,12 @@ int main(int argc, char* argv[]) |
| 1352 | 1359 | } |
| 1353 | 1360 | if (outfilename == 0) |
| 1354 | 1361 | { |
| 1362 | + if (show_npages) | |
| 1363 | + { | |
| 1364 | + QTC::TC("qpdf", "qpdf npages"); | |
| 1365 | + std::cout << pdf.getRoot().getKey("/Pages"). | |
| 1366 | + getKey("/Count").getIntValue() << std::endl; | |
| 1367 | + } | |
| 1355 | 1368 | if (show_encryption) |
| 1356 | 1369 | { |
| 1357 | 1370 | ::show_encryption(pdf); | ... | ... |
qpdf/qpdf.testcov
qpdf/qtest/qpdf.test
| ... | ... | @@ -199,7 +199,7 @@ $td->runtest("remove page we don't have", |
| 199 | 199 | show_ntests(); |
| 200 | 200 | # ---------- |
| 201 | 201 | $td->notify("--- Miscellaneous Tests ---"); |
| 202 | -$n_tests += 65; | |
| 202 | +$n_tests += 66; | |
| 203 | 203 | |
| 204 | 204 | $td->runtest("qpdf version", |
| 205 | 205 | {$td->COMMAND => "qpdf --version"}, |
| ... | ... | @@ -517,6 +517,12 @@ $td->runtest("check broken file", |
| 517 | 517 | {$td->FILE => "invalid-id-xref.out", $td->EXIT_STATUS => 3}, |
| 518 | 518 | $td->NORMALIZE_NEWLINES); |
| 519 | 519 | |
| 520 | +$td->runtest("show number of pages", | |
| 521 | + {$td->COMMAND => | |
| 522 | + "qpdf --show-npages 20-pages.pdf --password=user"}, | |
| 523 | + {$td->STRING => "20\n", $td->EXIT_STATUS => 0}, | |
| 524 | + $td->NORMALIZE_NEWLINES); | |
| 525 | + | |
| 520 | 526 | show_ntests(); |
| 521 | 527 | # ---------- |
| 522 | 528 | $td->notify("--- Numeric range parsing tests ---"); | ... | ... |