@@ -43,6 +43,7 @@ This file is part of the iText (R) project.
43
43
package com .itextpdf .kernel .pdf ;
44
44
45
45
import com .itextpdf .io .font .constants .StandardFonts ;
46
+ import com .itextpdf .io .image .ImageDataFactory ;
46
47
import com .itextpdf .kernel .font .PdfFontFactory ;
47
48
import com .itextpdf .kernel .geom .Rectangle ;
48
49
import com .itextpdf .kernel .pdf .annot .PdfLinkAnnotation ;
@@ -51,17 +52,23 @@ This file is part of the iText (R) project.
51
52
import com .itextpdf .kernel .pdf .tagging .PdfMcrDictionary ;
52
53
import com .itextpdf .kernel .pdf .tagging .PdfMcrNumber ;
53
54
import com .itextpdf .kernel .pdf .tagging .PdfStructElem ;
55
+ import com .itextpdf .kernel .pdf .xobject .PdfFormXObject ;
54
56
import com .itextpdf .kernel .utils .CompareTool ;
55
57
import com .itextpdf .kernel .utils .CompareTool .CompareResult ;
56
58
import com .itextpdf .test .ExtendedITextTest ;
57
59
import com .itextpdf .test .annotations .type .IntegrationTest ;
60
+ import org .junit .Assert ;
58
61
import org .junit .BeforeClass ;
62
+ import org .junit .Ignore ;
59
63
import org .junit .Test ;
60
64
import org .junit .experimental .categories .Category ;
65
+ import org .xml .sax .SAXException ;
61
66
67
+ import javax .xml .parsers .ParserConfigurationException ;
62
68
import java .io .IOException ;
63
69
64
70
import static org .junit .Assert .assertTrue ;
71
+ import static org .junit .Assert .fail ;
65
72
66
73
@ Category (IntegrationTest .class )
67
74
public class ParentTreeTest extends ExtendedITextTest {
@@ -104,6 +111,19 @@ public void test01() throws IOException {
104
111
assertTrue (checkParentTree (outFile , cmpFile ));
105
112
}
106
113
114
+ @ Ignore ("works in non-deterministic way because of the bug in iText code, DEVSIX-3322" )
115
+ @ Test
116
+ //TODO update cmp-file after DEVSIX-3322 fixed
117
+ public void stampingFormXobjectInnerContentTaggedTest () throws IOException , InterruptedException {
118
+ String pdf = sourceFolder + "alreadyTaggedFormXObjectInnerContent.pdf" ;
119
+ String outPdf = destinationFolder + "stampingFormXobjectInnerContentTaggedTest.pdf" ;
120
+ String cmpPdf = sourceFolder + "cmp_stampingFormXobjectInnerContentTaggedTest.pdf" ;
121
+
122
+ PdfDocument taggedPdf = new PdfDocument (new PdfReader (pdf ), new PdfWriter (outPdf ));
123
+ taggedPdf .setTagged ();
124
+ taggedPdf .close ();
125
+ Assert .assertNull (new CompareTool ().compareByContent (outPdf , cmpPdf , destinationFolder , "diff" ));
126
+ }
107
127
108
128
@ Test
109
129
public void test02 () throws IOException {
@@ -149,21 +169,21 @@ public void test03() throws IOException {
149
169
PdfPage firstPage = document .addNewPage ();
150
170
151
171
for (int i = 0 ; i < 51 ; i ++) {
152
- PdfPage anotherPage = document .addNewPage ();
153
- PdfCanvas canvas = new PdfCanvas (anotherPage );
154
- canvas .beginText ();
155
- canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
156
- canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
157
- PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
158
- PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , anotherPage ));
159
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (anotherPage , span1 ))));
160
- canvas .showText ("Hello " );
161
- canvas .closeTag ();
162
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (anotherPage , span1 ))));
163
- canvas .showText ("World" );
164
- canvas .closeTag ();
165
- canvas .endText ();
166
- canvas .release ();
172
+ PdfPage anotherPage = document .addNewPage ();
173
+ PdfCanvas canvas = new PdfCanvas (anotherPage );
174
+ canvas .beginText ();
175
+ canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
176
+ canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
177
+ PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
178
+ PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , anotherPage ));
179
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (anotherPage , span1 ))));
180
+ canvas .showText ("Hello " );
181
+ canvas .closeTag ();
182
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (anotherPage , span1 ))));
183
+ canvas .showText ("World" );
184
+ canvas .closeTag ();
185
+ canvas .endText ();
186
+ canvas .release ();
167
187
}
168
188
document .close ();
169
189
@@ -180,21 +200,21 @@ public void test04() throws IOException {
180
200
PdfStructElem doc = document .getStructTreeRoot ().addKid (new PdfStructElem (document , PdfName .Document ));
181
201
182
202
for (int i = 0 ; i < 51 ; i ++) {
183
- PdfPage anotherPage = document .addNewPage ();
184
- PdfCanvas canvas = new PdfCanvas (anotherPage );
185
- canvas .beginText ();
186
- canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
187
- canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
188
- PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
189
- PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , anotherPage ));
190
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (anotherPage , span1 ))));
191
- canvas .showText ("Hello " );
192
- canvas .closeTag ();
193
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (anotherPage , span1 ))));
194
- canvas .showText ("World" );
195
- canvas .closeTag ();
196
- canvas .endText ();
197
- canvas .release ();
203
+ PdfPage anotherPage = document .addNewPage ();
204
+ PdfCanvas canvas = new PdfCanvas (anotherPage );
205
+ canvas .beginText ();
206
+ canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
207
+ canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
208
+ PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
209
+ PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , anotherPage ));
210
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (anotherPage , span1 ))));
211
+ canvas .showText ("Hello " );
212
+ canvas .closeTag ();
213
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (anotherPage , span1 ))));
214
+ canvas .showText ("World" );
215
+ canvas .closeTag ();
216
+ canvas .endText ();
217
+ canvas .release ();
198
218
}
199
219
document .close ();
200
220
@@ -210,43 +230,43 @@ public void test05() throws IOException {
210
230
211
231
PdfStructElem doc = document .getStructTreeRoot ().addKid (new PdfStructElem (document , PdfName .Document ));
212
232
213
- PdfPage page1 = document .addNewPage ();
214
- PdfCanvas canvas = new PdfCanvas (page1 );
215
- canvas .beginText ();
216
- canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
217
- canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
218
- PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
219
- PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page1 ));
220
-
221
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (page1 , span1 ))));
222
- canvas .showText ("Hello " );
223
- canvas .closeTag ();
224
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (page1 , span1 ))));
225
- canvas .showText ("World" );
226
- canvas .closeTag ();
227
- canvas .endText ();
228
- canvas .release ();
229
-
230
- PdfPage page2 = document .addNewPage ();
231
- canvas = new PdfCanvas (page2 );
232
- canvas .beginText ();
233
- canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .HELVETICA ), 24 );
234
- canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
235
- paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
236
- span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page2 ));
237
- canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (page2 , span1 ))));
238
- canvas .showText ("Hello " );
239
- canvas .closeTag ();
240
- PdfStructElem span2 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page2 ));
241
- canvas .openTag (new CanvasTag (span2 .addKid (new PdfMcrNumber (page2 , span2 ))));
242
- canvas .showText ("World" );
243
- canvas .closeTag ();
244
- canvas .endText ();
245
- canvas .release ();
246
-
247
- document .close ();
248
-
249
- assertTrue (checkParentTree (outFile , cmpFile ));
233
+ PdfPage page1 = document .addNewPage ();
234
+ PdfCanvas canvas = new PdfCanvas (page1 );
235
+ canvas .beginText ();
236
+ canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .COURIER ), 24 );
237
+ canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
238
+ PdfStructElem paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
239
+ PdfStructElem span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page1 ));
240
+
241
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (page1 , span1 ))));
242
+ canvas .showText ("Hello " );
243
+ canvas .closeTag ();
244
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrDictionary (page1 , span1 ))));
245
+ canvas .showText ("World" );
246
+ canvas .closeTag ();
247
+ canvas .endText ();
248
+ canvas .release ();
249
+
250
+ PdfPage page2 = document .addNewPage ();
251
+ canvas = new PdfCanvas (page2 );
252
+ canvas .beginText ();
253
+ canvas .setFontAndSize (PdfFontFactory .createFont (StandardFonts .HELVETICA ), 24 );
254
+ canvas .setTextMatrix (1 , 0 , 0 , 1 , 32 , 512 );
255
+ paragraph = doc .addKid (new PdfStructElem (document , PdfName .P ));
256
+ span1 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page2 ));
257
+ canvas .openTag (new CanvasTag (span1 .addKid (new PdfMcrNumber (page2 , span1 ))));
258
+ canvas .showText ("Hello " );
259
+ canvas .closeTag ();
260
+ PdfStructElem span2 = paragraph .addKid (new PdfStructElem (document , PdfName .Span , page2 ));
261
+ canvas .openTag (new CanvasTag (span2 .addKid (new PdfMcrNumber (page2 , span2 ))));
262
+ canvas .showText ("World" );
263
+ canvas .closeTag ();
264
+ canvas .endText ();
265
+ canvas .release ();
266
+
267
+ document .close ();
268
+
269
+ assertTrue (checkParentTree (outFile , cmpFile ));
250
270
}
251
271
252
272
@ Test
@@ -283,14 +303,14 @@ public void test06() throws IOException {
283
303
}
284
304
285
305
private boolean checkParentTree (String outFileName , String cmpFileName ) throws IOException {
286
- PdfReader outReader = new PdfReader (outFileName );
287
- PdfDocument outDocument = new PdfDocument (outReader );
288
- PdfReader cmpReader = new PdfReader (cmpFileName );
289
- PdfDocument cmpDocument = new PdfDocument (cmpReader );
290
- CompareResult result = new CompareTool ().compareByCatalog (outDocument , cmpDocument );
291
- if (!result .isOk ()) {
306
+ PdfReader outReader = new PdfReader (outFileName );
307
+ PdfDocument outDocument = new PdfDocument (outReader );
308
+ PdfReader cmpReader = new PdfReader (cmpFileName );
309
+ PdfDocument cmpDocument = new PdfDocument (cmpReader );
310
+ CompareResult result = new CompareTool ().compareByCatalog (outDocument , cmpDocument );
311
+ if (!result .isOk ()) {
292
312
System .out .println (result .getReport ());
293
313
}
294
- return result .isOk ();
314
+ return result .isOk ();
295
315
}
296
316
}
0 commit comments