Commit 53d8e916b75b983c18d4611e91d6e74cb51a49ec
1 parent
5f128b9a
Interpret . in --pages as a shortcut for the primary file
Showing
4 changed files
with
31 additions
and
12 deletions
ChangeLog
| 1 | +2019-01-12 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * In --pages, allow "." as a replacement for the current input | ||
| 4 | + file, making it possible to say "qpdf A.pdf --pages . 1-3 --" | ||
| 5 | + instead of having to repeat the input filename. | ||
| 6 | + | ||
| 1 | 2019-01-10 Jay Berkenbilt <ejb@ql.org> | 7 | 2019-01-10 Jay Berkenbilt <ejb@ql.org> |
| 2 | 8 | ||
| 3 | * Add new configure option --enable-avoid-windows-handle, which | 9 | * Add new configure option --enable-avoid-windows-handle, which |
manual/qpdf-manual.xml
| @@ -956,6 +956,11 @@ make | @@ -956,6 +956,11 @@ make | ||
| 956 | selection flags. | 956 | selection flags. |
| 957 | </para> | 957 | </para> |
| 958 | <para> | 958 | <para> |
| 959 | + Starting with qpf 8.4, the special input file name | ||
| 960 | + “<filename>.</filename>” can be used shortcut for the | ||
| 961 | + primary input filename. | ||
| 962 | + </para> | ||
| 963 | + <para> | ||
| 959 | For each file that pages should be taken from, specify the file, a | 964 | For each file that pages should be taken from, specify the file, a |
| 960 | password needed to open the file (if any), and a page range. The | 965 | password needed to open the file (if any), and a page range. The |
| 961 | password needs to be given only once per file. If any of the | 966 | password needs to be given only once per file. If any of the |
| @@ -1075,7 +1080,7 @@ make | @@ -1075,7 +1080,7 @@ make | ||
| 1075 | <filename>infile.pdf</filename> while preserving all metadata | 1080 | <filename>infile.pdf</filename> while preserving all metadata |
| 1076 | associated with that file, you could use | 1081 | associated with that file, you could use |
| 1077 | 1082 | ||
| 1078 | - <programlisting><command>qpdf</command> <option>infile.pdf --pages infile.pdf 1-5 -- outfile.pdf</option> | 1083 | + <programlisting><command>qpdf</command> <option>infile.pdf --pages . 1-5 -- outfile.pdf</option> |
| 1079 | </programlisting> | 1084 | </programlisting> |
| 1080 | If you wanted pages 1 through 5 from | 1085 | If you wanted pages 1 through 5 from |
| 1081 | <filename>infile.pdf</filename> but you wanted the rest of the | 1086 | <filename>infile.pdf</filename> but you wanted the rest of the |
| @@ -1087,7 +1092,7 @@ make | @@ -1087,7 +1092,7 @@ make | ||
| 1087 | <filename>file1.pdf</filename> and pages 11–15 from | 1092 | <filename>file1.pdf</filename> and pages 11–15 from |
| 1088 | <filename>file2.pdf</filename> in reverse, you would run | 1093 | <filename>file2.pdf</filename> in reverse, you would run |
| 1089 | 1094 | ||
| 1090 | - <programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 file2.pdf 15-11 -- outfile.pdf</option> | 1095 | + <programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 . 15-11 -- outfile.pdf</option> |
| 1091 | </programlisting> | 1096 | </programlisting> |
| 1092 | If, for some reason, you wanted to take the first page of an | 1097 | If, for some reason, you wanted to take the first page of an |
| 1093 | encrypted file called <filename>encrypted.pdf</filename> with | 1098 | encrypted file called <filename>encrypted.pdf</filename> with |
qpdf/qpdf.cc
| @@ -1092,7 +1092,8 @@ ArgParser::argHelp() | @@ -1092,7 +1092,8 @@ ArgParser::argHelp() | ||
| 1092 | << "password needs to be given only once per file. If any of the input\n" | 1092 | << "password needs to be given only once per file. If any of the input\n" |
| 1093 | << "files are the same as the primary input file or the file used to copy\n" | 1093 | << "files are the same as the primary input file or the file used to copy\n" |
| 1094 | << "encryption parameters (if specified), you do not need to repeat the\n" | 1094 | << "encryption parameters (if specified), you do not need to repeat the\n" |
| 1095 | - << "password here. The same file can be repeated multiple times. All\n" | 1095 | + << "password here. The same file can be repeated multiple times. The\n" |
| 1096 | + << "filename \".\" may be used to refer to the current input file. All\n" | ||
| 1096 | << "non-page data (info, outlines, page numbers, etc. are taken from the\n" | 1097 | << "non-page data (info, outlines, page numbers, etc. are taken from the\n" |
| 1097 | << "primary input file. To discard this, use --empty as the primary\n" | 1098 | << "primary input file. To discard this, use --empty as the primary\n" |
| 1098 | << "input.\n" | 1099 | << "input.\n" |
| @@ -3676,6 +3677,17 @@ static void handle_page_specs(QPDF& pdf, Options& o) | @@ -3676,6 +3677,17 @@ static void handle_page_specs(QPDF& pdf, Options& o) | ||
| 3676 | // Parse all page specifications and translate them into lists of | 3677 | // Parse all page specifications and translate them into lists of |
| 3677 | // actual pages. | 3678 | // actual pages. |
| 3678 | 3679 | ||
| 3680 | + // Handle "." as a shortcut for the input file | ||
| 3681 | + for (std::vector<PageSpec>::iterator iter = o.page_specs.begin(); | ||
| 3682 | + iter != o.page_specs.end(); ++iter) | ||
| 3683 | + { | ||
| 3684 | + PageSpec& page_spec = *iter; | ||
| 3685 | + if (page_spec.filename == ".") | ||
| 3686 | + { | ||
| 3687 | + page_spec.filename = o.infilename; | ||
| 3688 | + } | ||
| 3689 | + } | ||
| 3690 | + | ||
| 3679 | if (! o.keep_files_open_set) | 3691 | if (! o.keep_files_open_set) |
| 3680 | { | 3692 | { |
| 3681 | // Count the number of distinct files to determine whether we | 3693 | // Count the number of distinct files to determine whether we |
qpdf/qtest/qpdf.test
| @@ -1692,11 +1692,10 @@ $td->runtest("check output", | @@ -1692,11 +1692,10 @@ $td->runtest("check output", | ||
| 1692 | {$td->FILE => "a.pdf"}, | 1692 | {$td->FILE => "a.pdf"}, |
| 1693 | {$td->FILE => "merge-multiple-labels.pdf"}); | 1693 | {$td->FILE => "merge-multiple-labels.pdf"}); |
| 1694 | 1694 | ||
| 1695 | -$td->runtest("split with shared resources", | 1695 | +$td->runtest("split with shared resources", # QXXXQ |
| 1696 | {$td->COMMAND => | 1696 | {$td->COMMAND => |
| 1697 | "qpdf --qdf --static-id" . | 1697 | "qpdf --qdf --static-id" . |
| 1698 | - " shared-images.pdf --pages" . | ||
| 1699 | - " shared-images.pdf 1,3" . | 1698 | + " shared-images.pdf --pages . 1,3" . |
| 1700 | " ./shared-images.pdf 1,2 -- a.pdf"}, | 1699 | " ./shared-images.pdf 1,2 -- a.pdf"}, |
| 1701 | {$td->STRING => "", $td->EXIT_STATUS => 0}); | 1700 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 1702 | $td->runtest("check output", | 1701 | $td->runtest("check output", |
| @@ -1706,8 +1705,7 @@ $td->runtest("check output", | @@ -1706,8 +1705,7 @@ $td->runtest("check output", | ||
| 1706 | $td->runtest("shared resources relevant errors", | 1705 | $td->runtest("shared resources relevant errors", |
| 1707 | {$td->COMMAND => | 1706 | {$td->COMMAND => |
| 1708 | "qpdf --qdf --static-id" . | 1707 | "qpdf --qdf --static-id" . |
| 1709 | - " shared-images-errors.pdf --pages" . | ||
| 1710 | - " shared-images-errors.pdf 2 -- a.pdf"}, | 1708 | + " shared-images-errors.pdf --pages . 2 -- a.pdf"}, |
| 1711 | {$td->FILE => "shared-images-errors-2.out", | 1709 | {$td->FILE => "shared-images-errors-2.out", |
| 1712 | $td->EXIT_STATUS => 3}, | 1710 | $td->EXIT_STATUS => 3}, |
| 1713 | $td->NORMALIZE_NEWLINES); | 1711 | $td->NORMALIZE_NEWLINES); |
| @@ -1718,8 +1716,7 @@ $td->runtest("check output", | @@ -1718,8 +1716,7 @@ $td->runtest("check output", | ||
| 1718 | $td->runtest("shared resources irrelevant errors", | 1716 | $td->runtest("shared resources irrelevant errors", |
| 1719 | {$td->COMMAND => | 1717 | {$td->COMMAND => |
| 1720 | "qpdf --qdf --static-id" . | 1718 | "qpdf --qdf --static-id" . |
| 1721 | - " shared-images-errors.pdf --pages" . | ||
| 1722 | - " shared-images-errors.pdf 1 -- a.pdf"}, | 1719 | + " shared-images-errors.pdf --pages . 1 -- a.pdf"}, |
| 1723 | {$td->FILE => "shared-images-errors-1.out", | 1720 | {$td->FILE => "shared-images-errors-1.out", |
| 1724 | $td->EXIT_STATUS => 3}, | 1721 | $td->EXIT_STATUS => 3}, |
| 1725 | $td->NORMALIZE_NEWLINES); | 1722 | $td->NORMALIZE_NEWLINES); |
| @@ -1730,8 +1727,7 @@ $td->runtest("check output", | @@ -1730,8 +1727,7 @@ $td->runtest("check output", | ||
| 1730 | $td->runtest("don't remove shared resources", | 1727 | $td->runtest("don't remove shared resources", |
| 1731 | {$td->COMMAND => | 1728 | {$td->COMMAND => |
| 1732 | "qpdf --qdf --static-id --preserve-unreferenced-resources" . | 1729 | "qpdf --qdf --static-id --preserve-unreferenced-resources" . |
| 1733 | - " shared-images.pdf --pages" . | ||
| 1734 | - " shared-images.pdf 1,3 -- a.pdf"}, | 1730 | + " shared-images.pdf --pages . 1,3 -- a.pdf"}, |
| 1735 | {$td->STRING => "", $td->EXIT_STATUS => 0}); | 1731 | {$td->STRING => "", $td->EXIT_STATUS => 0}); |
| 1736 | $td->runtest("check output", | 1732 | $td->runtest("check output", |
| 1737 | {$td->FILE => "a.pdf"}, | 1733 | {$td->FILE => "a.pdf"}, |