Commit 84cd53f5af72f8d1da5c6e73ebf7997243bf0b2c
1 parent
9d7eef7c
Make page range optional in --rotate (fixes #211)
Showing
5 changed files
with
52 additions
and
27 deletions
ChangeLog
| 1 | 1 | 2018-06-21 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | |
| 3 | + * The --rotate option to qpdf no longer requires an explicit page | |
| 4 | + range. You can now rotate all pages of a document with | |
| 5 | + qpdf --rotate=angle in.pdf out.pdf. Fixes #211. | |
| 6 | + | |
| 3 | 7 | * Create examples/pdf-set-form-values.cc to illustrate use of |
| 4 | 8 | interactive form helpers. |
| 5 | 9 | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -412,22 +412,26 @@ make |
| 412 | 412 | </listitem> |
| 413 | 413 | </varlistentry> |
| 414 | 414 | <varlistentry> |
| 415 | - <term><option>--rotate=[+|-]angle:page-range</option></term> | |
| 415 | + <term><option>--rotate=[+|-]angle[:page-range]</option></term> | |
| 416 | 416 | <listitem> |
| 417 | 417 | <para> |
| 418 | 418 | Apply rotation to specified pages. The |
| 419 | 419 | <option>page-range</option> portion of the option value has |
| 420 | 420 | the same format as page ranges in <xref |
| 421 | - linkend="ref.page-selection"/>. The <option>angle</option> | |
| 422 | - portion of the parameter may be either 90, 180, or 270. If | |
| 423 | - preceded by <option>+</option> or <option>-</option>, the | |
| 424 | - angle is added to or subtracted from the specified pages' | |
| 425 | - original rotations. Otherwise the pages' rotations are set to | |
| 426 | - the exact value. For example, the command <command>qpdf in.pdf | |
| 427 | - out.pdf --rotate=+90:2,4,6 --rotate=180:7-8</command> would | |
| 428 | - rotate pages 2, 4, and 6 90 degrees clockwise from their | |
| 429 | - original rotation and force the rotation of pages 7 through 9 | |
| 430 | - to 180 degrees regardless of their original rotation. | |
| 421 | + linkend="ref.page-selection"/>. If the page range is omitted, | |
| 422 | + the rotation is applied to all pages. The | |
| 423 | + <option>angle</option> portion of the parameter may be either | |
| 424 | + 90, 180, or 270. If preceded by <option>+</option> or | |
| 425 | + <option>-</option>, the angle is added to or subtracted from | |
| 426 | + the specified pages' original rotations. Otherwise the pages' | |
| 427 | + rotations are set to the exact value. For example, the command | |
| 428 | + <command>qpdf in.pdf out.pdf --rotate=+90:2,4,6 | |
| 429 | + --rotate=180:7-8</command> would rotate pages 2, 4, and 6 90 | |
| 430 | + degrees clockwise from their original rotation and force the | |
| 431 | + rotation of pages 7 through 9 to 180 degrees regardless of | |
| 432 | + their original rotation, and the command <command>qpdf in.pdf | |
| 433 | + out.pdf --rotate=180</command> would rotate all pages by 180 | |
| 434 | + degrees. | |
| 431 | 435 | </para> |
| 432 | 436 | </listitem> |
| 433 | 437 | </varlistentry> | ... | ... |
qpdf/qpdf.cc
| ... | ... | @@ -241,8 +241,9 @@ Basic Options\n\ |
| 241 | 241 | --decrypt remove any encryption on the file\n\ |
| 242 | 242 | --password-is-hex-key treat primary password option as a hex-encoded key\n\ |
| 243 | 243 | --pages options -- select specific pages from one or more files\n\ |
| 244 | ---rotate=[+|-]angle:page-range\n\ | |
| 245 | - rotate each specified page 90, 180, or 270 degrees\n\ | |
| 244 | +--rotate=[+|-]angle[:page-range]\n\ | |
| 245 | + rotate each specified page 90, 180, or 270 degrees;\n\ | |
| 246 | + rotate all pages if no page range is given\n\ | |
| 246 | 247 | --split-pages=[n] write each output page to a separate file\n\ |
| 247 | 248 | \n\ |
| 248 | 249 | 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) |
| 1303 | 1304 | if (colon > 0) |
| 1304 | 1305 | { |
| 1305 | 1306 | angle_str = parameter.substr(0, colon); |
| 1306 | - if (angle_str.length() > 0) | |
| 1307 | - { | |
| 1308 | - char first = angle_str.at(0); | |
| 1309 | - if ((first == '+') || (first == '-')) | |
| 1310 | - { | |
| 1311 | - relative = ((first == '+') ? 1 : -1); | |
| 1312 | - angle_str = angle_str.substr(1); | |
| 1313 | - } | |
| 1314 | - else if (! QUtil::is_digit(angle_str.at(0))) | |
| 1315 | - { | |
| 1316 | - angle_str = ""; | |
| 1317 | - } | |
| 1318 | - } | |
| 1319 | 1307 | } |
| 1320 | 1308 | if (colon + 1 < parameter.length()) |
| 1321 | 1309 | { |
| 1322 | 1310 | range = parameter.substr(colon + 1); |
| 1323 | 1311 | } |
| 1324 | 1312 | } |
| 1313 | + else | |
| 1314 | + { | |
| 1315 | + angle_str = parameter; | |
| 1316 | + } | |
| 1317 | + if (angle_str.length() > 0) | |
| 1318 | + { | |
| 1319 | + char first = angle_str.at(0); | |
| 1320 | + if ((first == '+') || (first == '-')) | |
| 1321 | + { | |
| 1322 | + relative = ((first == '+') ? 1 : -1); | |
| 1323 | + angle_str = angle_str.substr(1); | |
| 1324 | + } | |
| 1325 | + else if (! QUtil::is_digit(angle_str.at(0))) | |
| 1326 | + { | |
| 1327 | + angle_str = ""; | |
| 1328 | + } | |
| 1329 | + } | |
| 1330 | + if (range.empty()) | |
| 1331 | + { | |
| 1332 | + range = "1-z"; | |
| 1333 | + } | |
| 1325 | 1334 | bool range_valid = false; |
| 1326 | 1335 | try |
| 1327 | 1336 | { | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -1124,7 +1124,7 @@ foreach my $d (@sp_cases) |
| 1124 | 1124 | show_ntests(); |
| 1125 | 1125 | # ---------- |
| 1126 | 1126 | $td->notify("--- Rotate Pages ---"); |
| 1127 | -$n_tests += 2; | |
| 1127 | +$n_tests += 4; | |
| 1128 | 1128 | # Do absolute, positive, and negative on ranges that include |
| 1129 | 1129 | # inherited and non-inherited. |
| 1130 | 1130 | # Pages 11-15 inherit /Rotate 90 |
| ... | ... | @@ -1141,6 +1141,14 @@ $td->runtest("check output", |
| 1141 | 1141 | {$td->FILE => "a.pdf"}, |
| 1142 | 1142 | {$td->FILE => "rotated.pdf"}); |
| 1143 | 1143 | |
| 1144 | +$td->runtest("rotate all pages", | |
| 1145 | + {$td->COMMAND => | |
| 1146 | + "qpdf --static-id --rotate=180 minimal.pdf a.pdf"}, | |
| 1147 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | |
| 1148 | +$td->runtest("check output", | |
| 1149 | + {$td->FILE => "a.pdf"}, | |
| 1150 | + {$td->FILE => "minimal-rotated.pdf"}); | |
| 1151 | + | |
| 1144 | 1152 | show_ntests(); |
| 1145 | 1153 | # ---------- |
| 1146 | 1154 | $td->notify("--- Numeric range parsing tests ---"); | ... | ... |
qpdf/qtest/qpdf/minimal-rotated.pdf
0 → 100644
No preview for this file type