@@ -44,18 +44,24 @@ This file is part of the iText (R) project.
44
44
45
45
46
46
import com .itextpdf .kernel .color .ColorConstants ;
47
+ import com .itextpdf .kernel .PdfException ;
47
48
import com .itextpdf .kernel .geom .PageSize ;
48
49
import com .itextpdf .kernel .geom .Rectangle ;
49
50
import com .itextpdf .kernel .pdf .PdfDocument ;
50
51
import com .itextpdf .kernel .pdf .PdfReader ;
52
+ import com .itextpdf .kernel .pdf .PdfString ;
51
53
import com .itextpdf .kernel .pdf .PdfWriter ;
54
+ import com .itextpdf .kernel .pdf .annot .PdfAnnotation ;
55
+ import com .itextpdf .kernel .pdf .annot .PdfRedactAnnotation ;
52
56
import com .itextpdf .kernel .utils .CompareTool ;
53
57
import com .itextpdf .test .ExtendedITextTest ;
54
58
import com .itextpdf .test .annotations .type .IntegrationTest ;
55
59
import org .junit .Assert ;
56
60
import org .junit .BeforeClass ;
61
+ import org .junit .Rule ;
57
62
import org .junit .Test ;
58
63
import org .junit .experimental .categories .Category ;
64
+ import org .junit .rules .ExpectedException ;
59
65
60
66
import java .io .IOException ;
61
67
import java .util .Arrays ;
@@ -67,6 +73,9 @@ public class PdfCleanUpToolTest extends ExtendedITextTest {
67
73
private static final String inputPath = "./src/test/resources/com/itextpdf/pdfcleanup/PdfCleanUpToolTest/" ;
68
74
private static final String outputPath = "./target/test/com/itextpdf/pdfcleanup/PdfCleanUpToolTest/" ;
69
75
76
+ @ Rule
77
+ public ExpectedException junitExpectedException = ExpectedException .none ();
78
+
70
79
@ BeforeClass
71
80
public static void before () {
72
81
createOrClearDestinationFolder (outputPath );
@@ -537,6 +546,46 @@ public void cleanUpTest44() throws IOException, InterruptedException {
537
546
compareByContent (cmp , output , outputPath , "diff_44" );
538
547
}
539
548
549
+ @ Test
550
+ public void cleanUpTest45 () throws IOException , InterruptedException {
551
+ String input = inputPath + "emptyPdf.pdf" ;
552
+ String output = outputPath + "emptyPdf.pdf" ;
553
+ String cmp = inputPath + "cmp_emptyPdf.pdf" ;
554
+
555
+ PdfAnnotation redactAnnotation = new PdfRedactAnnotation (new Rectangle (97 , 405 , 383 , 40 ))
556
+ .setOverlayText (new PdfString ("OverlayTest" ))
557
+ .setDefaultAppearance (new PdfString ("/Helv 0 Tf 0 g" ));
558
+
559
+ PdfDocument pdfDocument = new PdfDocument (new PdfReader (input ), new PdfWriter (output ));
560
+
561
+ pdfDocument .getFirstPage ().addAnnotation (redactAnnotation );
562
+
563
+ new PdfCleanUpTool (pdfDocument , true ).cleanUp ();
564
+
565
+ pdfDocument .close ();
566
+ compareByContent (cmp , output , outputPath , "diff_45" );
567
+ }
568
+
569
+ @ Test
570
+ public void cleanUpTest46 () throws IOException {
571
+ junitExpectedException .expect (PdfException .class );
572
+ junitExpectedException .expectMessage (PdfException .DefaultAppearanceNotFound );
573
+
574
+ String input = inputPath + "emptyPdf.pdf" ;
575
+ String output = outputPath + "emptyPdf.pdf" ;
576
+
577
+ PdfAnnotation redactAnnotation = new PdfRedactAnnotation (new Rectangle (97 , 405 , 383 , 40 ))
578
+ .setOverlayText (new PdfString ("OverlayTest" ));
579
+
580
+ PdfDocument pdfDocument = new PdfDocument (new PdfReader (input ), new PdfWriter (output ));
581
+
582
+ pdfDocument .getFirstPage ().addAnnotation (redactAnnotation );
583
+
584
+ new PdfCleanUpTool (pdfDocument , true ).cleanUp ();
585
+
586
+ pdfDocument .close ();
587
+ }
588
+
540
589
private void cleanUp (String input , String output , List <PdfCleanUpLocation > cleanUpLocations ) throws IOException {
541
590
PdfDocument pdfDocument = new PdfDocument (new PdfReader (input ), new PdfWriter (output ));
542
591
0 commit comments