Commit df33c368b472b6e2c2f011fc111c637b3dfca720

Authored by Jay Berkenbilt
1 parent ad827060

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

This is in preparation for implementing page groups.
Showing 55 changed files with 66 additions and 55 deletions
ChangeLog
  1 +2017-08-12 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * Change --single-pages to --split-pages and make it take an
  4 + optional argument specifying the number of pages per file.
  5 +
1 6 2017-08-11 Jay Berkenbilt <ejb@ql.org>
2 7  
3 8 * Fix --newline-before-endstream to always add a newline before
... ...
manual/qpdf-manual.xml
... ... @@ -350,57 +350,61 @@ make
350 350 </listitem>
351 351 </varlistentry>
352 352 <varlistentry>
353   - <term><option>--single-pages</option></term>
  353 + <term><option>--split-pages=[n]</option></term>
354 354 <listitem>
355 355 <para>
356   - Write each page to a separate output file. Output file names
357   - are generated as follows:
  356 + Write each group of <option>n</option> pages to a separate
  357 + output file. If <option>n</option> is not specified, create
  358 + single pages. Output file names are generated as follows:
358 359 <itemizedlist>
359 360 <listitem>
360 361 <para>
361 362 If the string <literal>%d</literal> appears in the output
362   - file name, it is replaced with a zero-padded page number
363   - starting from 1.
  363 + file name, it is replaced with a range of zero-padded page
  364 + numbers starting from 1.
364 365 </para>
365 366 </listitem>
366 367 <listitem>
367 368 <para>
368 369 Otherwise, if the output file name ends in
369 370 <filename>.pdf</filename> (case insensitive), a zero-padded
370   - page number, preceded by a dash, is inserted before the
371   - file extension.
  371 + page range, preceded by a dash, is inserted before the file
  372 + extension.
372 373 </para>
373 374 </listitem>
374 375 <listitem>
375 376 <para>
376 377 Otherwise, the file name is appended with a zero-padded
377   - page number preceded by a dash.
  378 + page range preceded by a dash.
378 379 </para>
379 380 </listitem>
380 381 </itemizedlist>
381 382 </para>
382 383 <para>
  384 + Page ranges are a single number in the case of single-page
  385 + groups or two numbers separated by a dash otherwise.
383 386 For example, if <filename>infile.pdf</filename> has 12 pages
384 387 <itemizedlist>
385 388 <listitem>
386 389 <para>
387   - <command>qpdf infile.pdf %d-out</command> would generate
388   - files <filename>01-out</filename> through
  390 + <command>qpdf --split-pages infile.pdf %d-out</command>
  391 + would generate files <filename>01-out</filename> through
389 392 <filename>12-out</filename>
390 393 </para>
391 394 </listitem>
392 395 <listitem>
393 396 <para>
394   - <command>qpdf infile.pdf outfile.pdf
395   - --single-pages</command> would generate files
396   - <filename>outfile-01.pdf</filename> through
397   - <filename>outfile-12.pdf</filename>
  397 + <command>qpdf --split-pages=2 infile.pdf
  398 + outfile.pdf</command> would generate files
  399 + <filename>outfile-01-02.pdf</filename> through
  400 + <filename>outfile-11-12.pdf</filename>
398 401 </para>
399 402 </listitem>
400 403 <listitem>
401 404 <para>
402   - <command>qpdf infile.pdf something.else</command> would generate
403   - files <filename>something.else-01</filename> through
  405 + <command>qpdf --split-pages infile.pdf
  406 + something.else</command> would generate files
  407 + <filename>something.else-01</filename> through
404 408 <filename>something.else-12</filename>
405 409 </para>
406 410 </listitem>
... ... @@ -413,7 +417,7 @@ make
413 417 the output into it. If you require the global data, you will
414 418 have to run <command>qpdf</command> with the
415 419 <option>--pages</option> option once for each file. Using
416   - <option>--single-pages</option> is much faster if you don't
  420 + <option>--split-pages</option> is much faster if you don't
417 421 require the global data.
418 422 </para>
419 423 </listitem>
... ...
qpdf/qpdf.cc
... ... @@ -43,7 +43,7 @@ struct Options
43 43 password(0),
44 44 linearize(false),
45 45 decrypt(false),
46   - single_pages(false),
  46 + split_pages(false),
47 47 copy_encryption(false),
48 48 encryption_file(0),
49 49 encryption_file_password(0),
... ... @@ -98,7 +98,7 @@ struct Options
98 98 char const* password;
99 99 bool linearize;
100 100 bool decrypt;
101   - bool single_pages;
  101 + bool split_pages;
102 102 bool copy_encryption;
103 103 char const* encryption_file;
104 104 char const* encryption_file_password;
... ... @@ -206,7 +206,7 @@ Basic Options\n\
206 206 --encrypt options -- generate an encrypted file\n\
207 207 --decrypt remove any encryption on the file\n\
208 208 --pages options -- select specific pages from one or more files\n\
209   ---single-pages write each output page to a separate file\n\
  209 +--split-pages=[n] write each output page to a separate file\n\
210 210 \n\
211 211 If none of --copy-encryption, --encrypt or --decrypt are given, qpdf will\n\
212 212 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\
216 216 if the user password is used to open the other file. This works even if\n\
217 217 the owner password is not known.\n\
218 218 \n\
219   -If --single-pages is specified, each page is written to a separate output\n\
  219 +If --split-pages is specified, each page is written to a separate output\n\
220 220 file. File names are generated as follows:\n\
221 221 * If the string %d appears in the output file name, it is replaced with a\n\
222   - zero-padded page number starting from 1\n\
  222 + zero-padded page range starting from 1\n\
223 223 * Otherwise, if the output file name ends in .pdf (case insensitive), a\n\
224   - zero-padded page number, preceded by a dash, is inserted before the file\n\
  224 + zero-padded page range, preceded by a dash, is inserted before the file\n\
225 225 extension\n\
226   -* Otherwise, the file name is appended with a zero-padded page number\n\
  226 +* Otherwise, the file name is appended with a zero-padded page range\n\
227 227 preceded by a dash.\n\
  228 +Page ranges are single page numbers for single-page groups or first-last\n\
  229 +for multipage groups.\n\
228 230 \n\
229 231 \n\
230 232 Encryption Options\n\
... ... @@ -1334,9 +1336,9 @@ static void parse_options(int argc, char* argv[], Options&amp; o)
1334 1336 }
1335 1337 o.force_version = parameter;
1336 1338 }
1337   - else if (strcmp(arg, "single-pages") == 0)
  1339 + else if (strcmp(arg, "split-pages") == 0)
1338 1340 {
1339   - o.single_pages = true;
  1341 + o.split_pages = true; // XXX
1340 1342 }
1341 1343 else if (strcmp(arg, "deterministic-id") == 0)
1342 1344 {
... ... @@ -1451,9 +1453,9 @@ static void parse_options(int argc, char* argv[], Options&amp; o)
1451 1453 }
1452 1454  
1453 1455 if (o.require_outfile && (strcmp(o.outfilename, "-") == 0) &&
1454   - o.single_pages)
  1456 + o.split_pages)
1455 1457 {
1456   - usage("--single-pages may not be used when writing to standard output");
  1458 + usage("--split-pages may not be used when writing to standard output");
1457 1459 }
1458 1460  
1459 1461 if (QUtil::same_file(o.infilename, o.outfilename))
... ... @@ -1977,7 +1979,7 @@ static void set_writer_options(QPDF&amp; pdf, Options&amp; o, QPDFWriter&amp; w)
1977 1979  
1978 1980 static void write_outfile(QPDF& pdf, Options& o)
1979 1981 {
1980   - if (o.single_pages)
  1982 + if (o.split_pages)
1981 1983 {
1982 1984 // Generate output file pattern
1983 1985 std::string before;
... ... @@ -1986,20 +1988,20 @@ static void write_outfile(QPDF&amp; pdf, Options&amp; o)
1986 1988 char* num_spot = strstr(const_cast<char*>(o.outfilename), "%d");
1987 1989 if (num_spot != 0)
1988 1990 {
1989   - QTC::TC("qpdf", "qpdf single-pages %d");
  1991 + QTC::TC("qpdf", "qpdf split-pages %d");
1990 1992 before = std::string(o.outfilename, (num_spot - o.outfilename));
1991 1993 after = num_spot + 2;
1992 1994 }
1993 1995 else if ((len >= 4) &&
1994 1996 (QUtil::strcasecmp(o.outfilename + len - 4, ".pdf") == 0))
1995 1997 {
1996   - QTC::TC("qpdf", "qpdf single-pages .pdf");
  1998 + QTC::TC("qpdf", "qpdf split-pages .pdf");
1997 1999 before = std::string(o.outfilename, len - 4) + "-";
1998 2000 after = o.outfilename + len - 4;
1999 2001 }
2000 2002 else
2001 2003 {
2002   - QTC::TC("qpdf", "qpdf single-pages other");
  2004 + QTC::TC("qpdf", "qpdf split-pages other");
2003 2005 before = std::string(o.outfilename) + "-";
2004 2006 }
2005 2007  
... ...
qpdf/qpdf.testcov
... ... @@ -285,9 +285,9 @@ QPDF stream with non-space 0
285 285 qpdf same file error 0
286 286 qpdf read args from stdin 0
287 287 qpdf read args from file 0
288   -qpdf single-pages %d 0
289   -qpdf single-pages .pdf 0
290   -qpdf single-pages other 0
  288 +qpdf split-pages %d 0
  289 +qpdf split-pages .pdf 0
  290 +qpdf split-pages other 0
291 291 QPDFTokenizer allowing bad token 0
292 292 QPDF ignore first space in xref entry 0
293 293 QPDF ignore first extra space in xref entry 0
... ...
qpdf/qtest/qpdf.test
... ... @@ -713,14 +713,14 @@ foreach my $d (
713 713 }
714 714 show_ntests();
715 715 # ----------
716   -$td->notify("--- Single Page ---");
717   -# sp = single-pages
  716 +$td->notify("--- Split Pages ---"); # XXXX
  717 +# sp = split-pages
718 718 my @sp_cases = (
719   - [11, '%d at beginning', '', '%d_single-out.zdf'],
720   - [11, '%d at end', '--qdf', 'single-out.zdf_%d'],
721   - [11, '%d in middle', '--encrypt u o 128 --', 'a-%d-single-out.zdf'],
722   - [11, 'pdf extension', '', 'single-out.Pdf'],
723   - [4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'single-out'],
  719 + [11, '%d at beginning', '', '%d_split-out.zdf'],
  720 + [11, '%d at end', '--qdf', 'split-out.zdf_%d'],
  721 + [11, '%d in middle', '--encrypt u o 128 --', 'a-%d-split-out.zdf'],
  722 + [11, 'pdf extension', '', 'split-out.Pdf'],
  723 + [4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'split-out'],
724 724 );
725 725 $n_tests += 1;
726 726 for (@sp_cases)
... ... @@ -728,17 +728,17 @@ for (@sp_cases)
728 728 $n_tests += 1 + $_->[0];
729 729 }
730 730  
731   -$td->runtest("no single-pages to stdout",
732   - {$td->COMMAND => "qpdf --single-pages 11-pages.pdf -"},
733   - {$td->FILE => "single-pages-stdout.out", $td->EXIT_STATUS => 2},
  731 +$td->runtest("no split-pages to stdout",
  732 + {$td->COMMAND => "qpdf --split-pages 11-pages.pdf -"},
  733 + {$td->FILE => "split-pages-stdout.out", $td->EXIT_STATUS => 2},
734 734 $td->NORMALIZE_NEWLINES);
735 735  
736 736 foreach my $d (@sp_cases)
737 737 {
738 738 my ($n, $description, $xargs, $out) = @$d;
739   - $td->runtest("single pages " . $description,
  739 + $td->runtest("split pages " . $description,
740 740 {$td->COMMAND =>
741   - "qpdf --static-id --single-pages 11-pages.pdf" .
  741 + "qpdf --static-id --split-pages 11-pages.pdf" .
742 742 " $xargs $out"},
743 743 {$td->STRING => "", $td->EXIT_STATUS => 0});
744 744 my $pattern = $out;
... ... @@ -759,7 +759,7 @@ foreach my $d (@sp_cases)
759 759 {
760 760 my $actual = sprintf($pattern, $i);
761 761 my $expected = $actual;
762   - $expected =~ s/single-out/single-exp/;
  762 + $expected =~ s/split-out/split-exp/;
763 763 $td->runtest("checkout output page $i",
764 764 {$td->FILE => $actual},
765 765 {$td->FILE => $expected});
... ... @@ -2497,5 +2497,5 @@ sub get_md5_checksum
2497 2497 sub cleanup
2498 2498 {
2499 2499 system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
2500   - system("rm -rf *single-out*");
  2500 + system("rm -rf *split-out*");
2501 2501 }
... ...
qpdf/qtest/qpdf/01_single-exp.zdf renamed to qpdf/qtest/qpdf/01_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/02_single-exp.zdf renamed to qpdf/qtest/qpdf/02_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/03_single-exp.zdf renamed to qpdf/qtest/qpdf/03_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/04_single-exp.zdf renamed to qpdf/qtest/qpdf/04_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/05_single-exp.zdf renamed to qpdf/qtest/qpdf/05_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/06_single-exp.zdf renamed to qpdf/qtest/qpdf/06_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/07_single-exp.zdf renamed to qpdf/qtest/qpdf/07_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/08_single-exp.zdf renamed to qpdf/qtest/qpdf/08_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/09_single-exp.zdf renamed to qpdf/qtest/qpdf/09_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/10_single-exp.zdf renamed to qpdf/qtest/qpdf/10_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/11_single-exp.zdf renamed to qpdf/qtest/qpdf/11_split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-01-single-exp.zdf renamed to qpdf/qtest/qpdf/a-01-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-02-single-exp.zdf renamed to qpdf/qtest/qpdf/a-02-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-03-single-exp.zdf renamed to qpdf/qtest/qpdf/a-03-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-04-single-exp.zdf renamed to qpdf/qtest/qpdf/a-04-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-05-single-exp.zdf renamed to qpdf/qtest/qpdf/a-05-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-06-single-exp.zdf renamed to qpdf/qtest/qpdf/a-06-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-07-single-exp.zdf renamed to qpdf/qtest/qpdf/a-07-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-08-single-exp.zdf renamed to qpdf/qtest/qpdf/a-08-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-09-single-exp.zdf renamed to qpdf/qtest/qpdf/a-09-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-10-single-exp.zdf renamed to qpdf/qtest/qpdf/a-10-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/a-11-single-exp.zdf renamed to qpdf/qtest/qpdf/a-11-split-exp.zdf
No preview for this file type
qpdf/qtest/qpdf/single-pages-stdout.out deleted
1   -
2   -qpdf: --single-pages may not be used when writing to standard output
3   -
4   -Usage: qpdf [options] infile outfile
5   -For detailed help, run qpdf --help
6   -
qpdf/qtest/qpdf/single-exp-01.Pdf renamed to qpdf/qtest/qpdf/split-exp-01.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-02.Pdf renamed to qpdf/qtest/qpdf/split-exp-02.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-03.Pdf renamed to qpdf/qtest/qpdf/split-exp-03.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-04.Pdf renamed to qpdf/qtest/qpdf/split-exp-04.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-05.Pdf renamed to qpdf/qtest/qpdf/split-exp-05.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-06.Pdf renamed to qpdf/qtest/qpdf/split-exp-06.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-07.Pdf renamed to qpdf/qtest/qpdf/split-exp-07.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-08.Pdf renamed to qpdf/qtest/qpdf/split-exp-08.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-09.Pdf renamed to qpdf/qtest/qpdf/split-exp-09.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-1 renamed to qpdf/qtest/qpdf/split-exp-1
No preview for this file type
qpdf/qtest/qpdf/single-exp-10.Pdf renamed to qpdf/qtest/qpdf/split-exp-10.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-11.Pdf renamed to qpdf/qtest/qpdf/split-exp-11.Pdf
No preview for this file type
qpdf/qtest/qpdf/single-exp-2 renamed to qpdf/qtest/qpdf/split-exp-2
No preview for this file type
qpdf/qtest/qpdf/single-exp-3 renamed to qpdf/qtest/qpdf/split-exp-3
No preview for this file type
qpdf/qtest/qpdf/single-exp-4 renamed to qpdf/qtest/qpdf/split-exp-4
No preview for this file type
qpdf/qtest/qpdf/single-exp.zdf_01 renamed to qpdf/qtest/qpdf/split-exp.zdf_01
qpdf/qtest/qpdf/single-exp.zdf_02 renamed to qpdf/qtest/qpdf/split-exp.zdf_02
qpdf/qtest/qpdf/single-exp.zdf_03 renamed to qpdf/qtest/qpdf/split-exp.zdf_03
qpdf/qtest/qpdf/single-exp.zdf_04 renamed to qpdf/qtest/qpdf/split-exp.zdf_04
qpdf/qtest/qpdf/single-exp.zdf_05 renamed to qpdf/qtest/qpdf/split-exp.zdf_05
qpdf/qtest/qpdf/single-exp.zdf_06 renamed to qpdf/qtest/qpdf/split-exp.zdf_06
qpdf/qtest/qpdf/single-exp.zdf_07 renamed to qpdf/qtest/qpdf/split-exp.zdf_07
qpdf/qtest/qpdf/single-exp.zdf_08 renamed to qpdf/qtest/qpdf/split-exp.zdf_08
qpdf/qtest/qpdf/single-exp.zdf_09 renamed to qpdf/qtest/qpdf/split-exp.zdf_09
qpdf/qtest/qpdf/single-exp.zdf_10 renamed to qpdf/qtest/qpdf/split-exp.zdf_10
qpdf/qtest/qpdf/single-exp.zdf_11 renamed to qpdf/qtest/qpdf/split-exp.zdf_11
qpdf/qtest/qpdf/split-pages-stdout.out 0 → 100644
  1 +
  2 +qpdf: --split-pages may not be used when writing to standard output
  3 +
  4 +Usage: qpdf [options] infile outfile
  5 +For detailed help, run qpdf --help
  6 +
... ...