Skip to content

Commit

Permalink
Add --remove-page-labels option (fixes qpdf#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkenbilt committed Apr 21, 2019
1 parent e50d520 commit 2b011f9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
2019-04-20 Jay Berkenbilt <[email protected]>

* Add parameter --remove-page-labels to remove page labels from
output. In qpdf 8.3.0, the behavior changed so that page labels
were preserved when merging and splitting files. Some users were
relying on the fact that if you ran qpdf --empty --pages ... all
page labels were dropped. This option makes it possible to get
that behavior if it is explicitly desired. Fixes #317.

* Add parameter --keep-files-open-threshold to override the
maximum number of files that qpdf will allow to be kept open at
once. Fixes #288.
Expand Down
11 changes: 8 additions & 3 deletions manual/qpdf-manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1797,9 +1797,6 @@ outfile.pdf</option>
</para>
</listitem>
</varlistentry>



<varlistentry>
<term><option>--externalize-inline-images</option></term>
<listitem>
Expand Down Expand Up @@ -1834,6 +1831,14 @@ outfile.pdf</option>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--remove-page-labels</option></term>
<listitem>
<para>
Remove page labels from the output file.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--qdf</option></term>
<listitem>
Expand Down
15 changes: 15 additions & 0 deletions qpdf/qpdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct Options
optimize_images(false),
externalize_inline_images(false),
keep_inline_images(false),
remove_page_labels(false),
oi_min_width(128), // Default values for these
oi_min_height(128), // oi flags are in --help
oi_min_area(16384), // and in the manual.
Expand Down Expand Up @@ -261,6 +262,7 @@ struct Options
bool optimize_images;
bool externalize_inline_images;
bool keep_inline_images;
bool remove_page_labels;
size_t oi_min_width;
size_t oi_min_height;
size_t oi_min_area;
Expand Down Expand Up @@ -670,6 +672,7 @@ class ArgParser
void argOptimizeImages();
void argExternalizeInlineImages();
void argKeepInlineImages();
void argRemovePageLabels();
void argOiMinWidth(char* parameter);
void argOiMinHeight(char* parameter);
void argOiMinArea(char* parameter);
Expand Down Expand Up @@ -911,6 +914,7 @@ ArgParser::initOptionTable()
(*t)["externalize-inline-images"] =
oe_bare(&ArgParser::argExternalizeInlineImages);
(*t)["keep-inline-images"] = oe_bare(&ArgParser::argKeepInlineImages);
(*t)["remove-page-labels"] = oe_bare(&ArgParser::argRemovePageLabels);
(*t)["oi-min-width"] = oe_requiredParameter(
&ArgParser::argOiMinWidth, "minimum-width");
(*t)["oi-min-height"] = oe_requiredParameter(
Expand Down Expand Up @@ -1335,6 +1339,7 @@ ArgParser::argHelp()
<< "--ii-min-bytes=bytes specify minimum size of inline images to be\n"
<< " converted to regular images\n"
<< "--keep-inline-images exclude inline images from image optimization\n"
<< "--remove-page-labels remove any page labels present in the output file\n"
<< "--qdf turns on \"QDF mode\" (below)\n"
<< "--linearize-pass1=file write intermediate pass of linearized file\n"
<< " for debugging\n"
Expand Down Expand Up @@ -2012,6 +2017,12 @@ ArgParser::argKeepInlineImages()
o.keep_inline_images = true;
}

void
ArgParser::argRemovePageLabels()
{
o.remove_page_labels = true;
}

void
ArgParser::argOiMinWidth(char* parameter)
{
Expand Down Expand Up @@ -4335,6 +4346,10 @@ static void handle_transformations(QPDF& pdf, Options& o)
(*iter).coalesceContentStreams();
}
}
if (o.remove_page_labels)
{
pdf.getRoot().removeKey("/PageLabels");
}
}

static void handle_page_specs(QPDF& pdf, Options& o)
Expand Down
14 changes: 13 additions & 1 deletion qpdf/qtest/qpdf.test
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,7 @@ foreach my $f (qw(page_api_2 direct-pages))
show_ntests();
# ----------
$td->notify("--- Merging and Splitting ---");
$n_tests += 22;
$n_tests += 24;

# Select pages from the same file multiple times including selecting
# twice from an encrypted file and specifying the password only the
Expand Down Expand Up @@ -1944,6 +1944,18 @@ $td->runtest("merge with multiple labels",
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "merge-multiple-labels.pdf"});
$td->runtest("remove labels",
{$td->COMMAND =>
"qpdf --empty a.pdf" .
" --remove-page-labels" .
" --pages 11-pages-with-labels.pdf 8-11" .
" minimal.pdf " .
" page-labels-and-outlines.pdf 17-19 --" .
" --static-id"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "remove-labels.pdf"});

$td->runtest("split with shared resources",
{$td->COMMAND =>
Expand Down
Binary file added qpdf/qtest/qpdf/remove-labels.pdf
Binary file not shown.

0 comments on commit 2b011f9

Please sign in to comment.