Commit 65ef0bf3130b69c8d48181ab27688567535f2d9f

Authored by Jay Berkenbilt
1 parent 85f70cae

When flattening, remove annotations with no appearance stream

With the exception of form field annotations when /NeedAppearances is
true, remove annotations that don't have appearance streams when
flattening. There is no reason to keep these when flattening since
they are invisible. This may include unchecked checkboxes, unshown
popup windows, etc.
ChangeLog
  1 +2019-01-20 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * When flattening annotations, remove annotations from the file
  4 + that don't have appearance streams. These were previously being
  5 + preserved, but since they are invisible, there is no reason to
  6 + preserve them when flattening annotations.
  7 +
1 2019-01-19 Jay Berkenbilt <ejb@ql.org> 8 2019-01-19 Jay Berkenbilt <ejb@ql.org>
2 9
3 * NOTE: qpdf CLI: some non-compatible changes were made to how 10 * NOTE: qpdf CLI: some non-compatible changes were made to how
libqpdf/QPDFPageDocumentHelper.cc
@@ -141,11 +141,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( @@ -141,11 +141,7 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
141 QTC::TC("qpdf", "QPDFPageDocumentHelper skip widget need appearances"); 141 QTC::TC("qpdf", "QPDFPageDocumentHelper skip widget need appearances");
142 process = false; 142 process = false;
143 } 143 }
144 - if (process && (! as.isStream()))  
145 - {  
146 - process = false;  
147 - }  
148 - if (process) 144 + if (process && as.isStream())
149 { 145 {
150 if (is_widget) 146 if (is_widget)
151 { 147 {
@@ -200,6 +196,15 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage( @@ -200,6 +196,15 @@ QPDFPageDocumentHelper::flattenAnnotationsForPage(
200 } 196 }
201 new_content += content; 197 new_content += content;
202 } 198 }
  199 + else if (process)
  200 + {
  201 + // If an annotation has no appearance stream, just drop
  202 + // the annotation when flattening. This can happen for
  203 + // unchecked checkboxes and radio buttons, popup windows
  204 + // associated with comments that aren't visible, and other
  205 + // types of annotations that aren't visible.
  206 + QTC::TC("qpdf", "QPDFPageDocumentHelper ignore annotation with no appearance");
  207 + }
203 else 208 else
204 { 209 {
205 new_annots.push_back(aoh.getObjectHandle()); 210 new_annots.push_back(aoh.getObjectHandle());
qpdf/qpdf.testcov
@@ -421,3 +421,4 @@ qpdf auto-encode password 0 @@ -421,3 +421,4 @@ qpdf auto-encode password 0
421 qpdf bytes fallback warning 0 421 qpdf bytes fallback warning 0
422 qpdf invalid utf-8 in auto 0 422 qpdf invalid utf-8 in auto 0
423 qpdf input password hex-bytes 0 423 qpdf input password hex-bytes 0
  424 +QPDFPageDocumentHelper ignore annotation with no appearance 0
qpdf/qtest/qpdf.test
@@ -1609,6 +1609,7 @@ my @annotation_files = ( @@ -1609,6 +1609,7 @@ my @annotation_files = (
1609 'comment-annotation-direct', 1609 'comment-annotation-direct',
1610 'sample-form', 1610 'sample-form',
1611 'need-appearances', 1611 'need-appearances',
  1612 + 'need-appearances-more',
1612 ); 1613 );
1613 $n_tests += 2 * scalar(@annotation_files); 1614 $n_tests += 2 * scalar(@annotation_files);
1614 1615
qpdf/qtest/qpdf/appearances-a.pdf
No preview for this file type
qpdf/qtest/qpdf/comment-annotation-direct-out.pdf
@@ -22,13 +22,10 @@ endobj @@ -22,13 +22,10 @@ endobj
22 %% Page 1 22 %% Page 1
23 3 0 obj 23 3 0 obj
24 << 24 <<
25 - /Annots [  
26 - 4 0 R  
27 - ]  
28 /Contents [ 25 /Contents [
29 - 5 0 R  
30 - 7 0 R  
31 - 9 0 R 26 + 4 0 R
  27 + 6 0 R
  28 + 8 0 R
32 ] 29 ]
33 /MediaBox [ 30 /MediaBox [
34 0 31 0
@@ -39,51 +36,35 @@ endobj @@ -39,51 +36,35 @@ endobj
39 /Parent 2 0 R 36 /Parent 2 0 R
40 /Resources << 37 /Resources <<
41 /Font << 38 /Font <<
42 - /F1 11 0 R 39 + /F1 10 0 R
43 >> 40 >>
44 - /ProcSet 12 0 R 41 + /ProcSet 11 0 R
45 /XObject << 42 /XObject <<
46 - /Fxo1 13 0 R 43 + /Fxo1 12 0 R
47 >> 44 >>
48 >> 45 >>
49 /Type /Page 46 /Type /Page
50 >> 47 >>
51 endobj 48 endobj
52 49
53 -4 0 obj  
54 -<<  
55 - /F 28  
56 - /Open false  
57 - /Parent 15 0 R  
58 - /Rect [  
59 - 612  
60 - 601  
61 - 792  
62 - 721  
63 - ]  
64 - /Subtype /Popup  
65 - /Type /Annot  
66 ->>  
67 -endobj  
68 -  
69 %% Contents for page 1 50 %% Contents for page 1
70 -5 0 obj 51 +4 0 obj
71 << 52 <<
72 - /Length 6 0 R 53 + /Length 5 0 R
73 >> 54 >>
74 stream 55 stream
75 q 56 q
76 endstream 57 endstream
77 endobj 58 endobj
78 59
79 -6 0 obj 60 +5 0 obj
80 2 61 2
81 endobj 62 endobj
82 63
83 %% Contents for page 1 64 %% Contents for page 1
84 -7 0 obj 65 +6 0 obj
85 << 66 <<
86 - /Length 8 0 R 67 + /Length 7 0 R
87 >> 68 >>
88 stream 69 stream
89 BT 70 BT
@@ -94,14 +75,14 @@ ET @@ -94,14 +75,14 @@ ET
94 endstream 75 endstream
95 endobj 76 endobj
96 77
97 -8 0 obj 78 +7 0 obj
98 44 79 44
99 endobj 80 endobj
100 81
101 %% Contents for page 1 82 %% Contents for page 1
102 -9 0 obj 83 +8 0 obj
103 << 84 <<
104 - /Length 10 0 R 85 + /Length 9 0 R
105 >> 86 >>
106 stream 87 stream
107 88
@@ -113,11 +94,11 @@ Q @@ -113,11 +94,11 @@ Q
113 endstream 94 endstream
114 endobj 95 endobj
115 96
116 -10 0 obj 97 +9 0 obj
117 71 98 71
118 endobj 99 endobj
119 100
120 -11 0 obj 101 +10 0 obj
121 << 102 <<
122 /BaseFont /Helvetica 103 /BaseFont /Helvetica
123 /Encoding /WinAnsiEncoding 104 /Encoding /WinAnsiEncoding
@@ -127,14 +108,14 @@ endobj @@ -127,14 +108,14 @@ endobj
127 >> 108 >>
128 endobj 109 endobj
129 110
130 -12 0 obj 111 +11 0 obj
131 [ 112 [
132 /PDF 113 /PDF
133 /Text 114 /Text
134 ] 115 ]
135 endobj 116 endobj
136 117
137 -13 0 obj 118 +12 0 obj
138 << 119 <<
139 /BBox [ 120 /BBox [
140 0 121 0
@@ -155,7 +136,7 @@ endobj @@ -155,7 +136,7 @@ endobj
155 >> 136 >>
156 /Subtype /Form 137 /Subtype /Form
157 /Type /XObject 138 /Type /XObject
158 - /Length 14 0 R 139 + /Length 13 0 R
159 >> 140 >>
160 stream 141 stream
161 q 1 1 1 rg 0 i 1 w 4 M 1 j 0 J []0 d /GS0 gs 1 0 0 1 9 5.0908 cm 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c h f Q 0 G 1 1 0 rg 0 i 0.60 w 4 M 1 j 0 J []0 d 1 1 0 rg 0 G 0 i 0.59 w 4 M 1 j 0 J []0 d 1 0 0 1 9 5.0908 cm 0 0 m -0.142 0 -0.28 0.008 -0.418 0.015 c -2.199 -1.969 -5.555 -2.242 -4.642 -1.42 c -4.024 -0.862 -3.916 0.111 -3.954 0.916 c -5.658 1.795 -6.772 3.222 -6.772 4.839 c -6.772 7.509 -3.74 9.674 0 9.674 c 3.74 9.674 6.772 7.509 6.772 4.839 c 6.772 2.167 3.74 0 0 0 c 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c b 142 q 1 1 1 rg 0 i 1 w 4 M 1 j 0 J []0 d /GS0 gs 1 0 0 1 9 5.0908 cm 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c h f Q 0 G 1 1 0 rg 0 i 0.60 w 4 M 1 j 0 J []0 d 1 1 0 rg 0 G 0 i 0.59 w 4 M 1 j 0 J []0 d 1 0 0 1 9 5.0908 cm 0 0 m -0.142 0 -0.28 0.008 -0.418 0.015 c -2.199 -1.969 -5.555 -2.242 -4.642 -1.42 c -4.024 -0.862 -3.916 0.111 -3.954 0.916 c -5.658 1.795 -6.772 3.222 -6.772 4.839 c -6.772 7.509 -3.74 9.674 0 9.674 c 3.74 9.674 6.772 7.509 6.772 4.839 c 6.772 2.167 3.74 0 0 0 c 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c b
@@ -163,63 +144,31 @@ endstream @@ -163,63 +144,31 @@ endstream
163 endobj 144 endobj
164 145
165 %QDF: ignore_newline 146 %QDF: ignore_newline
166 -14 0 obj 147 +13 0 obj
167 928 148 928
168 endobj 149 endobj
169 150
170 -15 0 obj  
171 -<<  
172 - /AP <<  
173 - /N 13 0 R  
174 - >>  
175 - /C [  
176 - 1  
177 - 1  
178 - 0  
179 - ]  
180 - /CA 1  
181 - /Contents (Salad)  
182 - /CreationDate (D:20181231235455Z00'00)  
183 - /F 28  
184 - /M (D:20181231235455Z00'00)  
185 - /Name /Comment  
186 - /P 3 0 R  
187 - /Popup 4 0 R  
188 - /Rect [  
189 - 235  
190 - 703  
191 - 253  
192 - 721  
193 - ]  
194 - /Subtype /Text  
195 - /T (Jay Berkenbilt)  
196 - /Type /Annot  
197 ->>  
198 -endobj  
199 -  
200 xref 151 xref
201 -0 16 152 +0 14
202 0000000000 65535 f 153 0000000000 65535 f
203 0000000025 00000 n 154 0000000025 00000 n
204 0000000079 00000 n 155 0000000079 00000 n
205 0000000161 00000 n 156 0000000161 00000 n
206 -0000000453 00000 n  
207 -0000000616 00000 n  
208 -0000000673 00000 n  
209 -0000000714 00000 n  
210 -0000000813 00000 n  
211 -0000000855 00000 n  
212 -0000000982 00000 n  
213 -0000001002 00000 n  
214 -0000001121 00000 n  
215 -0000001157 00000 n  
216 -0000002401 00000 n  
217 -0000002422 00000 n 157 +0000000450 00000 n
  158 +0000000507 00000 n
  159 +0000000548 00000 n
  160 +0000000647 00000 n
  161 +0000000689 00000 n
  162 +0000000815 00000 n
  163 +0000000834 00000 n
  164 +0000000953 00000 n
  165 +0000000989 00000 n
  166 +0000002233 00000 n
218 trailer << 167 trailer <<
219 /Root 1 0 R 168 /Root 1 0 R
220 - /Size 16 169 + /Size 14
221 /ID [<c5b1999a07a3fdcd0c04cfeed299c25a><31415926535897932384626433832795>] 170 /ID [<c5b1999a07a3fdcd0c04cfeed299c25a><31415926535897932384626433832795>]
222 >> 171 >>
223 startxref 172 startxref
224 -2752 173 +2254
225 %%EOF 174 %%EOF
qpdf/qtest/qpdf/comment-annotation-out.pdf
@@ -22,11 +22,10 @@ endobj @@ -22,11 +22,10 @@ endobj
22 %% Page 1 22 %% Page 1
23 3 0 obj 23 3 0 obj
24 << 24 <<
25 - /Annots 4 0 R  
26 /Contents [ 25 /Contents [
27 - 5 0 R  
28 - 7 0 R  
29 - 9 0 R 26 + 4 0 R
  27 + 6 0 R
  28 + 8 0 R
30 ] 29 ]
31 /MediaBox [ 30 /MediaBox [
32 0 31 0
@@ -37,41 +36,35 @@ endobj @@ -37,41 +36,35 @@ endobj
37 /Parent 2 0 R 36 /Parent 2 0 R
38 /Resources << 37 /Resources <<
39 /Font << 38 /Font <<
40 - /F1 11 0 R 39 + /F1 10 0 R
41 >> 40 >>
42 - /ProcSet 12 0 R 41 + /ProcSet 11 0 R
43 /XObject << 42 /XObject <<
44 - /Fxo1 13 0 R 43 + /Fxo1 12 0 R
45 >> 44 >>
46 >> 45 >>
47 /Type /Page 46 /Type /Page
48 >> 47 >>
49 endobj 48 endobj
50 49
51 -4 0 obj  
52 -[  
53 - 15 0 R  
54 -]  
55 -endobj  
56 -  
57 %% Contents for page 1 50 %% Contents for page 1
58 -5 0 obj 51 +4 0 obj
59 << 52 <<
60 - /Length 6 0 R 53 + /Length 5 0 R
61 >> 54 >>
62 stream 55 stream
63 q 56 q
64 endstream 57 endstream
65 endobj 58 endobj
66 59
67 -6 0 obj 60 +5 0 obj
68 2 61 2
69 endobj 62 endobj
70 63
71 %% Contents for page 1 64 %% Contents for page 1
72 -7 0 obj 65 +6 0 obj
73 << 66 <<
74 - /Length 8 0 R 67 + /Length 7 0 R
75 >> 68 >>
76 stream 69 stream
77 BT 70 BT
@@ -82,14 +75,14 @@ ET @@ -82,14 +75,14 @@ ET
82 endstream 75 endstream
83 endobj 76 endobj
84 77
85 -8 0 obj 78 +7 0 obj
86 44 79 44
87 endobj 80 endobj
88 81
89 %% Contents for page 1 82 %% Contents for page 1
90 -9 0 obj 83 +8 0 obj
91 << 84 <<
92 - /Length 10 0 R 85 + /Length 9 0 R
93 >> 86 >>
94 stream 87 stream
95 88
@@ -101,11 +94,11 @@ Q @@ -101,11 +94,11 @@ Q
101 endstream 94 endstream
102 endobj 95 endobj
103 96
104 -10 0 obj 97 +9 0 obj
105 71 98 71
106 endobj 99 endobj
107 100
108 -11 0 obj 101 +10 0 obj
109 << 102 <<
110 /BaseFont /Helvetica 103 /BaseFont /Helvetica
111 /Encoding /WinAnsiEncoding 104 /Encoding /WinAnsiEncoding
@@ -115,14 +108,14 @@ endobj @@ -115,14 +108,14 @@ endobj
115 >> 108 >>
116 endobj 109 endobj
117 110
118 -12 0 obj 111 +11 0 obj
119 [ 112 [
120 /PDF 113 /PDF
121 /Text 114 /Text
122 ] 115 ]
123 endobj 116 endobj
124 117
125 -13 0 obj 118 +12 0 obj
126 << 119 <<
127 /BBox [ 120 /BBox [
128 0 121 0
@@ -143,7 +136,7 @@ endobj @@ -143,7 +136,7 @@ endobj
143 >> 136 >>
144 /Subtype /Form 137 /Subtype /Form
145 /Type /XObject 138 /Type /XObject
146 - /Length 14 0 R 139 + /Length 13 0 R
147 >> 140 >>
148 stream 141 stream
149 q 1 1 1 rg 0 i 1 w 4 M 1 j 0 J []0 d /GS0 gs 1 0 0 1 9 5.0908 cm 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c h f Q 0 G 1 1 0 rg 0 i 0.60 w 4 M 1 j 0 J []0 d 1 1 0 rg 0 G 0 i 0.59 w 4 M 1 j 0 J []0 d 1 0 0 1 9 5.0908 cm 0 0 m -0.142 0 -0.28 0.008 -0.418 0.015 c -2.199 -1.969 -5.555 -2.242 -4.642 -1.42 c -4.024 -0.862 -3.916 0.111 -3.954 0.916 c -5.658 1.795 -6.772 3.222 -6.772 4.839 c -6.772 7.509 -3.74 9.674 0 9.674 c 3.74 9.674 6.772 7.509 6.772 4.839 c 6.772 2.167 3.74 0 0 0 c 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c b 142 q 1 1 1 rg 0 i 1 w 4 M 1 j 0 J []0 d /GS0 gs 1 0 0 1 9 5.0908 cm 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c h f Q 0 G 1 1 0 rg 0 i 0.60 w 4 M 1 j 0 J []0 d 1 1 0 rg 0 G 0 i 0.59 w 4 M 1 j 0 J []0 d 1 0 0 1 9 5.0908 cm 0 0 m -0.142 0 -0.28 0.008 -0.418 0.015 c -2.199 -1.969 -5.555 -2.242 -4.642 -1.42 c -4.024 -0.862 -3.916 0.111 -3.954 0.916 c -5.658 1.795 -6.772 3.222 -6.772 4.839 c -6.772 7.509 -3.74 9.674 0 9.674 c 3.74 9.674 6.772 7.509 6.772 4.839 c 6.772 2.167 3.74 0 0 0 c 7.74 12.616 m -7.74 12.616 l -8.274 12.616 -8.707 12.184 -8.707 11.649 c -8.707 -3.831 l -8.707 -4.365 -8.274 -4.798 -7.74 -4.798 c 7.74 -4.798 l 8.274 -4.798 8.707 -4.365 8.707 -3.831 c 8.707 11.649 l 8.707 12.184 8.274 12.616 7.74 12.616 c b
@@ -151,80 +144,31 @@ endstream @@ -151,80 +144,31 @@ endstream
151 endobj 144 endobj
152 145
153 %QDF: ignore_newline 146 %QDF: ignore_newline
154 -14 0 obj 147 +13 0 obj
155 928 148 928
156 endobj 149 endobj
157 150
158 -15 0 obj  
159 -<<  
160 - /F 28  
161 - /Open false  
162 - /Parent 16 0 R  
163 - /Rect [  
164 - 612  
165 - 601  
166 - 792  
167 - 721  
168 - ]  
169 - /Subtype /Popup  
170 - /Type /Annot  
171 ->>  
172 -endobj  
173 -  
174 -16 0 obj  
175 -<<  
176 - /AP <<  
177 - /N 13 0 R  
178 - >>  
179 - /C [  
180 - 1  
181 - 1  
182 - 0  
183 - ]  
184 - /CA 1  
185 - /Contents (Salad)  
186 - /CreationDate (D:20181231235455Z00'00)  
187 - /F 28  
188 - /M (D:20181231235455Z00'00)  
189 - /Name /Comment  
190 - /P 3 0 R  
191 - /Popup 15 0 R  
192 - /Rect [  
193 - 235  
194 - 703  
195 - 253  
196 - 721  
197 - ]  
198 - /Subtype /Text  
199 - /T (Jay Berkenbilt)  
200 - /Type /Annot  
201 ->>  
202 -endobj  
203 -  
204 xref 151 xref
205 -0 17 152 +0 14
206 0000000000 65535 f 153 0000000000 65535 f
207 0000000025 00000 n 154 0000000025 00000 n
208 0000000079 00000 n 155 0000000079 00000 n
209 0000000161 00000 n 156 0000000161 00000 n
210 -0000000443 00000 n  
211 -0000000495 00000 n  
212 -0000000552 00000 n  
213 -0000000593 00000 n  
214 -0000000692 00000 n  
215 -0000000734 00000 n  
216 -0000000861 00000 n  
217 -0000000881 00000 n  
218 -0000001000 00000 n  
219 -0000001036 00000 n  
220 -0000002280 00000 n  
221 -0000002301 00000 n  
222 -0000002442 00000 n 157 +0000000450 00000 n
  158 +0000000507 00000 n
  159 +0000000548 00000 n
  160 +0000000647 00000 n
  161 +0000000689 00000 n
  162 +0000000815 00000 n
  163 +0000000834 00000 n
  164 +0000000953 00000 n
  165 +0000000989 00000 n
  166 +0000002233 00000 n
223 trailer << 167 trailer <<
224 /Root 1 0 R 168 /Root 1 0 R
225 - /Size 17 169 + /Size 14
226 /ID [<c5b1999a07a3fdcd0c04cfeed299c25a><31415926535897932384626433832795>] 170 /ID [<c5b1999a07a3fdcd0c04cfeed299c25a><31415926535897932384626433832795>]
227 >> 171 >>
228 startxref 172 startxref
229 -2773 173 +2254
230 %%EOF 174 %%EOF
qpdf/qtest/qpdf/need-appearances-more-out.pdf 0 โ†’ 100644
No preview for this file type
qpdf/qtest/qpdf/need-appearances-more-warn.out 0 โ†’ 100644
  1 +WARNING: need-appearances-more.pdf, object 1 0 at offset 50: document does not have updated appearance streams, so form fields will not be flattened
  2 +qpdf: operation succeeded with warnings; resulting file may have some problems
qpdf/qtest/qpdf/need-appearances-more.pdf 0 โ†’ 100644
No preview for this file type
qpdf/qtest/qpdf/need-appearances-out.pdf
No preview for this file type
qpdf/qtest/qpdf/sample-form-out.pdf
No preview for this file type