@@ -44,6 +44,8 @@ This file is part of the iText (R) project.
44
44
45
45
import com .itextpdf .io .logs .IoLogMessageConstant ;
46
46
import com .itextpdf .io .font .constants .StandardFonts ;
47
+ import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
48
+ import com .itextpdf .kernel .exceptions .PdfException ;
47
49
import com .itextpdf .kernel .font .PdfFontFactory ;
48
50
import com .itextpdf .kernel .geom .Rectangle ;
49
51
import com .itextpdf .kernel .pdf .annot .PdfLinkAnnotation ;
@@ -135,7 +137,7 @@ public void structElemTest01() throws Exception {
135
137
136
138
document .close ();
137
139
138
- compareResult ("structElemTest01.pdf" , "cmp_structElemTest01.pdf" , "diff_structElem_01_" );
140
+ compareResult ("structElemTest01.pdf" , "cmp_structElemTest01.pdf" );
139
141
}
140
142
141
143
@ Test
@@ -167,7 +169,7 @@ public void structElemTest02() throws Exception {
167
169
168
170
document .close ();
169
171
170
- compareResult ("structElemTest02.pdf" , "cmp_structElemTest02.pdf" , "diff_structElem_02_" );
172
+ compareResult ("structElemTest02.pdf" , "cmp_structElemTest02.pdf" );
171
173
}
172
174
173
175
@ Test
@@ -289,7 +291,7 @@ public void structElemTest04() throws Exception {
289
291
290
292
document .close ();
291
293
292
- compareResult ("structElemTest04.pdf" , "cmp_structElemTest04.pdf" , "diff_structElem_04_" );
294
+ compareResult ("structElemTest04.pdf" , "cmp_structElemTest04.pdf" );
293
295
}
294
296
295
297
@ Test
@@ -330,7 +332,7 @@ public void structElemTest05() throws Exception {
330
332
331
333
document .close ();
332
334
333
- compareResult ("structElemTest05.pdf" , "cmp_structElemTest05.pdf" , "diff_structElem_05_" );
335
+ compareResult ("structElemTest05.pdf" , "cmp_structElemTest05.pdf" );
334
336
}
335
337
336
338
@ Test
@@ -359,7 +361,7 @@ public void structElemTest06() throws Exception {
359
361
360
362
document .close ();
361
363
362
- compareResult ("structElemTest06.pdf" , "cmp_structElemTest06.pdf" , "diff_structElem_06_" );
364
+ compareResult ("structElemTest06.pdf" , "cmp_structElemTest06.pdf" );
363
365
}
364
366
365
367
@ Test
@@ -401,7 +403,7 @@ public void structElemTest07() throws Exception {
401
403
402
404
document .close ();
403
405
404
- compareResult ("structElemTest07.pdf" , "cmp_structElemTest07.pdf" , "diff_structElem_07_" );
406
+ compareResult ("structElemTest07.pdf" , "cmp_structElemTest07.pdf" );
405
407
}
406
408
407
409
@ Test
@@ -437,7 +439,7 @@ public void structElemTest08() throws Exception {
437
439
438
440
document .close ();
439
441
440
- compareResult ("structElemTest08.pdf" , "cmp_structElemTest08.pdf" , "diff_structElem_08_" );
442
+ compareResult ("structElemTest08.pdf" , "cmp_structElemTest08.pdf" );
441
443
}
442
444
443
445
@ Test
@@ -450,7 +452,7 @@ public void structElemTest09() throws Exception {
450
452
document .removePage (1 );
451
453
document .close ();
452
454
453
- compareResult ("structElemTest09.pdf" , "cmp_structElemTest09.pdf" , "diff_structElem_09_" );
455
+ compareResult ("structElemTest09.pdf" , "cmp_structElemTest09.pdf" );
454
456
}
455
457
456
458
@ Test
@@ -475,7 +477,7 @@ public void structTreeCopyingTest01() throws Exception {
475
477
destination .close ();
476
478
source .close ();
477
479
478
- compareResult ("structTreeCopyingTest01.pdf" , "cmp_structTreeCopyingTest01.pdf" , "diff_copying_01_" );
480
+ compareResult ("structTreeCopyingTest01.pdf" , "cmp_structTreeCopyingTest01.pdf" );
479
481
}
480
482
481
483
@ Test
@@ -495,7 +497,7 @@ public void structTreeCopyingTest02() throws Exception {
495
497
destination .close ();
496
498
source .close ();
497
499
498
- compareResult ("structTreeCopyingTest02.pdf" , "cmp_structTreeCopyingTest02.pdf" , "diff_copying_02_" );
500
+ compareResult ("structTreeCopyingTest02.pdf" , "cmp_structTreeCopyingTest02.pdf" );
499
501
}
500
502
501
503
@ Test
@@ -539,7 +541,7 @@ public void structTreeCopyingTest04() throws Exception {
539
541
destination .close ();
540
542
source .close ();
541
543
542
- compareResult ("structTreeCopyingTest04.pdf" , "cmp_structTreeCopyingTest04.pdf" , "diff_copying_04_" );
544
+ compareResult ("structTreeCopyingTest04.pdf" , "cmp_structTreeCopyingTest04.pdf" );
543
545
}
544
546
545
547
@ Test
@@ -557,7 +559,7 @@ public void structTreeCopyingTest05() throws Exception {
557
559
document1 .close ();
558
560
document2 .close ();
559
561
560
- compareResult ("structTreeCopyingTest05.pdf" , "cmp_structTreeCopyingTest05.pdf" , "diff_copying_05_" );
562
+ compareResult ("structTreeCopyingTest05.pdf" , "cmp_structTreeCopyingTest05.pdf" );
561
563
}
562
564
563
565
@ Test
@@ -576,7 +578,7 @@ public void structTreeCopyingTest06() throws Exception {
576
578
destination .close ();
577
579
source .close ();
578
580
579
- compareResult ("structTreeCopyingTest06.pdf" , "cmp_structTreeCopyingTest06.pdf" , "diff_copying_06_" );
581
+ compareResult ("structTreeCopyingTest06.pdf" , "cmp_structTreeCopyingTest06.pdf" );
580
582
}
581
583
582
584
@ Test
@@ -611,7 +613,7 @@ public void structTreeCopyingTest07() throws Exception {
611
613
document .close ();
612
614
document1 .close ();
613
615
614
- compareResult ("structTreeCopyingTest07.pdf" , "cmp_structTreeCopyingTest07.pdf" , "diff_copying_07_" );
616
+ compareResult ("structTreeCopyingTest07.pdf" , "cmp_structTreeCopyingTest07.pdf" );
615
617
}
616
618
617
619
@ Test
@@ -626,7 +628,7 @@ public void structTreeCopyingTest08() throws Exception {
626
628
document .close ();
627
629
document1 .close ();
628
630
629
- compareResult ("structTreeCopyingTest08.pdf" , "cmp_structTreeCopyingTest08.pdf" , "diff_copying_08_" );
631
+ compareResult ("structTreeCopyingTest08.pdf" , "cmp_structTreeCopyingTest08.pdf" );
630
632
}
631
633
632
634
@ Test
@@ -642,7 +644,7 @@ public void structTreeCopyingTest09() throws Exception {
642
644
document .close ();
643
645
document1 .close ();
644
646
645
- compareResult ("structTreeCopyingTest09.pdf" , "cmp_structTreeCopyingTest09.pdf" , "diff_copying_09_" );
647
+ compareResult ("structTreeCopyingTest09.pdf" , "cmp_structTreeCopyingTest09.pdf" );
646
648
}
647
649
648
650
@ Test
@@ -662,7 +664,7 @@ public void structTreeCopyingTest10() throws Exception {
662
664
document1 .close ();
663
665
document2 .close ();
664
666
665
- compareResult ("structTreeCopyingTest10.pdf" , "cmp_structTreeCopyingTest10.pdf" , "diff_copying_10_" );
667
+ compareResult ("structTreeCopyingTest10.pdf" , "cmp_structTreeCopyingTest10.pdf" );
666
668
}
667
669
668
670
@ Test
@@ -683,7 +685,33 @@ public void structTreeCopyingTest11() throws Exception {
683
685
document1 .close ();
684
686
document2 .close ();
685
687
686
- compareResult ("structTreeCopyingTest11.pdf" , "cmp_structTreeCopyingTest11.pdf" , "diff_copying_11_" );
688
+ compareResult ("structTreeCopyingTest11.pdf" , "cmp_structTreeCopyingTest11.pdf" );
689
+ }
690
+
691
+ @ Test
692
+ public void structTreeCopyingToPartiallyFlushedDocumentTest () throws Exception {
693
+ String outFile = "structTreeCopyingToPartiallyFlushedDocumentTest.pdf" ;
694
+
695
+ PdfDocument resultDoc = new PdfDocument (new PdfWriter (destinationFolder + outFile ));
696
+ resultDoc .setTagged ();
697
+
698
+ PdfDocument document1 = new PdfDocument (new PdfReader (sourceFolder + "quick-brown-fox.pdf" ));
699
+ document1 .copyPagesTo (1 , 1 , resultDoc );
700
+ resultDoc .flushCopiedObjects (document1 );
701
+ document1 .close ();
702
+
703
+ PdfDocument document2 = new PdfDocument (new PdfReader (sourceFolder + "quick-brown-fox.pdf" ));
704
+ Exception e = Assert .assertThrows (PdfException .class , () -> {
705
+ document2 .copyPagesTo (1 , 1 , resultDoc );
706
+ });
707
+ // TODO DEVSIX-7005 after exception is gone add assertion for the resulting document
708
+ Assert .assertEquals (
709
+ KernelExceptionMessageConstant .TAG_STRUCTURE_COPYING_FAILED_IT_MIGHT_BE_CORRUPTED_IN_ONE_OF_THE_DOCUMENTS ,
710
+ e .getMessage ()
711
+ );
712
+ document2 .close ();
713
+
714
+ resultDoc .close ();
687
715
}
688
716
689
717
@ Test
@@ -734,14 +762,14 @@ public void corruptedTagStructureTest04() throws IOException {
734
762
document .close ();
735
763
}
736
764
737
- private void compareResult (String outFileName , String cmpFileName , String diffNamePrefix )
765
+ private void compareResult (String outFileName , String cmpFileName )
738
766
throws IOException , InterruptedException , ParserConfigurationException , SAXException {
739
767
CompareTool compareTool = new CompareTool ();
740
768
String outPdf = destinationFolder + outFileName ;
741
769
String cmpPdf = sourceFolder + cmpFileName ;
742
770
743
771
String contentDifferences = compareTool .compareByContent (outPdf ,
744
- cmpPdf , destinationFolder , diffNamePrefix );
772
+ cmpPdf , destinationFolder );
745
773
String taggedStructureDifferences = compareTool .compareTagStructures (outPdf , cmpPdf );
746
774
747
775
String errorMessage = "" ;
0 commit comments