@@ -22,13 +22,16 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .pdfcleanup ;
24
24
25
+ import com .itextpdf .io .util .DecimalFormatUtil ;
25
26
import com .itextpdf .kernel .colors .ColorConstants ;
26
27
import com .itextpdf .kernel .pdf .PdfDocument ;
27
28
import com .itextpdf .kernel .pdf .PdfReader ;
28
29
import com .itextpdf .kernel .pdf .PdfWriter ;
29
30
import com .itextpdf .kernel .geom .Rectangle ;
31
+ import com .itextpdf .kernel .pdf .canvas .PdfCanvas ;
30
32
import com .itextpdf .kernel .utils .CompareTool ;
31
33
import com .itextpdf .test .ExtendedITextTest ;
34
+
32
35
import org .junit .jupiter .api .Assertions ;
33
36
import org .junit .jupiter .api .Test ;
34
37
import org .junit .jupiter .api .BeforeAll ;
@@ -127,11 +130,10 @@ public void extractionWithSettingOverlapRatio1() throws IOException, Interrupted
127
130
128
131
PdfDocument pdfDoc = new PdfDocument (new PdfReader (inputFile ), new PdfWriter (targetFile ));
129
132
130
-
131
133
CleanUpProperties properties = new CleanUpProperties ();
132
134
properties .setOverlapRatio (1d );
133
135
134
- List <PdfCleanUpLocation > cleanUpLocations = new ArrayList <>(); // convertCleanupLocations();
136
+ List <PdfCleanUpLocation > cleanUpLocations = new ArrayList <>();
135
137
cleanUpLocations .add (new PdfCleanUpLocation (1 , new Rectangle (20 , 690 , 263.75f , 40 ), ColorConstants .YELLOW ));
136
138
PdfCleaner .cleanUp (pdfDoc , cleanUpLocations , properties );
137
139
pdfDoc .close ();
@@ -141,6 +143,39 @@ public void extractionWithSettingOverlapRatio1() throws IOException, Interrupted
141
143
Assertions .assertNull (errorMessage );
142
144
}
143
145
146
+ @ Test
147
+ public void differentTextRenderInfo () throws IOException , InterruptedException {
148
+ final String inputFile = inputPath + "differentTextRenderInfo.pdf" ;
149
+ final Double [] ratioArray = new Double [] {0d , 0.001 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1d };
150
+ final Rectangle r = new Rectangle (110 , 700 , 400 , 130 );
151
+
152
+ List <PdfCleanUpLocation > cleanUpLocations = new ArrayList <PdfCleanUpLocation >();
153
+ PdfCleanUpLocation location = new PdfCleanUpLocation (1 , r );
154
+ cleanUpLocations .add (location );
155
+ CleanUpProperties cleanUpProperties = new CleanUpProperties ();
156
+
157
+ for (Double ratio : ratioArray ) {
158
+ final String targetFile = outputPath + "differentTextRenderInfo_" +
159
+ DecimalFormatUtil .formatNumber (ratio .doubleValue (), "#.000#" ) + "_redact.pdf" ;
160
+ final String cmpFile = inputPath + "cmp_differentTextRenderInfo_" +
161
+ DecimalFormatUtil .formatNumber (ratio .doubleValue (), "#.000#" ) + "_redact.pdf" ;
162
+
163
+ try (PdfDocument pdfDoc = new PdfDocument (new PdfReader (inputFile ), new PdfWriter (targetFile ))) {
164
+ if (ratio == 0d ) {
165
+ cleanUpProperties .setOverlapRatio (null );
166
+ } else {
167
+ cleanUpProperties .setOverlapRatio (ratio );
168
+ }
169
+ PdfCleaner .cleanUp (pdfDoc , cleanUpLocations , cleanUpProperties );
170
+
171
+ // Draw a rectangle to visualize the cleanup
172
+ PdfCanvas pdfCanvas = new PdfCanvas (pdfDoc .getPage (1 ));
173
+ pdfCanvas .setStrokeColor (ColorConstants .RED ).rectangle (r ).stroke ();
174
+ }
175
+
176
+ Assertions .assertNull (new CompareTool ().compareByContent (targetFile , cmpFile , outputPath , "diff_" ));
177
+ }
178
+ }
144
179
145
180
private static List <PdfCleanUpLocation > convertCleanupLocations () {
146
181
List <PdfCleanUpLocation > cleanUpLocations = new ArrayList <>();
0 commit comments