From d926d7805963901d2c7cd10198f2cb125e363210 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 12 Aug 2017 12:30:18 -0400 Subject: [PATCH] Add --verbose flag --- ChangeLog | 3 +++ manual/qpdf-manual.xml | 9 +++++++++ qpdf/qpdf.cc | 16 ++++++++++++++++ qpdf/qtest/qpdf.test | 8 ++++---- qpdf/qtest/qpdf/split-pages-group.out | 3 +++ 5 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 qpdf/qtest/qpdf/split-pages-group.out diff --git a/ChangeLog b/ChangeLog index eacde282..3b7eb32a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2017-08-12 Jay Berkenbilt + * Provide --verbose option that causes qpdf to print an indication + of what files it is writing. + * Change --single-pages to --split-pages and make it take an optional argument specifying the number of pages per file. diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 3f3415c8..d05af020 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -284,6 +284,15 @@ make + + + + + Increase verbosity of output. For now, this just prints some + indication of any file that it creates. + + + diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index f3051eb4..b68434a9 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -44,6 +44,7 @@ struct Options linearize(false), decrypt(false), split_pages(0), + verbose(false), copy_encryption(false), encryption_file(0), encryption_file_password(0), @@ -99,6 +100,7 @@ struct Options bool linearize; bool decrypt; int split_pages; + bool verbose; bool copy_encryption; char const* encryption_file; char const* encryption_file_password; @@ -198,6 +200,7 @@ Basic Options\n\ -------------\n\ \n\ --password=password specify a password for accessing encrypted files\n\ +--verbose provide additional informational output\n\ --linearize generated a linearized (web optimized) file\n\ --copy-encryption=file copy encryption parameters from specified file\n\ --encryption-file-password=password\n\ @@ -1341,6 +1344,10 @@ static void parse_options(int argc, char* argv[], Options& o) int n = ((parameter == 0) ? 1 : atoi(parameter)); o.split_pages = n; } + else if (strcmp(arg, "verbose") == 0) + { + o.verbose = true; + } else if (strcmp(arg, "deterministic-id") == 0) { o.deterministic_id = true; @@ -2033,6 +2040,10 @@ static void write_outfile(QPDF& pdf, Options& o) QPDFWriter w(outpdf, outfile.c_str()); set_writer_options(outpdf, o, w); w.write(); + if (o.verbose) + { + std::cout << whoami << ": wrote file " << outfile << std::endl; + } } } else @@ -2044,6 +2055,11 @@ static void write_outfile(QPDF& pdf, Options& o) QPDFWriter w(pdf, o.outfilename); set_writer_options(pdf, o, w); w.write(); + if (o.verbose && o.outfilename) + { + std::cout << whoami << ": wrote file " + << o.outfilename << std::endl; + } } } diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index e5a97058..98887102 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -325,8 +325,8 @@ $td->runtest("check obj0.pdf", # Min/Force version $td->runtest("set min version", - {$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"}, - {$td->STRING => "", + {$td->COMMAND => "qpdf --verbose --min-version=1.6 good1.pdf a.pdf"}, + {$td->STRING => "qpdf: wrote file a.pdf\n", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); $td->runtest("check version", @@ -730,8 +730,8 @@ for (@sp_cases) $td->runtest("split page group > 1", {$td->COMMAND => "qpdf --static-id --split-pages=5 11-pages.pdf" . - " split-out-group.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, + " --verbose split-out-group.pdf"}, + {$td->FILE => "split-pages-group.out", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); foreach my $f ('01-05', '06-10', '11-11') { diff --git a/qpdf/qtest/qpdf/split-pages-group.out b/qpdf/qtest/qpdf/split-pages-group.out new file mode 100644 index 00000000..ec00ab7e --- /dev/null +++ b/qpdf/qtest/qpdf/split-pages-group.out @@ -0,0 +1,3 @@ +qpdf: wrote file split-out-group-01-05.pdf +qpdf: wrote file split-out-group-06-10.pdf +qpdf: wrote file split-out-group-11-11.pdf