mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-05 08:02:11 +00:00
Change --single-pages to --split-pages
This is in preparation for implementing page groups.
This commit is contained in:
parent
ad82706003
commit
df33c368b4
@ -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>
|
2017-08-11 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* Fix --newline-before-endstream to always add a newline before
|
* Fix --newline-before-endstream to always add a newline before
|
||||||
|
@ -350,57 +350,61 @@ make
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>--single-pages</option></term>
|
<term><option>--split-pages=[n]</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Write each page to a separate output file. Output file names
|
Write each group of <option>n</option> pages to a separate
|
||||||
are generated as follows:
|
output file. If <option>n</option> is not specified, create
|
||||||
|
single pages. Output file names are generated as follows:
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
If the string <literal>%d</literal> appears in the output
|
If the string <literal>%d</literal> appears in the output
|
||||||
file name, it is replaced with a zero-padded page number
|
file name, it is replaced with a range of zero-padded page
|
||||||
starting from 1.
|
numbers starting from 1.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Otherwise, if the output file name ends in
|
Otherwise, if the output file name ends in
|
||||||
<filename>.pdf</filename> (case insensitive), a zero-padded
|
<filename>.pdf</filename> (case insensitive), a zero-padded
|
||||||
page number, preceded by a dash, is inserted before the
|
page range, preceded by a dash, is inserted before the file
|
||||||
file extension.
|
extension.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Otherwise, the file name is appended with a zero-padded
|
Otherwise, the file name is appended with a zero-padded
|
||||||
page number preceded by a dash.
|
page range preceded by a dash.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</para>
|
</para>
|
||||||
<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
|
For example, if <filename>infile.pdf</filename> has 12 pages
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<command>qpdf infile.pdf %d-out</command> would generate
|
<command>qpdf --split-pages infile.pdf %d-out</command>
|
||||||
files <filename>01-out</filename> through
|
would generate files <filename>01-out</filename> through
|
||||||
<filename>12-out</filename>
|
<filename>12-out</filename>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<command>qpdf infile.pdf outfile.pdf
|
<command>qpdf --split-pages=2 infile.pdf
|
||||||
--single-pages</command> would generate files
|
outfile.pdf</command> would generate files
|
||||||
<filename>outfile-01.pdf</filename> through
|
<filename>outfile-01-02.pdf</filename> through
|
||||||
<filename>outfile-12.pdf</filename>
|
<filename>outfile-11-12.pdf</filename>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<command>qpdf infile.pdf something.else</command> would generate
|
<command>qpdf --split-pages infile.pdf
|
||||||
files <filename>something.else-01</filename> through
|
something.else</command> would generate files
|
||||||
|
<filename>something.else-01</filename> through
|
||||||
<filename>something.else-12</filename>
|
<filename>something.else-12</filename>
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
@ -413,7 +417,7 @@ make
|
|||||||
the output into it. If you require the global data, you will
|
the output into it. If you require the global data, you will
|
||||||
have to run <command>qpdf</command> with the
|
have to run <command>qpdf</command> with the
|
||||||
<option>--pages</option> option once for each file. Using
|
<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.
|
require the global data.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
32
qpdf/qpdf.cc
32
qpdf/qpdf.cc
@ -43,7 +43,7 @@ struct Options
|
|||||||
password(0),
|
password(0),
|
||||||
linearize(false),
|
linearize(false),
|
||||||
decrypt(false),
|
decrypt(false),
|
||||||
single_pages(false),
|
split_pages(false),
|
||||||
copy_encryption(false),
|
copy_encryption(false),
|
||||||
encryption_file(0),
|
encryption_file(0),
|
||||||
encryption_file_password(0),
|
encryption_file_password(0),
|
||||||
@ -98,7 +98,7 @@ struct Options
|
|||||||
char const* password;
|
char const* password;
|
||||||
bool linearize;
|
bool linearize;
|
||||||
bool decrypt;
|
bool decrypt;
|
||||||
bool single_pages;
|
bool split_pages;
|
||||||
bool copy_encryption;
|
bool copy_encryption;
|
||||||
char const* encryption_file;
|
char const* encryption_file;
|
||||||
char const* encryption_file_password;
|
char const* encryption_file_password;
|
||||||
@ -206,7 +206,7 @@ Basic Options\n\
|
|||||||
--encrypt options -- generate an encrypted file\n\
|
--encrypt options -- generate an encrypted file\n\
|
||||||
--decrypt remove any encryption on the file\n\
|
--decrypt remove any encryption on the file\n\
|
||||||
--pages options -- select specific pages from one or more files\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\
|
\n\
|
||||||
If none of --copy-encryption, --encrypt or --decrypt are given, qpdf will\n\
|
If none of --copy-encryption, --encrypt or --decrypt are given, qpdf will\n\
|
||||||
preserve any encryption data associated with a file.\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\
|
if the user password is used to open the other file. This works even if\n\
|
||||||
the owner password is not known.\n\
|
the owner password is not known.\n\
|
||||||
\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\
|
file. File names are generated as follows:\n\
|
||||||
* If the string %d appears in the output file name, it is replaced with a\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\
|
* 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\
|
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\
|
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\
|
||||||
\n\
|
\n\
|
||||||
Encryption Options\n\
|
Encryption Options\n\
|
||||||
@ -1334,9 +1336,9 @@ static void parse_options(int argc, char* argv[], Options& o)
|
|||||||
}
|
}
|
||||||
o.force_version = parameter;
|
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)
|
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) &&
|
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))
|
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)
|
static void write_outfile(QPDF& pdf, Options& o)
|
||||||
{
|
{
|
||||||
if (o.single_pages)
|
if (o.split_pages)
|
||||||
{
|
{
|
||||||
// Generate output file pattern
|
// Generate output file pattern
|
||||||
std::string before;
|
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");
|
char* num_spot = strstr(const_cast<char*>(o.outfilename), "%d");
|
||||||
if (num_spot != 0)
|
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));
|
before = std::string(o.outfilename, (num_spot - o.outfilename));
|
||||||
after = num_spot + 2;
|
after = num_spot + 2;
|
||||||
}
|
}
|
||||||
else if ((len >= 4) &&
|
else if ((len >= 4) &&
|
||||||
(QUtil::strcasecmp(o.outfilename + len - 4, ".pdf") == 0))
|
(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) + "-";
|
before = std::string(o.outfilename, len - 4) + "-";
|
||||||
after = o.outfilename + len - 4;
|
after = o.outfilename + len - 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "qpdf single-pages other");
|
QTC::TC("qpdf", "qpdf split-pages other");
|
||||||
before = std::string(o.outfilename) + "-";
|
before = std::string(o.outfilename) + "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,9 +285,9 @@ QPDF stream with non-space 0
|
|||||||
qpdf same file error 0
|
qpdf same file error 0
|
||||||
qpdf read args from stdin 0
|
qpdf read args from stdin 0
|
||||||
qpdf read args from file 0
|
qpdf read args from file 0
|
||||||
qpdf single-pages %d 0
|
qpdf split-pages %d 0
|
||||||
qpdf single-pages .pdf 0
|
qpdf split-pages .pdf 0
|
||||||
qpdf single-pages other 0
|
qpdf split-pages other 0
|
||||||
QPDFTokenizer allowing bad token 0
|
QPDFTokenizer allowing bad token 0
|
||||||
QPDF ignore first space in xref entry 0
|
QPDF ignore first space in xref entry 0
|
||||||
QPDF ignore first extra space in xref entry 0
|
QPDF ignore first extra space in xref entry 0
|
||||||
|
@ -713,14 +713,14 @@ foreach my $d (
|
|||||||
}
|
}
|
||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Single Page ---");
|
$td->notify("--- Split Pages ---"); # XXXX
|
||||||
# sp = single-pages
|
# sp = split-pages
|
||||||
my @sp_cases = (
|
my @sp_cases = (
|
||||||
[11, '%d at beginning', '', '%d_single-out.zdf'],
|
[11, '%d at beginning', '', '%d_split-out.zdf'],
|
||||||
[11, '%d at end', '--qdf', 'single-out.zdf_%d'],
|
[11, '%d at end', '--qdf', 'split-out.zdf_%d'],
|
||||||
[11, '%d in middle', '--encrypt u o 128 --', 'a-%d-single-out.zdf'],
|
[11, '%d in middle', '--encrypt u o 128 --', 'a-%d-split-out.zdf'],
|
||||||
[11, 'pdf extension', '', 'single-out.Pdf'],
|
[11, 'pdf extension', '', 'split-out.Pdf'],
|
||||||
[4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'single-out'],
|
[4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'split-out'],
|
||||||
);
|
);
|
||||||
$n_tests += 1;
|
$n_tests += 1;
|
||||||
for (@sp_cases)
|
for (@sp_cases)
|
||||||
@ -728,17 +728,17 @@ for (@sp_cases)
|
|||||||
$n_tests += 1 + $_->[0];
|
$n_tests += 1 + $_->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$td->runtest("no single-pages to stdout",
|
$td->runtest("no split-pages to stdout",
|
||||||
{$td->COMMAND => "qpdf --single-pages 11-pages.pdf -"},
|
{$td->COMMAND => "qpdf --split-pages 11-pages.pdf -"},
|
||||||
{$td->FILE => "single-pages-stdout.out", $td->EXIT_STATUS => 2},
|
{$td->FILE => "split-pages-stdout.out", $td->EXIT_STATUS => 2},
|
||||||
$td->NORMALIZE_NEWLINES);
|
$td->NORMALIZE_NEWLINES);
|
||||||
|
|
||||||
foreach my $d (@sp_cases)
|
foreach my $d (@sp_cases)
|
||||||
{
|
{
|
||||||
my ($n, $description, $xargs, $out) = @$d;
|
my ($n, $description, $xargs, $out) = @$d;
|
||||||
$td->runtest("single pages " . $description,
|
$td->runtest("split pages " . $description,
|
||||||
{$td->COMMAND =>
|
{$td->COMMAND =>
|
||||||
"qpdf --static-id --single-pages 11-pages.pdf" .
|
"qpdf --static-id --split-pages 11-pages.pdf" .
|
||||||
" $xargs $out"},
|
" $xargs $out"},
|
||||||
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
{$td->STRING => "", $td->EXIT_STATUS => 0});
|
||||||
my $pattern = $out;
|
my $pattern = $out;
|
||||||
@ -759,7 +759,7 @@ foreach my $d (@sp_cases)
|
|||||||
{
|
{
|
||||||
my $actual = sprintf($pattern, $i);
|
my $actual = sprintf($pattern, $i);
|
||||||
my $expected = $actual;
|
my $expected = $actual;
|
||||||
$expected =~ s/single-out/single-exp/;
|
$expected =~ s/split-out/split-exp/;
|
||||||
$td->runtest("checkout output page $i",
|
$td->runtest("checkout output page $i",
|
||||||
{$td->FILE => $actual},
|
{$td->FILE => $actual},
|
||||||
{$td->FILE => $expected});
|
{$td->FILE => $expected});
|
||||||
@ -2497,5 +2497,5 @@ sub get_md5_checksum
|
|||||||
sub cleanup
|
sub cleanup
|
||||||
{
|
{
|
||||||
system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
|
system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
|
||||||
system("rm -rf *single-out*");
|
system("rm -rf *split-out*");
|
||||||
}
|
}
|
||||||
|
@ -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
|
Usage: qpdf [options] infile outfile
|
||||||
For detailed help, run qpdf --help
|
For detailed help, run qpdf --help
|
Loading…
Reference in New Issue
Block a user