Skip to content

Commit da7fba7

Browse files
committed
[RELEASE] iText pdfSweep 5.0.1
2 parents 543f808 + ab4df34 commit da7fba7

File tree

96 files changed

+310
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+310
-91
lines changed

pom.xml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
<parent>
66
<groupId>com.itextpdf</groupId>
77
<artifactId>root</artifactId>
8-
<version>9.0.0</version>
8+
<version>9.1.0</version>
99
<relativePath />
1010
</parent>
1111

1212
<artifactId>cleanup</artifactId>
13-
<version>5.0.0</version>
13+
<version>5.0.1</version>
1414

1515
<name>pdfSweep</name>
16-
<description>Redact PDF documents. If you have to share PDFs with different departments or send them out of house, but they
16+
<description>Redact PDF documents. If you have to share PDFs with different departments or send them out of house, but
17+
they
1718
include some confidential, sensitive information which should not be shared, pdfSweep is your solution. Redact a PDF
1819
containing sensitive, confidential information, such as personal medical information, account numbers, national
1920
identification numbers, personal details or social security numbers in a reliable and secure way. Data redaction
@@ -31,6 +32,8 @@
3132

3233
<properties>
3334
<itext.version>${project.parent.version}</itext.version>
35+
<sourceFolder>${project.basedir}/src/main/java</sourceFolder>
36+
<testSourceFolder>${project.basedir}/src/test/java</testSourceFolder>
3437
</properties>
3538

3639
<dependencies>
@@ -98,11 +101,53 @@
98101
</repository>
99102
</repositories>
100103

101-
<build>
102-
<plugins>
103-
<plugin>
104-
<artifactId>maven-javadoc-plugin</artifactId>
105-
</plugin>
106-
</plugins>
107-
</build>
104+
<profiles>
105+
<profile>
106+
<id>with-sharpen</id>
107+
<build>
108+
<plugins>
109+
<plugin>
110+
<groupId>sharpen</groupId>
111+
<artifactId>sharpen-maven-plugin</artifactId>
112+
<version>1.0-SNAPSHOT</version>
113+
<executions>
114+
<execution>
115+
<phase>install</phase>
116+
<goals>
117+
<goal>sharpen</goal>
118+
</goals>
119+
</execution>
120+
</executions>
121+
<dependencies>
122+
<dependency>
123+
<groupId>sharpen</groupId>
124+
<artifactId>standard-framework-mapping</artifactId>
125+
<version>1.0-SNAPSHOT</version>
126+
</dependency>
127+
<dependency>
128+
<groupId>com.itextpdf</groupId>
129+
<artifactId>cleanup</artifactId>
130+
<version>${project.version}</version>
131+
<classifier>sharpen-configuration</classifier>
132+
</dependency>
133+
</dependencies>
134+
<configuration>
135+
<projectName>cleanup</projectName>
136+
<cSharpTargetFolder>./../../sharp/cleanup</cSharpTargetFolder>
137+
<cSharpSourceCodeDestination>itext/itext.cleanup</cSharpSourceCodeDestination>
138+
<cSharpTestCodeDestination>itext.tests/itext.cleanup.tests</cSharpTestCodeDestination>
139+
<buildDotnet>${sharpen.builddotnet}</buildDotnet>
140+
<showDiff>${sharpen.showdiff}</showDiff>
141+
<sourceCodeFiles>
142+
<file>**/src/main/java/**/*.java</file>
143+
</sourceCodeFiles>
144+
<testCodeFiles>
145+
<file>**/src/test/java/**/*.java</file>
146+
</testCodeFiles>
147+
</configuration>
148+
</plugin>
149+
</plugins>
150+
</build>
151+
</profile>
152+
</profiles>
108153
</project>

src/main/java/com/itextpdf/pdfcleanup/CleanUpProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -29,7 +29,7 @@ This file is part of the iText (R) project.
2929
* Contains properties for {@link PdfCleanUpTool} operations.
3030
*/
3131
public class CleanUpProperties {
32-
32+
//test comment for sharpen
3333
private IMetaInfo metaInfo;
3434
private boolean processAnnotations;
3535
private Double overlapRatio;

src/main/java/com/itextpdf/pdfcleanup/FilteredImagesCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/LineDashPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/PathOffsetApproximationProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpFilter.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.pdfcleanup;
2424

25+
import com.itextpdf.commons.datastructures.Tuple2;
2526
import com.itextpdf.commons.utils.MessageFormatUtil;
2627
import com.itextpdf.io.font.FontProgram;
2728
import com.itextpdf.io.image.ImageData;
@@ -225,21 +226,24 @@ private boolean checkIfIntersectionOccurs(Paths paths, Point[] rect1, boolean is
225226
FilterResult<PdfArray> filterText(TextRenderInfo text) {
226227
PdfTextArray textArray = new PdfTextArray();
227228

228-
if (isTextNotToBeCleaned(text)) {
229+
// Overlap ratio should not be taken into account when we check the whole text not to be cleaned up
230+
if (properties.getOverlapRatio() == null && isTextNotToBeCleaned(text)) {
229231
return new FilterResult<>(false, new PdfArray(text.getPdfString()));
230232
}
231233

234+
boolean isModified = false;
232235
for (TextRenderInfo ri : text.getCharacterRenderInfos()) {
233236
if (isTextNotToBeCleaned(ri)) {
234237
textArray.add(ri.getPdfString());
235238
} else {
239+
isModified = true;
236240
textArray.add(new PdfNumber(FontProgram.convertGlyphSpaceToTextSpace(-ri.getUnscaledWidth()) /
237241
(text.getFontSize() * text.getHorizontalScaling() / FontProgram.HORIZONTAL_SCALING_FACTOR)
238242
));
239243
}
240244
}
241245

242-
return new FilterResult<PdfArray>(true, textArray);
246+
return new FilterResult<PdfArray>(isModified, textArray);
243247
}
244248

245249
/**
@@ -262,7 +266,7 @@ FilterResult<ImageData> filterImage(FilteredImagesCache.FilteredImageKey imageKe
262266
* @param path the PathRenderInfo object to be filtered
263267
* @return a filtered {@link com.itextpdf.kernel.geom.Path} object.
264268
*/
265-
com.itextpdf.kernel.geom.Path filterStrokePath(PathRenderInfo path) {
269+
Tuple2<Path, Boolean> filterStrokePath(PathRenderInfo path) {
266270
PdfArray dashPattern = path.getLineDashPattern();
267271
LineDashPattern lineDashPattern = new LineDashPattern(dashPattern.getAsArray(0), dashPattern.getAsNumber(1).floatValue());
268272

@@ -279,7 +283,7 @@ com.itextpdf.kernel.geom.Path filterStrokePath(PathRenderInfo path) {
279283
* @return a filtered {@link com.itextpdf.kernel.geom.Path} object.
280284
*/
281285
com.itextpdf.kernel.geom.Path filterFillPath(PathRenderInfo path, int fillingRule) {
282-
return filterFillPath(path.getPath(), path.getCtm(), fillingRule);
286+
return filterFillPath(path.getPath(), path.getCtm(), fillingRule, false);
283287
}
284288

285289
FilteredImagesCache.FilteredImageKey createFilteredImageKey(PdfImageXObject image, Matrix imageCtm, PdfDocument document) {
@@ -292,10 +296,16 @@ FilteredImagesCache.FilteredImageKey createFilteredImageKey(PdfImageXObject imag
292296
* @param path the PathRenderInfo object to be filtered.
293297
* @param ctm a {@link com.itextpdf.kernel.geom.Path} transformation matrix.
294298
* @param fillingRule If the subpath is contour, pass any value.
299+
* @param checkForIntersection if true, the intersection check of path and regions will be performed, and if
300+
* there is no intersection, original path from parameters will be returned.
301+
* We pass true when we filter stroke path (stroke converted to fill)
302+
* not to put fill path into the output if it's not intersected with cleanup area.
303+
* We pass false when we filter fill and clip paths (there we don't convert stroke to
304+
* fill) and thus happy with the result from ClipperBridge DIFFERENCES.
295305
* @return a filtered {@link com.itextpdf.kernel.geom.Path} object.
296306
*/
297307
private com.itextpdf.kernel.geom.Path filterFillPath(com.itextpdf.kernel.geom.Path path,
298-
Matrix ctm, int fillingRule) {
308+
Matrix ctm, int fillingRule, boolean checkForIntersection) {
299309
path.closeAllSubpaths();
300310

301311
List<Point[]> transfRectVerticesList = new ArrayList<>();
@@ -327,6 +337,15 @@ private com.itextpdf.kernel.geom.Path filterFillPath(com.itextpdf.kernel.geom.Pa
327337
if (fillingRule == PdfCanvasConstants.FillingRule.EVEN_ODD) {
328338
fillType = PolyFillType.EVEN_ODD;
329339
}
340+
if (checkForIntersection) {
341+
//Find intersection with cleanup areas
342+
PolyTree cleanupAreaIntersection = new PolyTree();
343+
clipper.execute(ClipType.INTERSECTION, cleanupAreaIntersection, fillType, PolyFillType.NON_ZERO);
344+
if (Paths.makePolyTreeToPaths(cleanupAreaIntersection).isEmpty()) {
345+
//if there are no intersections, return original path as mark that no need to filter anything
346+
return path;
347+
}
348+
}
330349

331350
PolyTree resultTree = new PolyTree();
332351
clipper.execute(ClipType.DIFFERENCE, resultTree, fillType, PolyFillType.NON_ZERO);
@@ -363,10 +382,10 @@ private List<Rectangle> getImageAreasToBeCleaned(Matrix imageCtm) {
363382
return areasToBeCleaned;
364383
}
365384

366-
private com.itextpdf.kernel.geom.Path filterStrokePath(com.itextpdf.kernel.geom.Path sourcePath, Matrix ctm,
385+
private Tuple2<Path, Boolean> filterStrokePath(Path sourcePath, Matrix ctm,
367386
float lineWidth, int lineCapStyle, int lineJoinStyle,
368387
float miterLimit, LineDashPattern lineDashPattern) {
369-
com.itextpdf.kernel.geom.Path path = sourcePath;
388+
Path path = sourcePath;
370389
JoinType joinType = ClipperBridge.getJoinType(lineJoinStyle);
371390
EndType endType = ClipperBridge.getEndType(lineCapStyle);
372391

@@ -394,7 +413,12 @@ private com.itextpdf.kernel.geom.Path filterStrokePath(com.itextpdf.kernel.geom.
394413
}
395414
}
396415

397-
return filterFillPath(offsetedPath, ctm, PdfCanvasConstants.FillingRule.NONZERO_WINDING);
416+
Path resultPath = filterFillPath(offsetedPath, ctm, PdfCanvasConstants.FillingRule.NONZERO_WINDING, true);
417+
//if path was not filtered, return original path
418+
if (resultPath == offsetedPath) {
419+
return new Tuple2<Path, Boolean>(sourcePath, Boolean.FALSE);
420+
}
421+
return new Tuple2<Path, Boolean>(resultPath, Boolean.TRUE);
398422
}
399423

400424
/**

src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpProcessor.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.pdfcleanup;
2424

25+
import com.itextpdf.commons.datastructures.Tuple2;
2526
import com.itextpdf.io.image.ImageData;
2627
import com.itextpdf.io.image.ImageDataFactory;
2728
import com.itextpdf.io.source.ByteUtils;
@@ -823,12 +824,18 @@ private void writePath() {
823824
}
824825

825826
if (stroke) {
826-
Path strokePath = filter.filterStrokePath(path);
827-
if (!strokePath.isEmpty()) {
828-
// we pass stroke here as false, because stroke is transformed into fill. we don't need to set stroke color
829-
writeNotAppliedGsParams(false, false);
830-
openNotWrittenTags();
831-
writeStrokePath(strokePath, path.getStrokeColor());
827+
Tuple2<Path, Boolean> strokePath = filter.filterStrokePath(path);
828+
if (!strokePath.getFirst().isEmpty()) {
829+
if (strokePath.getSecond()) {
830+
// we pass stroke here as false, because stroke is transformed into fill. we don't need to set stroke color
831+
writeNotAppliedGsParams(false, false);
832+
openNotWrittenTags();
833+
writeFilteredStrokePath(strokePath.getFirst(), path.getStrokeColor());
834+
} else {
835+
writeNotAppliedGsParams(false, true);
836+
openNotWrittenTags();
837+
writeStrokePath(strokePath.getFirst(), path.getStrokeColor());
838+
}
832839
}
833840
}
834841

@@ -893,14 +900,21 @@ private void writePath(Path path) {
893900
}
894901
}
895902

896-
private void writeStrokePath(Path strokePath, Color strokeColor) {
903+
private void writeFilteredStrokePath(Path strokePath, Color strokeColor) {
897904
PdfCanvas canvas = getCanvas();
898-
// As we transformed stroke to fill, we set stroke color for filling here
905+
//As we transformed stroke to fill, we set stroke color for filling here
899906
canvas.saveState().setFillColor(strokeColor);
900907
writePath(strokePath);
901908
canvas.fill().restoreState();
902909
}
903910

911+
private void writeStrokePath(Path strokePath, Color strokeColor) {
912+
PdfCanvas canvas = getCanvas();
913+
canvas.saveState().setStrokeColor(strokeColor);
914+
writePath(strokePath);
915+
canvas.stroke().restoreState();
916+
}
917+
904918
private void removeOrCloseTag() {
905919
if (notWrittenTags.size() > 0) {
906920
CanvasTag tag = notWrittenTags.pop();

src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/PdfCleaner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/TextPositioning.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/actions/data/PdfSweepProductData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.
@@ -31,9 +31,9 @@ public class PdfSweepProductData {
3131
public static final String PDF_SWEEP_PRODUCT_NAME = "pdfSweep";
3232
public static final String PDF_SWEEP_PUBLIC_PRODUCT_NAME = PDF_SWEEP_PRODUCT_NAME;
3333

34-
private static final String PDF_SWEEP_VERSION = "5.0.0";
34+
private static final String PDF_SWEEP_VERSION = "5.0.1";
3535
private static final int PDF_SWEEP_COPYRIGHT_SINCE = 2000;
36-
private static final int PDF_SWEEP_COPYRIGHT_TO = 2024;
36+
private static final int PDF_SWEEP_COPYRIGHT_TO = 2025;
3737

3838
private static final ProductData PDF_SWEEP_PRODUCT_DATA = new ProductData(PDF_SWEEP_PUBLIC_PRODUCT_NAME,
3939
PDF_SWEEP_PRODUCT_NAME, PDF_SWEEP_VERSION, PDF_SWEEP_COPYRIGHT_SINCE, PDF_SWEEP_COPYRIGHT_TO);

src/main/java/com/itextpdf/pdfcleanup/actions/event/PdfSweepProductEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

src/main/java/com/itextpdf/pdfcleanup/autosweep/CommonRegex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the iText (R) project.
3-
Copyright (c) 1998-2024 Apryse Group NV
3+
Copyright (c) 1998-2025 Apryse Group NV
44
Authors: Apryse Software.
55
66
This program is offered under a commercial and under the AGPL license.

0 commit comments

Comments
 (0)