Commit 2b011f9d817fa2cb2e8ed0b410f655e9e61cb6fa

Authored by Jay Berkenbilt
1 parent e50d5201

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

ChangeLog
1 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 10 * Add parameter --keep-files-open-threshold to override the
4 11 maximum number of files that qpdf will allow to be kept open at
5 12 once. Fixes #288.
... ...
manual/qpdf-manual.xml
... ... @@ -1797,9 +1797,6 @@ outfile.pdf&lt;/option&gt;
1797 1797 </para>
1798 1798 </listitem>
1799 1799 </varlistentry>
1800   -
1801   -
1802   -
1803 1800 <varlistentry>
1804 1801 <term><option>--externalize-inline-images</option></term>
1805 1802 <listitem>
... ... @@ -1835,6 +1832,14 @@ outfile.pdf&lt;/option&gt;
1835 1832 </listitem>
1836 1833 </varlistentry>
1837 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 1843 <term><option>--qdf</option></term>
1839 1844 <listitem>
1840 1845 <para>
... ...
qpdf/qpdf.cc
... ... @@ -164,6 +164,7 @@ struct Options
164 164 optimize_images(false),
165 165 externalize_inline_images(false),
166 166 keep_inline_images(false),
  167 + remove_page_labels(false),
167 168 oi_min_width(128), // Default values for these
168 169 oi_min_height(128), // oi flags are in --help
169 170 oi_min_area(16384), // and in the manual.
... ... @@ -261,6 +262,7 @@ struct Options
261 262 bool optimize_images;
262 263 bool externalize_inline_images;
263 264 bool keep_inline_images;
  265 + bool remove_page_labels;
264 266 size_t oi_min_width;
265 267 size_t oi_min_height;
266 268 size_t oi_min_area;
... ... @@ -670,6 +672,7 @@ class ArgParser
670 672 void argOptimizeImages();
671 673 void argExternalizeInlineImages();
672 674 void argKeepInlineImages();
  675 + void argRemovePageLabels();
673 676 void argOiMinWidth(char* parameter);
674 677 void argOiMinHeight(char* parameter);
675 678 void argOiMinArea(char* parameter);
... ... @@ -911,6 +914,7 @@ ArgParser::initOptionTable()
911 914 (*t)["externalize-inline-images"] =
912 915 oe_bare(&ArgParser::argExternalizeInlineImages);
913 916 (*t)["keep-inline-images"] = oe_bare(&ArgParser::argKeepInlineImages);
  917 + (*t)["remove-page-labels"] = oe_bare(&ArgParser::argRemovePageLabels);
914 918 (*t)["oi-min-width"] = oe_requiredParameter(
915 919 &ArgParser::argOiMinWidth, "minimum-width");
916 920 (*t)["oi-min-height"] = oe_requiredParameter(
... ... @@ -1335,6 +1339,7 @@ ArgParser::argHelp()
1335 1339 << "--ii-min-bytes=bytes specify minimum size of inline images to be\n"
1336 1340 << " converted to regular images\n"
1337 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 1343 << "--qdf turns on \"QDF mode\" (below)\n"
1339 1344 << "--linearize-pass1=file write intermediate pass of linearized file\n"
1340 1345 << " for debugging\n"
... ... @@ -2013,6 +2018,12 @@ ArgParser::argKeepInlineImages()
2013 2018 }
2014 2019  
2015 2020 void
  2021 +ArgParser::argRemovePageLabels()
  2022 +{
  2023 + o.remove_page_labels = true;
  2024 +}
  2025 +
  2026 +void
2016 2027 ArgParser::argOiMinWidth(char* parameter)
2017 2028 {
2018 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 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 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 1877 show_ntests();
1878 1878 # ----------
1879 1879 $td->notify("--- Merging and Splitting ---");
1880   -$n_tests += 22;
  1880 +$n_tests += 24;
1881 1881  
1882 1882 # Select pages from the same file multiple times including selecting
1883 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 1944 $td->runtest("check output",
1945 1945 {$td->FILE => "a.pdf"},
1946 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 1960 $td->runtest("split with shared resources",
1949 1961 {$td->COMMAND =>
... ...
qpdf/qtest/qpdf/remove-labels.pdf 0 → 100644
No preview for this file type