Commit 2b011f9d817fa2cb2e8ed0b410f655e9e61cb6fa

Authored by Jay Berkenbilt
1 parent e50d5201

Add --remove-page-labels option (fixes #317)

ChangeLog
1 2019-04-20 Jay Berkenbilt <ejb@ql.org> 1 2019-04-20 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Add parameter --remove-page-labels to remove page labels from
  4 + output. In qpdf 8.3.0, the behavior changed so that page labels
  5 + were preserved when merging and splitting files. Some users were
  6 + relying on the fact that if you ran qpdf --empty --pages ... all
  7 + page labels were dropped. This option makes it possible to get
  8 + that behavior if it is explicitly desired. Fixes #317.
  9 +
3 * Add parameter --keep-files-open-threshold to override the 10 * Add parameter --keep-files-open-threshold to override the
4 maximum number of files that qpdf will allow to be kept open at 11 maximum number of files that qpdf will allow to be kept open at
5 once. Fixes #288. 12 once. Fixes #288.
manual/qpdf-manual.xml
@@ -1797,9 +1797,6 @@ outfile.pdf&lt;/option&gt; @@ -1797,9 +1797,6 @@ outfile.pdf&lt;/option&gt;
1797 </para> 1797 </para>
1798 </listitem> 1798 </listitem>
1799 </varlistentry> 1799 </varlistentry>
1800 -  
1801 -  
1802 -  
1803 <varlistentry> 1800 <varlistentry>
1804 <term><option>--externalize-inline-images</option></term> 1801 <term><option>--externalize-inline-images</option></term>
1805 <listitem> 1802 <listitem>
@@ -1835,6 +1832,14 @@ outfile.pdf&lt;/option&gt; @@ -1835,6 +1832,14 @@ outfile.pdf&lt;/option&gt;
1835 </listitem> 1832 </listitem>
1836 </varlistentry> 1833 </varlistentry>
1837 <varlistentry> 1834 <varlistentry>
  1835 + <term><option>--remove-page-labels</option></term>
  1836 + <listitem>
  1837 + <para>
  1838 + Remove page labels from the output file.
  1839 + </para>
  1840 + </listitem>
  1841 + </varlistentry>
  1842 + <varlistentry>
1838 <term><option>--qdf</option></term> 1843 <term><option>--qdf</option></term>
1839 <listitem> 1844 <listitem>
1840 <para> 1845 <para>
qpdf/qpdf.cc
@@ -164,6 +164,7 @@ struct Options @@ -164,6 +164,7 @@ struct Options
164 optimize_images(false), 164 optimize_images(false),
165 externalize_inline_images(false), 165 externalize_inline_images(false),
166 keep_inline_images(false), 166 keep_inline_images(false),
  167 + remove_page_labels(false),
167 oi_min_width(128), // Default values for these 168 oi_min_width(128), // Default values for these
168 oi_min_height(128), // oi flags are in --help 169 oi_min_height(128), // oi flags are in --help
169 oi_min_area(16384), // and in the manual. 170 oi_min_area(16384), // and in the manual.
@@ -261,6 +262,7 @@ struct Options @@ -261,6 +262,7 @@ struct Options
261 bool optimize_images; 262 bool optimize_images;
262 bool externalize_inline_images; 263 bool externalize_inline_images;
263 bool keep_inline_images; 264 bool keep_inline_images;
  265 + bool remove_page_labels;
264 size_t oi_min_width; 266 size_t oi_min_width;
265 size_t oi_min_height; 267 size_t oi_min_height;
266 size_t oi_min_area; 268 size_t oi_min_area;
@@ -670,6 +672,7 @@ class ArgParser @@ -670,6 +672,7 @@ class ArgParser
670 void argOptimizeImages(); 672 void argOptimizeImages();
671 void argExternalizeInlineImages(); 673 void argExternalizeInlineImages();
672 void argKeepInlineImages(); 674 void argKeepInlineImages();
  675 + void argRemovePageLabels();
673 void argOiMinWidth(char* parameter); 676 void argOiMinWidth(char* parameter);
674 void argOiMinHeight(char* parameter); 677 void argOiMinHeight(char* parameter);
675 void argOiMinArea(char* parameter); 678 void argOiMinArea(char* parameter);
@@ -911,6 +914,7 @@ ArgParser::initOptionTable() @@ -911,6 +914,7 @@ ArgParser::initOptionTable()
911 (*t)["externalize-inline-images"] = 914 (*t)["externalize-inline-images"] =
912 oe_bare(&ArgParser::argExternalizeInlineImages); 915 oe_bare(&ArgParser::argExternalizeInlineImages);
913 (*t)["keep-inline-images"] = oe_bare(&ArgParser::argKeepInlineImages); 916 (*t)["keep-inline-images"] = oe_bare(&ArgParser::argKeepInlineImages);
  917 + (*t)["remove-page-labels"] = oe_bare(&ArgParser::argRemovePageLabels);
914 (*t)["oi-min-width"] = oe_requiredParameter( 918 (*t)["oi-min-width"] = oe_requiredParameter(
915 &ArgParser::argOiMinWidth, "minimum-width"); 919 &ArgParser::argOiMinWidth, "minimum-width");
916 (*t)["oi-min-height"] = oe_requiredParameter( 920 (*t)["oi-min-height"] = oe_requiredParameter(
@@ -1335,6 +1339,7 @@ ArgParser::argHelp() @@ -1335,6 +1339,7 @@ ArgParser::argHelp()
1335 << "--ii-min-bytes=bytes specify minimum size of inline images to be\n" 1339 << "--ii-min-bytes=bytes specify minimum size of inline images to be\n"
1336 << " converted to regular images\n" 1340 << " converted to regular images\n"
1337 << "--keep-inline-images exclude inline images from image optimization\n" 1341 << "--keep-inline-images exclude inline images from image optimization\n"
  1342 + << "--remove-page-labels remove any page labels present in the output file\n"
1338 << "--qdf turns on \"QDF mode\" (below)\n" 1343 << "--qdf turns on \"QDF mode\" (below)\n"
1339 << "--linearize-pass1=file write intermediate pass of linearized file\n" 1344 << "--linearize-pass1=file write intermediate pass of linearized file\n"
1340 << " for debugging\n" 1345 << " for debugging\n"
@@ -2013,6 +2018,12 @@ ArgParser::argKeepInlineImages() @@ -2013,6 +2018,12 @@ ArgParser::argKeepInlineImages()
2013 } 2018 }
2014 2019
2015 void 2020 void
  2021 +ArgParser::argRemovePageLabels()
  2022 +{
  2023 + o.remove_page_labels = true;
  2024 +}
  2025 +
  2026 +void
2016 ArgParser::argOiMinWidth(char* parameter) 2027 ArgParser::argOiMinWidth(char* parameter)
2017 { 2028 {
2018 o.oi_min_width = QUtil::string_to_int(parameter); 2029 o.oi_min_width = QUtil::string_to_int(parameter);
@@ -4335,6 +4346,10 @@ static void handle_transformations(QPDF&amp; pdf, Options&amp; o) @@ -4335,6 +4346,10 @@ static void handle_transformations(QPDF&amp; pdf, Options&amp; o)
4335 (*iter).coalesceContentStreams(); 4346 (*iter).coalesceContentStreams();
4336 } 4347 }
4337 } 4348 }
  4349 + if (o.remove_page_labels)
  4350 + {
  4351 + pdf.getRoot().removeKey("/PageLabels");
  4352 + }
4338 } 4353 }
4339 4354
4340 static void handle_page_specs(QPDF& pdf, Options& o) 4355 static void handle_page_specs(QPDF& pdf, Options& o)
qpdf/qtest/qpdf.test
@@ -1877,7 +1877,7 @@ foreach my $f (qw(page_api_2 direct-pages)) @@ -1877,7 +1877,7 @@ foreach my $f (qw(page_api_2 direct-pages))
1877 show_ntests(); 1877 show_ntests();
1878 # ---------- 1878 # ----------
1879 $td->notify("--- Merging and Splitting ---"); 1879 $td->notify("--- Merging and Splitting ---");
1880 -$n_tests += 22; 1880 +$n_tests += 24;
1881 1881
1882 # Select pages from the same file multiple times including selecting 1882 # Select pages from the same file multiple times including selecting
1883 # twice from an encrypted file and specifying the password only the 1883 # twice from an encrypted file and specifying the password only the
@@ -1944,6 +1944,18 @@ $td-&gt;runtest(&quot;merge with multiple labels&quot;, @@ -1944,6 +1944,18 @@ $td-&gt;runtest(&quot;merge with multiple labels&quot;,
1944 $td->runtest("check output", 1944 $td->runtest("check output",
1945 {$td->FILE => "a.pdf"}, 1945 {$td->FILE => "a.pdf"},
1946 {$td->FILE => "merge-multiple-labels.pdf"}); 1946 {$td->FILE => "merge-multiple-labels.pdf"});
  1947 +$td->runtest("remove labels",
  1948 + {$td->COMMAND =>
  1949 + "qpdf --empty a.pdf" .
  1950 + " --remove-page-labels" .
  1951 + " --pages 11-pages-with-labels.pdf 8-11" .
  1952 + " minimal.pdf " .
  1953 + " page-labels-and-outlines.pdf 17-19 --" .
  1954 + " --static-id"},
  1955 + {$td->STRING => "", $td->EXIT_STATUS => 0});
  1956 +$td->runtest("check output",
  1957 + {$td->FILE => "a.pdf"},
  1958 + {$td->FILE => "remove-labels.pdf"});
1947 1959
1948 $td->runtest("split with shared resources", 1960 $td->runtest("split with shared resources",
1949 {$td->COMMAND => 1961 {$td->COMMAND =>
qpdf/qtest/qpdf/remove-labels.pdf 0 → 100644
No preview for this file type