summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2013-07-07 23:04:41 +0200
committerJay Berkenbilt <ejb@ql.org>2013-07-08 01:43:16 +0200
commit91367239fd55f7c4996ed6158405ea10573ae3cb (patch)
tree720b32b0ba282eb47987a5856d2251f762dca68c
parentadccedc02fea78dd5a924605d254ea709d63473b (diff)
downloadqpdf-91367239fd55f7c4996ed6158405ea10573ae3cb.tar.zst
Add --show-npages option to qpdf
-rw-r--r--ChangeLog4
-rw-r--r--manual/qpdf-manual.xml11
-rw-r--r--qpdf/qpdf.cc13
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf.test8
5 files changed, 36 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index aab42fea..1a460344 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2013-07-07 Jay Berkenbilt <ejb@ql.org>
+ * qpdf: add --show-npages command-line option, which causes the
+ number of pages in the input file to be printed on a line by
+ itself.
+
* qpdf: allow omission of range in --pages. If range is omitted
such that an argument that is supposed to be a range is an invalid
range and a valid file name, the range of 1-z is assumed. This
diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml
index b5748c24..334cf41e 100644
--- a/manual/qpdf-manual.xml
+++ b/manual/qpdf-manual.xml
@@ -1090,6 +1090,17 @@ outfile.pdf</option>
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>-show-npages</option></term>
+ <listitem>
+ <para>
+ Prints the number of pages in the input file on a line by
+ itself. Since the number of pages appears by itself on a
+ line, this option can be useful for scripting if you need to
+ know the number of pages in a file.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>-show-pages</option></term>
<listitem>
<para>
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index a2e165fb..876b150f 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -248,6 +248,7 @@ automated test suites for software that uses the qpdf library.\n\
--show-object=obj[,gen] show the contents of the given object\n\
--raw-stream-data show raw stream data instead of object contents\n\
--filtered-stream-data show filtered stream data instead of object contents\n\
+--show-npages print the number of pages in the file\n\
--show-pages shows the object/generation number for each page\n\
--with-images also shows the object IDs for images on each page\n\
--check check file structure + encryption, linearization\n\
@@ -1029,6 +1030,7 @@ int main(int argc, char* argv[])
std::string min_version;
std::string force_version;
+ bool show_npages = false;
bool static_id = false;
bool static_aes_iv = false;
bool suppress_original_object_id = false;
@@ -1284,6 +1286,11 @@ int main(int argc, char* argv[])
{
show_filtered_stream_data = true;
}
+ else if (strcmp(arg, "show-npages") == 0)
+ {
+ show_npages = true;
+ require_outfile = false;
+ }
else if (strcmp(arg, "show-pages") == 0)
{
show_pages = true;
@@ -1352,6 +1359,12 @@ int main(int argc, char* argv[])
}
if (outfilename == 0)
{
+ if (show_npages)
+ {
+ QTC::TC("qpdf", "qpdf npages");
+ std::cout << pdf.getRoot().getKey("/Pages").
+ getKey("/Count").getIntValue() << std::endl;
+ }
if (show_encryption)
{
::show_encryption(pdf);
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index a29ae284..e78a4f4a 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -267,3 +267,4 @@ QPDF_optimization indirect outlines 0
QPDF xref space 2
qpdf pages range omitted at end 0
qpdf pages range omitted in middle 0
+qpdf npages 0
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 3589944a..1a6e44ad 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -199,7 +199,7 @@ $td->runtest("remove page we don't have",
show_ntests();
# ----------
$td->notify("--- Miscellaneous Tests ---");
-$n_tests += 65;
+$n_tests += 66;
$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
@@ -517,6 +517,12 @@ $td->runtest("check broken file",
{$td->FILE => "invalid-id-xref.out", $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
+$td->runtest("show number of pages",
+ {$td->COMMAND =>
+ "qpdf --show-npages 20-pages.pdf --password=user"},
+ {$td->STRING => "20\n", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+
show_ntests();
# ----------
$td->notify("--- Numeric range parsing tests ---");