mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
Make page range optional in --rotate (fixes #211)
This commit is contained in:
parent
9d7eef7cc6
commit
84cd53f5af
@ -1,5 +1,9 @@
|
|||||||
2018-06-21 Jay Berkenbilt <ejb@ql.org>
|
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
|
* Create examples/pdf-set-form-values.cc to illustrate use of
|
||||||
interactive form helpers.
|
interactive form helpers.
|
||||||
|
|
||||||
|
@ -412,22 +412,26 @@ make
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>--rotate=[+|-]angle:page-range</option></term>
|
<term><option>--rotate=[+|-]angle[:page-range]</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Apply rotation to specified pages. The
|
Apply rotation to specified pages. The
|
||||||
<option>page-range</option> portion of the option value has
|
<option>page-range</option> portion of the option value has
|
||||||
the same format as page ranges in <xref
|
the same format as page ranges in <xref
|
||||||
linkend="ref.page-selection"/>. The <option>angle</option>
|
linkend="ref.page-selection"/>. If the page range is omitted,
|
||||||
portion of the parameter may be either 90, 180, or 270. If
|
the rotation is applied to all pages. The
|
||||||
preceded by <option>+</option> or <option>-</option>, the
|
<option>angle</option> portion of the parameter may be either
|
||||||
angle is added to or subtracted from the specified pages'
|
90, 180, or 270. If preceded by <option>+</option> or
|
||||||
original rotations. Otherwise the pages' rotations are set to
|
<option>-</option>, the angle is added to or subtracted from
|
||||||
the exact value. For example, the command <command>qpdf in.pdf
|
the specified pages' original rotations. Otherwise the pages'
|
||||||
out.pdf --rotate=+90:2,4,6 --rotate=180:7-8</command> would
|
rotations are set to the exact value. For example, the command
|
||||||
rotate pages 2, 4, and 6 90 degrees clockwise from their
|
<command>qpdf in.pdf out.pdf --rotate=+90:2,4,6
|
||||||
original rotation and force the rotation of pages 7 through 9
|
--rotate=180:7-8</command> would rotate pages 2, 4, and 6 90
|
||||||
to 180 degrees regardless of their original rotation.
|
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>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
39
qpdf/qpdf.cc
39
qpdf/qpdf.cc
@ -241,8 +241,9 @@ Basic Options\n\
|
|||||||
--decrypt remove any encryption on the file\n\
|
--decrypt remove any encryption on the file\n\
|
||||||
--password-is-hex-key treat primary password option as a hex-encoded key\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\
|
--pages options -- select specific pages from one or more files\n\
|
||||||
--rotate=[+|-]angle:page-range\n\
|
--rotate=[+|-]angle[:page-range]\n\
|
||||||
rotate each specified page 90, 180, or 270 degrees\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\
|
--split-pages=[n] write each output page to a separate file\n\
|
||||||
\n\
|
\n\
|
||||||
Note that you can use the @filename or @- syntax for any argument at any\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)
|
if (colon > 0)
|
||||||
{
|
{
|
||||||
angle_str = parameter.substr(0, colon);
|
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())
|
if (colon + 1 < parameter.length())
|
||||||
{
|
{
|
||||||
range = parameter.substr(colon + 1);
|
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;
|
bool range_valid = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1124,7 +1124,7 @@ foreach my $d (@sp_cases)
|
|||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Rotate Pages ---");
|
$td->notify("--- Rotate Pages ---");
|
||||||
$n_tests += 2;
|
$n_tests += 4;
|
||||||
# Do absolute, positive, and negative on ranges that include
|
# Do absolute, positive, and negative on ranges that include
|
||||||
# inherited and non-inherited.
|
# inherited and non-inherited.
|
||||||
# Pages 11-15 inherit /Rotate 90
|
# Pages 11-15 inherit /Rotate 90
|
||||||
@ -1141,6 +1141,14 @@ $td->runtest("check output",
|
|||||||
{$td->FILE => "a.pdf"},
|
{$td->FILE => "a.pdf"},
|
||||||
{$td->FILE => "rotated.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();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Numeric range parsing tests ---");
|
$td->notify("--- Numeric range parsing tests ---");
|
||||||
|
BIN
qpdf/qtest/qpdf/minimal-rotated.pdf
Normal file
BIN
qpdf/qtest/qpdf/minimal-rotated.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user