Change --single-pages to --split-pages

This is in preparation for implementing page groups.
This commit is contained in:
Jay Berkenbilt 2017-08-12 11:49:04 -04:00
parent ad82706003
commit df33c368b4
54 changed files with 61 additions and 50 deletions

View File

@ -1,3 +1,8 @@
2017-08-12 Jay Berkenbilt <ejb@ql.org>
* Change --single-pages to --split-pages and make it take an
optional argument specifying the number of pages per file.
2017-08-11 Jay Berkenbilt <ejb@ql.org>
* Fix --newline-before-endstream to always add a newline before

View File

@ -350,57 +350,61 @@ make
</listitem>
</varlistentry>
<varlistentry>
<term><option>--single-pages</option></term>
<term><option>--split-pages=[n]</option></term>
<listitem>
<para>
Write each page to a separate output file. Output file names
are generated as follows:
Write each group of <option>n</option> pages to a separate
output file. If <option>n</option> is not specified, create
single pages. Output file names are generated as follows:
<itemizedlist>
<listitem>
<para>
If the string <literal>%d</literal> appears in the output
file name, it is replaced with a zero-padded page number
starting from 1.
file name, it is replaced with a range of zero-padded page
numbers starting from 1.
</para>
</listitem>
<listitem>
<para>
Otherwise, if the output file name ends in
<filename>.pdf</filename> (case insensitive), a zero-padded
page number, preceded by a dash, is inserted before the
file extension.
page range, preceded by a dash, is inserted before the file
extension.
</para>
</listitem>
<listitem>
<para>
Otherwise, the file name is appended with a zero-padded
page number preceded by a dash.
page range preceded by a dash.
</para>
</listitem>
</itemizedlist>
</para>
<para>
Page ranges are a single number in the case of single-page
groups or two numbers separated by a dash otherwise.
For example, if <filename>infile.pdf</filename> has 12 pages
<itemizedlist>
<listitem>
<para>
<command>qpdf infile.pdf %d-out</command> would generate
files <filename>01-out</filename> through
<command>qpdf --split-pages infile.pdf %d-out</command>
would generate files <filename>01-out</filename> through
<filename>12-out</filename>
</para>
</listitem>
<listitem>
<para>
<command>qpdf infile.pdf outfile.pdf
--single-pages</command> would generate files
<filename>outfile-01.pdf</filename> through
<filename>outfile-12.pdf</filename>
<command>qpdf --split-pages=2 infile.pdf
outfile.pdf</command> would generate files
<filename>outfile-01-02.pdf</filename> through
<filename>outfile-11-12.pdf</filename>
</para>
</listitem>
<listitem>
<para>
<command>qpdf infile.pdf something.else</command> would generate
files <filename>something.else-01</filename> through
<command>qpdf --split-pages infile.pdf
something.else</command> would generate files
<filename>something.else-01</filename> through
<filename>something.else-12</filename>
</para>
</listitem>
@ -413,7 +417,7 @@ make
the output into it. If you require the global data, you will
have to run <command>qpdf</command> with the
<option>--pages</option> option once for each file. Using
<option>--single-pages</option> is much faster if you don't
<option>--split-pages</option> is much faster if you don't
require the global data.
</para>
</listitem>

View File

@ -43,7 +43,7 @@ struct Options
password(0),
linearize(false),
decrypt(false),
single_pages(false),
split_pages(false),
copy_encryption(false),
encryption_file(0),
encryption_file_password(0),
@ -98,7 +98,7 @@ struct Options
char const* password;
bool linearize;
bool decrypt;
bool single_pages;
bool split_pages;
bool copy_encryption;
char const* encryption_file;
char const* encryption_file_password;
@ -206,7 +206,7 @@ Basic Options\n\
--encrypt options -- generate an encrypted file\n\
--decrypt remove any encryption on the file\n\
--pages options -- select specific pages from one or more files\n\
--single-pages write each output page to a separate file\n\
--split-pages=[n] write each output page to a separate file\n\
\n\
If none of --copy-encryption, --encrypt or --decrypt are given, qpdf will\n\
preserve any encryption data associated with a file.\n\
@ -216,15 +216,17 @@ parameters will be copied, including both user and owner passwords, even\n\
if the user password is used to open the other file. This works even if\n\
the owner password is not known.\n\
\n\
If --single-pages is specified, each page is written to a separate output\n\
If --split-pages is specified, each page is written to a separate output\n\
file. File names are generated as follows:\n\
* If the string %d appears in the output file name, it is replaced with a\n\
zero-padded page number starting from 1\n\
zero-padded page range starting from 1\n\
* Otherwise, if the output file name ends in .pdf (case insensitive), a\n\
zero-padded page number, preceded by a dash, is inserted before the file\n\
zero-padded page range, preceded by a dash, is inserted before the file\n\
extension\n\
* Otherwise, the file name is appended with a zero-padded page number\n\
* Otherwise, the file name is appended with a zero-padded page range\n\
preceded by a dash.\n\
Page ranges are single page numbers for single-page groups or first-last\n\
for multipage groups.\n\
\n\
\n\
Encryption Options\n\
@ -1334,9 +1336,9 @@ static void parse_options(int argc, char* argv[], Options& o)
}
o.force_version = parameter;
}
else if (strcmp(arg, "single-pages") == 0)
else if (strcmp(arg, "split-pages") == 0)
{
o.single_pages = true;
o.split_pages = true; // XXX
}
else if (strcmp(arg, "deterministic-id") == 0)
{
@ -1451,9 +1453,9 @@ static void parse_options(int argc, char* argv[], Options& o)
}
if (o.require_outfile && (strcmp(o.outfilename, "-") == 0) &&
o.single_pages)
o.split_pages)
{
usage("--single-pages may not be used when writing to standard output");
usage("--split-pages may not be used when writing to standard output");
}
if (QUtil::same_file(o.infilename, o.outfilename))
@ -1977,7 +1979,7 @@ static void set_writer_options(QPDF& pdf, Options& o, QPDFWriter& w)
static void write_outfile(QPDF& pdf, Options& o)
{
if (o.single_pages)
if (o.split_pages)
{
// Generate output file pattern
std::string before;
@ -1986,20 +1988,20 @@ static void write_outfile(QPDF& pdf, Options& o)
char* num_spot = strstr(const_cast<char*>(o.outfilename), "%d");
if (num_spot != 0)
{
QTC::TC("qpdf", "qpdf single-pages %d");
QTC::TC("qpdf", "qpdf split-pages %d");
before = std::string(o.outfilename, (num_spot - o.outfilename));
after = num_spot + 2;
}
else if ((len >= 4) &&
(QUtil::strcasecmp(o.outfilename + len - 4, ".pdf") == 0))
{
QTC::TC("qpdf", "qpdf single-pages .pdf");
QTC::TC("qpdf", "qpdf split-pages .pdf");
before = std::string(o.outfilename, len - 4) + "-";
after = o.outfilename + len - 4;
}
else
{
QTC::TC("qpdf", "qpdf single-pages other");
QTC::TC("qpdf", "qpdf split-pages other");
before = std::string(o.outfilename) + "-";
}

View File

@ -285,9 +285,9 @@ QPDF stream with non-space 0
qpdf same file error 0
qpdf read args from stdin 0
qpdf read args from file 0
qpdf single-pages %d 0
qpdf single-pages .pdf 0
qpdf single-pages other 0
qpdf split-pages %d 0
qpdf split-pages .pdf 0
qpdf split-pages other 0
QPDFTokenizer allowing bad token 0
QPDF ignore first space in xref entry 0
QPDF ignore first extra space in xref entry 0

View File

@ -713,14 +713,14 @@ foreach my $d (
}
show_ntests();
# ----------
$td->notify("--- Single Page ---");
# sp = single-pages
$td->notify("--- Split Pages ---"); # XXXX
# sp = split-pages
my @sp_cases = (
[11, '%d at beginning', '', '%d_single-out.zdf'],
[11, '%d at end', '--qdf', 'single-out.zdf_%d'],
[11, '%d in middle', '--encrypt u o 128 --', 'a-%d-single-out.zdf'],
[11, 'pdf extension', '', 'single-out.Pdf'],
[4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'single-out'],
[11, '%d at beginning', '', '%d_split-out.zdf'],
[11, '%d at end', '--qdf', 'split-out.zdf_%d'],
[11, '%d in middle', '--encrypt u o 128 --', 'a-%d-split-out.zdf'],
[11, 'pdf extension', '', 'split-out.Pdf'],
[4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'split-out'],
);
$n_tests += 1;
for (@sp_cases)
@ -728,17 +728,17 @@ for (@sp_cases)
$n_tests += 1 + $_->[0];
}
$td->runtest("no single-pages to stdout",
{$td->COMMAND => "qpdf --single-pages 11-pages.pdf -"},
{$td->FILE => "single-pages-stdout.out", $td->EXIT_STATUS => 2},
$td->runtest("no split-pages to stdout",
{$td->COMMAND => "qpdf --split-pages 11-pages.pdf -"},
{$td->FILE => "split-pages-stdout.out", $td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
foreach my $d (@sp_cases)
{
my ($n, $description, $xargs, $out) = @$d;
$td->runtest("single pages " . $description,
$td->runtest("split pages " . $description,
{$td->COMMAND =>
"qpdf --static-id --single-pages 11-pages.pdf" .
"qpdf --static-id --split-pages 11-pages.pdf" .
" $xargs $out"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
my $pattern = $out;
@ -759,7 +759,7 @@ foreach my $d (@sp_cases)
{
my $actual = sprintf($pattern, $i);
my $expected = $actual;
$expected =~ s/single-out/single-exp/;
$expected =~ s/split-out/split-exp/;
$td->runtest("checkout output page $i",
{$td->FILE => $actual},
{$td->FILE => $expected});
@ -2497,5 +2497,5 @@ sub get_md5_checksum
sub cleanup
{
system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
system("rm -rf *single-out*");
system("rm -rf *split-out*");
}

View File

@ -1,5 +1,5 @@
qpdf: --single-pages may not be used when writing to standard output
qpdf: --split-pages may not be used when writing to standard output
Usage: qpdf [options] infile outfile
For detailed help, run qpdf --help