Skip to content

Commit

Permalink
[RELEASE] iText pdfSweep 5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iText-CI committed Feb 5, 2025
2 parents 543f808 + ab4df34 commit da7fba7
Show file tree
Hide file tree
Showing 96 changed files with 310 additions and 91 deletions.
65 changes: 55 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<parent>
<groupId>com.itextpdf</groupId>
<artifactId>root</artifactId>
<version>9.0.0</version>
<version>9.1.0</version>
<relativePath />
</parent>

<artifactId>cleanup</artifactId>
<version>5.0.0</version>
<version>5.0.1</version>

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

<properties>
<itext.version>${project.parent.version}</itext.version>
<sourceFolder>${project.basedir}/src/main/java</sourceFolder>
<testSourceFolder>${project.basedir}/src/test/java</testSourceFolder>
</properties>

<dependencies>
Expand Down Expand Up @@ -98,11 +101,53 @@
</repository>
</repositories>

<build>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>with-sharpen</id>
<build>
<plugins>
<plugin>
<groupId>sharpen</groupId>
<artifactId>sharpen-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>sharpen</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>sharpen</groupId>
<artifactId>standard-framework-mapping</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>cleanup</artifactId>
<version>${project.version}</version>
<classifier>sharpen-configuration</classifier>
</dependency>
</dependencies>
<configuration>
<projectName>cleanup</projectName>
<cSharpTargetFolder>./../../sharp/cleanup</cSharpTargetFolder>
<cSharpSourceCodeDestination>itext/itext.cleanup</cSharpSourceCodeDestination>
<cSharpTestCodeDestination>itext.tests/itext.cleanup.tests</cSharpTestCodeDestination>
<buildDotnet>${sharpen.builddotnet}</buildDotnet>
<showDiff>${sharpen.showdiff}</showDiff>
<sourceCodeFiles>
<file>**/src/main/java/**/*.java</file>
</sourceCodeFiles>
<testCodeFiles>
<file>**/src/test/java/**/*.java</file>
</testCodeFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
4 changes: 2 additions & 2 deletions src/main/java/com/itextpdf/pdfcleanup/CleanUpProperties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down Expand Up @@ -29,7 +29,7 @@ This file is part of the iText (R) project.
* Contains properties for {@link PdfCleanUpTool} operations.
*/
public class CleanUpProperties {

//test comment for sharpen
private IMetaInfo metaInfo;
private boolean processAnnotations;
private Double overlapRatio;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/pdfcleanup/LineDashPattern.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
42 changes: 33 additions & 9 deletions src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpFilter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand All @@ -22,6 +22,7 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.pdfcleanup;

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

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

boolean isModified = false;
for (TextRenderInfo ri : text.getCharacterRenderInfos()) {
if (isTextNotToBeCleaned(ri)) {
textArray.add(ri.getPdfString());
} else {
isModified = true;
textArray.add(new PdfNumber(FontProgram.convertGlyphSpaceToTextSpace(-ri.getUnscaledWidth()) /
(text.getFontSize() * text.getHorizontalScaling() / FontProgram.HORIZONTAL_SCALING_FACTOR)
));
}
}

return new FilterResult<PdfArray>(true, textArray);
return new FilterResult<PdfArray>(isModified, textArray);
}

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

Expand All @@ -279,7 +283,7 @@ com.itextpdf.kernel.geom.Path filterStrokePath(PathRenderInfo path) {
* @return a filtered {@link com.itextpdf.kernel.geom.Path} object.
*/
com.itextpdf.kernel.geom.Path filterFillPath(PathRenderInfo path, int fillingRule) {
return filterFillPath(path.getPath(), path.getCtm(), fillingRule);
return filterFillPath(path.getPath(), path.getCtm(), fillingRule, false);
}

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

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

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

private com.itextpdf.kernel.geom.Path filterStrokePath(com.itextpdf.kernel.geom.Path sourcePath, Matrix ctm,
private Tuple2<Path, Boolean> filterStrokePath(Path sourcePath, Matrix ctm,
float lineWidth, int lineCapStyle, int lineJoinStyle,
float miterLimit, LineDashPattern lineDashPattern) {
com.itextpdf.kernel.geom.Path path = sourcePath;
Path path = sourcePath;
JoinType joinType = ClipperBridge.getJoinType(lineJoinStyle);
EndType endType = ClipperBridge.getEndType(lineCapStyle);

Expand Down Expand Up @@ -394,7 +413,12 @@ private com.itextpdf.kernel.geom.Path filterStrokePath(com.itextpdf.kernel.geom.
}
}

return filterFillPath(offsetedPath, ctm, PdfCanvasConstants.FillingRule.NONZERO_WINDING);
Path resultPath = filterFillPath(offsetedPath, ctm, PdfCanvasConstants.FillingRule.NONZERO_WINDING, true);
//if path was not filtered, return original path
if (resultPath == offsetedPath) {
return new Tuple2<Path, Boolean>(sourcePath, Boolean.FALSE);
}
return new Tuple2<Path, Boolean>(resultPath, Boolean.TRUE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
32 changes: 23 additions & 9 deletions src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpProcessor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand All @@ -22,6 +22,7 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.pdfcleanup;

import com.itextpdf.commons.datastructures.Tuple2;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.io.source.ByteUtils;
Expand Down Expand Up @@ -823,12 +824,18 @@ private void writePath() {
}

if (stroke) {
Path strokePath = filter.filterStrokePath(path);
if (!strokePath.isEmpty()) {
// we pass stroke here as false, because stroke is transformed into fill. we don't need to set stroke color
writeNotAppliedGsParams(false, false);
openNotWrittenTags();
writeStrokePath(strokePath, path.getStrokeColor());
Tuple2<Path, Boolean> strokePath = filter.filterStrokePath(path);
if (!strokePath.getFirst().isEmpty()) {
if (strokePath.getSecond()) {
// we pass stroke here as false, because stroke is transformed into fill. we don't need to set stroke color
writeNotAppliedGsParams(false, false);
openNotWrittenTags();
writeFilteredStrokePath(strokePath.getFirst(), path.getStrokeColor());
} else {
writeNotAppliedGsParams(false, true);
openNotWrittenTags();
writeStrokePath(strokePath.getFirst(), path.getStrokeColor());
}
}
}

Expand Down Expand Up @@ -893,14 +900,21 @@ private void writePath(Path path) {
}
}

private void writeStrokePath(Path strokePath, Color strokeColor) {
private void writeFilteredStrokePath(Path strokePath, Color strokeColor) {
PdfCanvas canvas = getCanvas();
// As we transformed stroke to fill, we set stroke color for filling here
//As we transformed stroke to fill, we set stroke color for filling here
canvas.saveState().setFillColor(strokeColor);
writePath(strokePath);
canvas.fill().restoreState();
}

private void writeStrokePath(Path strokePath, Color strokeColor) {
PdfCanvas canvas = getCanvas();
canvas.saveState().setStrokeColor(strokeColor);
writePath(strokePath);
canvas.stroke().restoreState();
}

private void removeOrCloseTag() {
if (notWrittenTags.size() > 0) {
CanvasTag tag = notWrittenTags.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/pdfcleanup/PdfCleanUpTool.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/pdfcleanup/PdfCleaner.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/pdfcleanup/TextPositioning.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down Expand Up @@ -31,9 +31,9 @@ public class PdfSweepProductData {
public static final String PDF_SWEEP_PRODUCT_NAME = "pdfSweep";
public static final String PDF_SWEEP_PUBLIC_PRODUCT_NAME = PDF_SWEEP_PRODUCT_NAME;

private static final String PDF_SWEEP_VERSION = "5.0.0";
private static final String PDF_SWEEP_VERSION = "5.0.1";
private static final int PDF_SWEEP_COPYRIGHT_SINCE = 2000;
private static final int PDF_SWEEP_COPYRIGHT_TO = 2024;
private static final int PDF_SWEEP_COPYRIGHT_TO = 2025;

private static final ProductData PDF_SWEEP_PRODUCT_DATA = new ProductData(PDF_SWEEP_PUBLIC_PRODUCT_NAME,
PDF_SWEEP_PRODUCT_NAME, PDF_SWEEP_VERSION, PDF_SWEEP_COPYRIGHT_SINCE, PDF_SWEEP_COPYRIGHT_TO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Copyright (c) 1998-2025 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
Expand Down
Loading

0 comments on commit da7fba7

Please sign in to comment.