2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Make page range optional in --rotate (fixes #211)

This commit is contained in:
Jay Berkenbilt 2018-06-21 16:28:44 -04:00
parent 9d7eef7cc6
commit 84cd53f5af
5 changed files with 52 additions and 27 deletions

View File

@ -1,5 +1,9 @@
2018-06-21 Jay Berkenbilt <ejb@ql.org>
* The --rotate option to qpdf no longer requires an explicit page
range. You can now rotate all pages of a document with
qpdf --rotate=angle in.pdf out.pdf. Fixes #211.
* Create examples/pdf-set-form-values.cc to illustrate use of
interactive form helpers.

View File

@ -412,22 +412,26 @@ make
</listitem>
</varlistentry>
<varlistentry>
<term><option>--rotate=[+|-]angle:page-range</option></term>
<term><option>--rotate=[+|-]angle[:page-range]</option></term>
<listitem>
<para>
Apply rotation to specified pages. The
<option>page-range</option> portion of the option value has
the same format as page ranges in <xref
linkend="ref.page-selection"/>. The <option>angle</option>
portion of the parameter may be either 90, 180, or 270. If
preceded by <option>+</option> or <option>-</option>, the
angle is added to or subtracted from the specified pages'
original rotations. Otherwise the pages' rotations are set to
the exact value. For example, the command <command>qpdf in.pdf
out.pdf --rotate=+90:2,4,6 --rotate=180:7-8</command> would
rotate pages 2, 4, and 6 90 degrees clockwise from their
original rotation and force the rotation of pages 7 through 9
to 180 degrees regardless of their original rotation.
linkend="ref.page-selection"/>. If the page range is omitted,
the rotation is applied to all pages. The
<option>angle</option> portion of the parameter may be either
90, 180, or 270. If preceded by <option>+</option> or
<option>-</option>, the angle is added to or subtracted from
the specified pages' original rotations. Otherwise the pages'
rotations are set to the exact value. For example, the command
<command>qpdf in.pdf out.pdf --rotate=+90:2,4,6
--rotate=180:7-8</command> would rotate pages 2, 4, and 6 90
degrees clockwise from their original rotation and force the
rotation of pages 7 through 9 to 180 degrees regardless of
their original rotation, and the command <command>qpdf in.pdf
out.pdf --rotate=180</command> would rotate all pages by 180
degrees.
</para>
</listitem>
</varlistentry>

View File

@ -241,8 +241,9 @@ Basic Options\n\
--decrypt remove any encryption on the file\n\
--password-is-hex-key treat primary password option as a hex-encoded key\n\
--pages options -- select specific pages from one or more files\n\
--rotate=[+|-]angle:page-range\n\
rotate each specified page 90, 180, or 270 degrees\n\
--rotate=[+|-]angle[:page-range]\n\
rotate each specified page 90, 180, or 270 degrees;\n\
rotate all pages if no page range is given\n\
--split-pages=[n] write each output page to a separate file\n\
\n\
Note that you can use the @filename or @- syntax for any argument at any\n\
@ -1303,25 +1304,33 @@ static void parse_rotation_parameter(Options& o, std::string const& parameter)
if (colon > 0)
{
angle_str = parameter.substr(0, colon);
if (angle_str.length() > 0)
{
char first = angle_str.at(0);
if ((first == '+') || (first == '-'))
{
relative = ((first == '+') ? 1 : -1);
angle_str = angle_str.substr(1);
}
else if (! QUtil::is_digit(angle_str.at(0)))
{
angle_str = "";
}
}
}
if (colon + 1 < parameter.length())
{
range = parameter.substr(colon + 1);
}
}
else
{
angle_str = parameter;
}
if (angle_str.length() > 0)
{
char first = angle_str.at(0);
if ((first == '+') || (first == '-'))
{
relative = ((first == '+') ? 1 : -1);
angle_str = angle_str.substr(1);
}
else if (! QUtil::is_digit(angle_str.at(0)))
{
angle_str = "";
}
}
if (range.empty())
{
range = "1-z";
}
bool range_valid = false;
try
{

View File

@ -1124,7 +1124,7 @@ foreach my $d (@sp_cases)
show_ntests();
# ----------
$td->notify("--- Rotate Pages ---");
$n_tests += 2;
$n_tests += 4;
# Do absolute, positive, and negative on ranges that include
# inherited and non-inherited.
# Pages 11-15 inherit /Rotate 90
@ -1141,6 +1141,14 @@ $td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "rotated.pdf"});
$td->runtest("rotate all pages",
{$td->COMMAND =>
"qpdf --static-id --rotate=180 minimal.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "minimal-rotated.pdf"});
show_ntests();
# ----------
$td->notify("--- Numeric range parsing tests ---");

Binary file not shown.