Add --show-npages option to qpdf

This commit is contained in:
Jay Berkenbilt 2013-07-07 17:04:41 -04:00
parent adccedc02f
commit 91367239fd
5 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -1089,6 +1089,17 @@ outfile.pdf</option>
</para>
</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>

View File

@ -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);

View File

@ -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

View File

@ -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 ---");