From 53d8e916b75b983c18d4611e91d6e74cb51a49ec Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 12 Jan 2019 09:21:52 -0500 Subject: [PATCH] Interpret . in --pages as a shortcut for the primary file --- ChangeLog | 6 ++++++ manual/qpdf-manual.xml | 9 +++++++-- qpdf/qpdf.cc | 14 +++++++++++++- qpdf/qtest/qpdf.test | 14 +++++--------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80560611..d74e9b01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-01-12 Jay Berkenbilt + + * 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 * Add new configure option --enable-avoid-windows-handle, which diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index d30e8ea4..f7c528b7 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -955,6 +955,11 @@ make “” terminates parsing of page selection flags. + + Starting with qpf 8.4, the special input file name + “.” can be used shortcut for the + primary input filename. + 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 infile.pdf while preserving all metadata associated with that file, you could use - qpdf + qpdf If you wanted pages 1 through 5 from infile.pdf but you wanted the rest of the @@ -1087,7 +1092,7 @@ make file1.pdf and pages 11–15 from file2.pdf in reverse, you would run - qpdf + qpdf If, for some reason, you wanted to take the first page of an encrypted file called encrypted.pdf with diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index e7d9eab7..db3193d5 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -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::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 diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index c36b8c95..b45f32a1 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -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"},