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

Interpret . in --pages as a shortcut for the primary file

This commit is contained in:
Jay Berkenbilt 2019-01-12 09:21:52 -05:00
parent 5f128b9a27
commit 53d8e916b7
4 changed files with 31 additions and 12 deletions

View File

@ -1,3 +1,9 @@
2019-01-12 Jay Berkenbilt <ejb@ql.org>
* In --pages, allow "." as a replacement for the current input
file, making it possible to say "qpdf A.pdf --pages . 1-3 --"
instead of having to repeat the input filename.
2019-01-10 Jay Berkenbilt <ejb@ql.org>
* Add new configure option --enable-avoid-windows-handle, which

View File

@ -955,6 +955,11 @@ make
&ldquo;<option>--</option>&rdquo; terminates parsing of page
selection flags.
</para>
<para>
Starting with qpf 8.4, the special input file name
&ldquo;<filename>.</filename>&rdquo; can be used shortcut for the
primary input filename.
</para>
<para>
For each file that pages should be taken from, specify the file, a
password needed to open the file (if any), and a page range. The
@ -1075,7 +1080,7 @@ make
<filename>infile.pdf</filename> while preserving all metadata
associated with that file, you could use
<programlisting><command>qpdf</command> <option>infile.pdf --pages infile.pdf 1-5 -- outfile.pdf</option>
<programlisting><command>qpdf</command> <option>infile.pdf --pages . 1-5 -- outfile.pdf</option>
</programlisting>
If you wanted pages 1 through 5 from
<filename>infile.pdf</filename> but you wanted the rest of the
@ -1087,7 +1092,7 @@ make
<filename>file1.pdf</filename> and pages 11&ndash;15 from
<filename>file2.pdf</filename> in reverse, you would run
<programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 file2.pdf 15-11 -- outfile.pdf</option>
<programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 . 15-11 -- outfile.pdf</option>
</programlisting>
If, for some reason, you wanted to take the first page of an
encrypted file called <filename>encrypted.pdf</filename> with

View File

@ -1092,7 +1092,8 @@ ArgParser::argHelp()
<< "password needs to be given only once per file. If any of the input\n"
<< "files are the same as the primary input file or the file used to copy\n"
<< "encryption parameters (if specified), you do not need to repeat the\n"
<< "password here. The same file can be repeated multiple times. All\n"
<< "password here. The same file can be repeated multiple times. The\n"
<< "filename \".\" may be used to refer to the current input file. All\n"
<< "non-page data (info, outlines, page numbers, etc. are taken from the\n"
<< "primary input file. To discard this, use --empty as the primary\n"
<< "input.\n"
@ -3676,6 +3677,17 @@ static void handle_page_specs(QPDF& pdf, Options& o)
// Parse all page specifications and translate them into lists of
// actual pages.
// Handle "." as a shortcut for the input file
for (std::vector<PageSpec>::iterator iter = o.page_specs.begin();
iter != o.page_specs.end(); ++iter)
{
PageSpec& page_spec = *iter;
if (page_spec.filename == ".")
{
page_spec.filename = o.infilename;
}
}
if (! o.keep_files_open_set)
{
// Count the number of distinct files to determine whether we

View File

@ -1692,11 +1692,10 @@ $td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "merge-multiple-labels.pdf"});
$td->runtest("split with shared resources",
$td->runtest("split with shared resources", # QXXXQ
{$td->COMMAND =>
"qpdf --qdf --static-id" .
" shared-images.pdf --pages" .
" shared-images.pdf 1,3" .
" shared-images.pdf --pages . 1,3" .
" ./shared-images.pdf 1,2 -- a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
@ -1706,8 +1705,7 @@ $td->runtest("check output",
$td->runtest("shared resources relevant errors",
{$td->COMMAND =>
"qpdf --qdf --static-id" .
" shared-images-errors.pdf --pages" .
" shared-images-errors.pdf 2 -- a.pdf"},
" shared-images-errors.pdf --pages . 2 -- a.pdf"},
{$td->FILE => "shared-images-errors-2.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
@ -1718,8 +1716,7 @@ $td->runtest("check output",
$td->runtest("shared resources irrelevant errors",
{$td->COMMAND =>
"qpdf --qdf --static-id" .
" shared-images-errors.pdf --pages" .
" shared-images-errors.pdf 1 -- a.pdf"},
" shared-images-errors.pdf --pages . 1 -- a.pdf"},
{$td->FILE => "shared-images-errors-1.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
@ -1730,8 +1727,7 @@ $td->runtest("check output",
$td->runtest("don't remove shared resources",
{$td->COMMAND =>
"qpdf --qdf --static-id --preserve-unreferenced-resources" .
" shared-images.pdf --pages" .
" shared-images.pdf 1,3 -- a.pdf"},
" shared-images.pdf --pages . 1,3 -- a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
{$td->FILE => "a.pdf"},