Commit 6bf47ac6e8f3c404a383c743137edb6ebfbe7170

Authored by Jay Berkenbilt
1 parent a433ed24

With --verbose, give information on processing merge inputs

Showing 2 changed files with 44 additions and 7 deletions
ChangeLog
1 2018-06-22 Jay Berkenbilt <ejb@ql.org> 1 2018-06-22 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * With --verbose, print information about each input file when
  4 + merging files.
  5 +
3 * Add progress reporting to QPDFWriter. Programmatically, you can 6 * Add progress reporting to QPDFWriter. Programmatically, you can
4 register a progress reporter with registerProgressReporter(). From 7 register a progress reporter with registerProgressReporter(). From
5 the command line, passing --progress will give progress indicators 8 the command line, passing --progress will give progress indicators
qpdf/qpdf.cc
@@ -191,8 +191,9 @@ struct Options @@ -191,8 +191,9 @@ struct Options
191 191
192 struct QPDFPageData 192 struct QPDFPageData
193 { 193 {
194 - QPDFPageData(QPDF* qpdf, char const* range); 194 + QPDFPageData(std::string const& filename, QPDF* qpdf, char const* range);
195 195
  196 + std::string filename;
196 QPDF* qpdf; 197 QPDF* qpdf;
197 std::vector<QPDFObjectHandle> orig_pages; 198 std::vector<QPDFObjectHandle> orig_pages;
198 std::vector<int> selected_pages; 199 std::vector<int> selected_pages;
@@ -1213,7 +1214,10 @@ static void test_numrange(char const* range) @@ -1213,7 +1214,10 @@ static void test_numrange(char const* range)
1213 } 1214 }
1214 } 1215 }
1215 1216
1216 -QPDFPageData::QPDFPageData(QPDF* qpdf, char const* range) : 1217 +QPDFPageData::QPDFPageData(std::string const& filename,
  1218 + QPDF* qpdf,
  1219 + char const* range) :
  1220 + filename(filename),
1217 qpdf(qpdf), 1221 qpdf(qpdf),
1218 orig_pages(qpdf->getAllPages()) 1222 orig_pages(qpdf->getAllPages())
1219 { 1223 {
@@ -1788,10 +1792,23 @@ static void parse_options(int argc, char* argv[], Options&amp; o) @@ -1788,10 +1792,23 @@ static void parse_options(int argc, char* argv[], Options&amp; o)
1788 usage("no output file may be given for this option"); 1792 usage("no output file may be given for this option");
1789 } 1793 }
1790 1794
1791 - if (o.require_outfile && (strcmp(o.outfilename, "-") == 0) &&  
1792 - o.split_pages) 1795 + if (o.require_outfile && (strcmp(o.outfilename, "-") == 0))
1793 { 1796 {
1794 - usage("--split-pages may not be used when writing to standard output"); 1797 + if (o.split_pages)
  1798 + {
  1799 + usage("--split-pages may not be used when"
  1800 + " writing to standard output");
  1801 + }
  1802 + if (o.verbose)
  1803 + {
  1804 + usage("--verbose may not be used when"
  1805 + " writing to standard output");
  1806 + }
  1807 + if (o.progress)
  1808 + {
  1809 + usage("--progress may not be used when"
  1810 + " writing to standard output");
  1811 + }
1795 } 1812 }
1796 1813
1797 if (QUtil::same_file(o.infilename, o.outfilename)) 1814 if (QUtil::same_file(o.infilename, o.outfilename))
@@ -2114,6 +2131,11 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o, @@ -2114,6 +2131,11 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o,
2114 QTC::TC("qpdf", "qpdf pages encryption password"); 2131 QTC::TC("qpdf", "qpdf pages encryption password");
2115 password = o.encryption_file_password; 2132 password = o.encryption_file_password;
2116 } 2133 }
  2134 + if (o.verbose)
  2135 + {
  2136 + std::cout << whoami << ": processing "
  2137 + << page_spec.filename << std::endl;
  2138 + }
2117 qpdf->processInputSource( 2139 qpdf->processInputSource(
2118 new ClosedFileInputSource( 2140 new ClosedFileInputSource(
2119 page_spec.filename.c_str()), password); 2141 page_spec.filename.c_str()), password);
@@ -2123,7 +2145,8 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o, @@ -2123,7 +2145,8 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o,
2123 // Read original pages from the PDF, and parse the page range 2145 // Read original pages from the PDF, and parse the page range
2124 // associated with this occurrence of the file. 2146 // associated with this occurrence of the file.
2125 parsed_specs.push_back( 2147 parsed_specs.push_back(
2126 - QPDFPageData(page_spec_qpdfs[page_spec.filename], 2148 + QPDFPageData(page_spec.filename,
  2149 + page_spec_qpdfs[page_spec.filename],
2127 page_spec.range)); 2150 page_spec.range));
2128 } 2151 }
2129 2152
@@ -2144,6 +2167,12 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o, @@ -2144,6 +2167,12 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o,
2144 // without changing their object numbers. This enables other 2167 // without changing their object numbers. This enables other
2145 // things in the original file, such as outlines, to continue to 2168 // things in the original file, such as outlines, to continue to
2146 // work. 2169 // work.
  2170 + if (o.verbose)
  2171 + {
  2172 + std::cout << whoami
  2173 + << ": removing unreferenced pages from primary input"
  2174 + << std::endl;
  2175 + }
2147 QPDFPageDocumentHelper dh(pdf); 2176 QPDFPageDocumentHelper dh(pdf);
2148 std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages(); 2177 std::vector<QPDFPageObjectHelper> orig_pages = dh.getAllPages();
2149 for (std::vector<QPDFPageObjectHelper>::iterator iter = 2178 for (std::vector<QPDFPageObjectHelper>::iterator iter =
@@ -2162,6 +2191,11 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o, @@ -2162,6 +2191,11 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o,
2162 iter != parsed_specs.end(); ++iter) 2191 iter != parsed_specs.end(); ++iter)
2163 { 2192 {
2164 QPDFPageData& page_data = *iter; 2193 QPDFPageData& page_data = *iter;
  2194 + if (o.verbose)
  2195 + {
  2196 + std::cout << whoami << ": adding pages from "
  2197 + << page_data.filename << std::endl;
  2198 + }
2165 for (std::vector<int>::iterator pageno_iter = 2199 for (std::vector<int>::iterator pageno_iter =
2166 page_data.selected_pages.begin(); 2200 page_data.selected_pages.begin();
2167 pageno_iter != page_data.selected_pages.end(); 2201 pageno_iter != page_data.selected_pages.end();
@@ -2462,7 +2496,7 @@ static void write_outfile(QPDF&amp; pdf, Options&amp; o) @@ -2462,7 +2496,7 @@ static void write_outfile(QPDF&amp; pdf, Options&amp; o)
2462 QPDFWriter w(pdf, o.outfilename); 2496 QPDFWriter w(pdf, o.outfilename);
2463 set_writer_options(pdf, o, w); 2497 set_writer_options(pdf, o, w);
2464 w.write(); 2498 w.write();
2465 - if (o.verbose && o.outfilename) 2499 + if (o.verbose)
2466 { 2500 {
2467 std::cout << whoami << ": wrote file " 2501 std::cout << whoami << ": wrote file "
2468 << o.outfilename << std::endl; 2502 << o.outfilename << std::endl;