aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/merge-and-split.test
blob: 33935e71058c1d409ec31ccff36efb125840dc27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('merge-and-split');

my $n_tests = 28;

# Select pages from the same file multiple times including selecting
# twice from an encrypted file and specifying the password only the
# first time.  The file 20-pages.pdf is specified with two different
# paths to duplicate a page.
my $pages_options = "--pages page-labels-and-outlines.pdf 1,3,5-7,z" .
    " --file=20-pages.pdf --range=z-15 --password=user" .
    " page-labels-and-outlines.pdf --range=12" .
    " --file=20-pages.pdf 10" .
    " ./20-pages.pdf --password=owner 10" .
    " minimal.pdf 1 --";

$td->runtest("merge three files",
             {$td->COMMAND => "qpdf page-labels-and-outlines.pdf a.pdf" .
                  " $pages_options --static-id --verbose --progress",
                  $td->FILTER => "perl filter-progress.pl"},
             {$td->FILE => "verbose-merge.out", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
# Manually verified about this file: make sure that outline entries
# that pointed to pages that were preserved still work in the copy,
# and verify that all pages are as expected.  page-labels-and-outlines
# as well as 20-pages have text on page n (from 1) that shows its page
# position from 0, so page 1 says it's page 0.
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf merge-three-files-1.pdf"},
             {$td->FILE => "merge-three-files-1.pdf", $td->EXIT_STATUS => 0});
# Select the same pages but add them to an empty file
$td->runtest("merge three files",
             {$td->COMMAND => "qpdf --empty a.pdf" .
                  " $pages_options --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
# Manually verified about this file: it has the same pages but does
# not contain outlines or other things from the original file.
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf merge-three-files-2.pdf"},
             {$td->FILE => "merge-three-files-2.pdf", $td->EXIT_STATUS => 0});
$td->runtest("avoid respecification of password",
             {$td->COMMAND =>
                  "qpdf --empty a.pdf --copy-encryption=20-pages.pdf" .
                  " --allow-weak-crypto" .
                  " --encryption-file-password=user" .
                  " --pages 20-pages.pdf 1,z -- --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "pages-copy-encryption.pdf"});
$td->runtest("merge with implicit ranges",
             {$td->COMMAND =>
                  "qpdf --empty a.pdf" .
                  " --pages minimal.pdf 20-pages.pdf --password=user" .
                  " page-labels-and-outlines.pdf --" .
                  " --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf merge-implicit-ranges.pdf"},
             {$td->FILE => "merge-implicit-ranges.pdf", $td->EXIT_STATUS => 0});
$td->runtest("merge with . and implicit ranges",
             {$td->COMMAND =>
                  "qpdf minimal.pdf a.pdf --pages minimal.pdf . 1 --" .
                  " --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf merge-dot-implicit-ranges.pdf"},
             {$td->FILE => "merge-dot-implicit-ranges.pdf", $td->EXIT_STATUS => 0});
$td->runtest("merge with multiple labels",
             {$td->COMMAND =>
                  "qpdf --empty a.pdf" .
                  " --pages 11-pages-with-labels.pdf 8-11" .
                  " minimal.pdf " .
                  " page-labels-and-outlines.pdf 17-19 --" .
                  " --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf merge-multiple-labels.pdf"},
             {$td->FILE => "merge-multiple-labels.pdf", $td->EXIT_STATUS => 0});
$td->runtest("remove labels",
             {$td->COMMAND =>
                  "qpdf --empty a.pdf" .
                  " --remove-page-labels" .
                  " --pages 11-pages-with-labels.pdf 8-11" .
                  " minimal.pdf " .
                  " page-labels-and-outlines.pdf 17-19 --" .
                  " --static-id"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf remove-labels.pdf"},
             {$td->FILE => "remove-labels.pdf", $td->EXIT_STATUS => 0});

$td->runtest("split with shared resources",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id" .
                  " --remove-unreferenced-resources=yes" .
                  " shared-images.pdf --pages . 1,3" .
                  " ./shared-images.pdf 1,2 -- a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "shared-images-pages-out.pdf"});

$td->runtest("split with really shared resources",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id" .
                  " --remove-unreferenced-resources=yes" .
                  " shared-images.pdf --pages . 1,3" .
                  " . 1,2 -- a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "really-shared-images-pages-out.pdf"});

$td->runtest("shared resources relevant errors",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id" .
                  " shared-images-errors.pdf --pages . 2 -- a.pdf"},
             {$td->FILE => "shared-images-errors-2.out",
                  $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "shared-images-errors-2-out.pdf"});

# This test used to generate warnings about images on pages we didn't
# care about, but qpdf was modified not to process those pages, so the
# "irrelevant" errors went away.
$td->runtest("shared resources irrelevant errors",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id" .
                  " shared-images-errors.pdf --pages . 1 -- a.pdf"},
             {$td->STRING => "",
                  $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "shared-images-errors-1-out.pdf"});

$td->runtest("don't remove shared resources",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id --preserve-unreferenced-resources" .
                  " shared-images.pdf --pages . 1,3 -- a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "shared-images-errors-1-3-out.pdf"});

$td->runtest("duplicate pages",
             {$td->COMMAND =>
                  "qpdf --qdf --static-id 11-pages-with-labels.pdf" .
                  " --pages . 6,5,6 . 5 minimal.pdf 1,1 minimal.pdf 1 --" .
                  " a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "duplicate-pages.pdf"});

# See https://github.com/qpdf/qpdf/issues/399 -- we don't want to
# break this, especially if we ever implement deduplication of
# identical streams.
$td->runtest("force full page duplication",
             {$td->COMMAND => "qpdf --static-id minimal.pdf" .
                  " --pages . ./minimal.pdf -- a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare a.pdf deep-duplicate-pages.pdf"},
             {$td->FILE => "deep-duplicate-pages.pdf", $td->EXIT_STATUS => 0});


cleanup();
$td->report($n_tests);