Skip to content

Commit a7d3d7f

Browse files
committed
[RELEASE] iText 7 pdfSweep - 2.0.4
https://github.com/itext/i7n-pdfsweep/releases/tag/2.0.4 * release/2.0.4: [RELEASE] 2.0.4-SNAPSHOT -> 2.0.4 Suppress XML doc related warnings Implement image masks filtering Handle noninvertible transformation matricies. Add some tests. Make use of SystemUtil#getTimeBasedIntSeed() method for Random instance creation Improve contribution guidelines Remove unused imports and add @category for tests Update port-hash after release [RELEASE] 2.0.3-SNAPSHOT -> 2.0.4-SNAPSHOT
2 parents edef710 + b7505d2 commit a7d3d7f

Some content is hidden

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

50 files changed

+697
-209
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -70,83 +70,29 @@ Before you submit your pull request consider the following guidelines:
7070
* Please sign the [iText Contributor License Agreement (iCLA)](#cla) before sending pull
7171
requests for any change of more than 20 significant lines of code (we're not counting curly braces and other syntactical sugar).
7272
We cannot accept code without this agreement.
73-
* Clone **iText 7 Community** to your local machine.
74-
75-
```shell
76-
git clone [email protected]:itext/itext7.git
77-
cd itext7
78-
git fetch origin
79-
git checkout -b develop origin/develop
80-
```
81-
82-
* Make your changes in a new git branch based off the develop branch:
83-
84-
```shell
85-
git checkout -b my-fix-branch develop
86-
```
87-
88-
* Create your patch, **including appropriate test cases**.
73+
* Fork the iText repository on GitHub.
74+
* Clone your iText fork to your local machine.
75+
* Make your changes, **including appropriate test cases**.
8976
* Follow our [Coding Rules](#rules).
90-
* Run the full **iText 7 Community** test suite and ensure that all tests pass.
9177
* Commit your changes using a descriptive commit message that follows our
9278
[commit message conventions](#commit-message-format).
93-
94-
```shell
95-
git commit -a
96-
```
97-
Note: the optional commit `-a` command line option will automatically `add` and `rm` edited files.
98-
9979
* Now would be a good time to fix up your commits (if you want or need to) with `git rebase --interactive`.
10080
* Build your changes locally to ensure all the tests pass.
101-
* Push your branch to your GitHub account:
102-
103-
```shell
104-
git remote add my-remote [email protected]:my-remote/itext7.git
105-
git push my-remote my-fix-branch
106-
```
107-
108-
* In GitHub, send a pull request to `itext7:develop`.
81+
* Push your changes to your GitHub account.
82+
* Create a pull request in GitHub.
83+
"Head fork" should be your repository, and the "base fork" should be the iText7 official repository.
10984
* If we suggest changes then:
11085
* Make the required updates.
111-
* Re-run the **iText 7 Community** test suite to ensure tests are still passing.
112-
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
113-
114-
```shell
115-
git fetch origin
116-
git rebase develop -i
117-
git push my-remote my-fix-branch -f
118-
```
86+
* Fix up your commits if needed, with an interactive rebase.
87+
* Re-run the tests and make sure that they are still passing.
88+
* Force push to your GitHub repository. This will update your Pull Request.
11989

12090
That's it! Thank you for your contribution!
12191

12292
#### After your pull request is merged
12393

124-
After your pull request is merged, you can safely delete your branch and pull the changes
125-
from the main (upstream) repository:
126-
127-
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
128-
129-
```shell
130-
git push my-remote --delete my-fix-branch
131-
```
132-
133-
* Check out the develop branch:
134-
135-
```shell
136-
git checkout develop -f
137-
```
138-
139-
* Delete the local branch:
140-
141-
```shell
142-
git branch -D my-fix-branch
143-
```
144-
145-
* Update your develop with the latest upstream version:
146-
147-
```shell
148-
git pull --ff upstream develop
149-
```
94+
After your pull request is merged, you can safely delete your fork and pull the changes
95+
from the main (upstream) repository.
15096

15197

15298
## <a name="rules">Coding Rules</a>

itext.tests/itext.cleanup.tests/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
[assembly: Guid("647c862e-d837-4901-8e7b-68f5f8bf8f34")]
1717

18-
[assembly: AssemblyVersion("2.0.3.0")]
19-
[assembly: AssemblyFileVersion("2.0.3.0")]
20-
[assembly: AssemblyInformationalVersion("2.0.3")]
18+
[assembly: AssemblyVersion("2.0.4.0")]
19+
[assembly: AssemblyFileVersion("2.0.4.0")]
20+
[assembly: AssemblyInformationalVersion("2.0.4")]
2121

2222
[assembly: NUnit.Framework.Timeout(300000)]

itext.tests/itext.cleanup.tests/itext.cleanup.tests.csproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<DefineConstants>DEBUG;TRACE</DefineConstants>
2121
<ErrorReport>prompt</ErrorReport>
2222
<WarningLevel>4</WarningLevel>
23+
<NoWarn>CS1591;CS1570;CS1572;CS1573;CS1574;CS1580;CS1584;CS1658</NoWarn>
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2526
<DebugType>pdbonly</DebugType>
@@ -28,6 +29,7 @@
2829
<DefineConstants>TRACE</DefineConstants>
2930
<ErrorReport>prompt</ErrorReport>
3031
<WarningLevel>4</WarningLevel>
32+
<NoWarn>CS1591;CS1570;CS1572;CS1573;CS1574;CS1580;CS1584;CS1658</NoWarn>
3133
</PropertyGroup>
3234
<PropertyGroup>
3335
<SignAssembly>true</SignAssembly>
@@ -64,8 +66,8 @@
6466
<Project>{CEE5E7E1-1BF0-4BE1-9941-903262CE2F83}</Project>
6567
<Name>itext.io</Name>
6668
</ProjectReference>
67-
<Reference Include="itext.io, Version=7.1.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')">
68-
<HintPath>$(SolutionDir)\packages\itext7.7.1.5\lib\net40\itext.io.dll</HintPath>
69+
<Reference Include="itext.io, Version=7.1.6.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.io\itext.io.csproj')">
70+
<HintPath>$(SolutionDir)\packages\itext7.7.1.6\lib\net40\itext.io.dll</HintPath>
6971
</Reference>
7072
<ProjectReference Include="..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')">
7173
<Project>{4E7819E8-7555-4E2E-9A01-D8718A2CFDDA}</Project>
@@ -74,15 +76,15 @@
7476
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942" Condition="!Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')">
7577
<HintPath>$(SolutionDir)\packages\Portable.BouncyCastle.1.8.1.3\lib\net40\BouncyCastle.Crypto.dll</HintPath>
7678
</Reference>
77-
<Reference Include="itext.kernel, Version=7.1.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')">
78-
<HintPath>$(SolutionDir)\packages\itext7.7.1.5\lib\net40\itext.kernel.dll</HintPath>
79+
<Reference Include="itext.kernel, Version=7.1.6.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.kernel\itext.kernel.csproj')">
80+
<HintPath>$(SolutionDir)\packages\itext7.7.1.6\lib\net40\itext.kernel.dll</HintPath>
7981
</Reference>
8082
<ProjectReference Include="..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj" Condition="Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')">
8183
<Project>{F9880DC4-F015-4413-AF86-66D0E9512774}</Project>
8284
<Name>itext.pdftest</Name>
8385
</ProjectReference>
84-
<Reference Include="itext.pdftest, Version=7.1.5.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')">
85-
<HintPath>$(SolutionDir)\packages\itext7.pdftest.7.1.5\lib\net40\itext.pdftest.dll</HintPath>
86+
<Reference Include="itext.pdftest, Version=7.1.6.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca" Condition="!Exists('..\..\..\itextcore\itext\itext.pdftest\itext.pdftest.csproj')">
87+
<HintPath>$(SolutionDir)\packages\itext7.pdftest.7.1.6\lib\net40\itext.pdftest.dll</HintPath>
8688
</Reference>
8789
<ProjectReference Include="..\..\itext\itext.cleanup\itext.cleanup.csproj">
8890
<Project>{2F9B8138-96D5-4DF7-A011-61FE24900987}</Project>

itext.tests/itext.cleanup.tests/itext/pdfcleanup/BigDocumentAutoCleanUpTest.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,6 @@ public static void Before() {
6363
ITextTest.CreateOrClearDestinationFolder(outputPath);
6464
}
6565

66-
/// <exception cref="System.IO.IOException"/>
67-
/// <exception cref="System.Exception"/>
68-
[NUnit.Framework.Test]
69-
public virtual void RedactLipsum() {
70-
String input = inputPath + "Lipsum.pdf";
71-
String output = outputPath + "redactLipsum.pdf";
72-
String cmp = inputPath + "cmp_redactLipsum.pdf";
73-
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
74-
strategy.Add(new RegexBasedCleanupStrategy("(D|d)olor").SetRedactionColor(ColorConstants.GREEN));
75-
PdfWriter writer = new PdfWriter(output);
76-
writer.SetCompressionLevel(0);
77-
PdfDocument pdf = new PdfDocument(new PdfReader(input), writer);
78-
// sweep
79-
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
80-
autoSweep.CleanUp(pdf);
81-
pdf.Close();
82-
// compare
83-
CompareResults(cmp, output, outputPath, "diff_redactLipsum_");
84-
}
85-
8666
/// <exception cref="System.IO.IOException"/>
8767
/// <exception cref="System.Exception"/>
8868
[NUnit.Framework.Test]
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
using System;
44+
using iText.Kernel.Colors;
45+
using iText.Kernel.Pdf;
46+
using iText.Kernel.Utils;
47+
using iText.PdfCleanup.Autosweep;
48+
using iText.Test;
49+
using iText.Test.Attributes;
50+
51+
namespace iText.PdfCleanup {
52+
public class PdfAutoSweepTest : ExtendedITextTest {
53+
private static readonly String inputPath = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
54+
.CurrentContext.TestDirectory) + "/resources/itext/pdfcleanup/PdfAutoSweepTest/";
55+
56+
private static readonly String outputPath = NUnit.Framework.TestContext.CurrentContext.TestDirectory + "/test/itext/pdfcleanup/PdfAutoSweepTest/";
57+
58+
[NUnit.Framework.OneTimeSetUp]
59+
public static void Before() {
60+
CreateOrClearDestinationFolder(outputPath);
61+
}
62+
63+
/// <exception cref="System.IO.IOException"/>
64+
/// <exception cref="System.Exception"/>
65+
[NUnit.Framework.Test]
66+
public virtual void RedactLipsum() {
67+
String input = inputPath + "Lipsum.pdf";
68+
String output = outputPath + "redactLipsum.pdf";
69+
String cmp = inputPath + "cmp_redactLipsum.pdf";
70+
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
71+
strategy.Add(new RegexBasedCleanupStrategy("(D|d)olor").SetRedactionColor(ColorConstants.GREEN));
72+
PdfWriter writer = new PdfWriter(output);
73+
writer.SetCompressionLevel(0);
74+
PdfDocument pdf = new PdfDocument(new PdfReader(input), writer);
75+
// sweep
76+
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
77+
autoSweep.CleanUp(pdf);
78+
pdf.Close();
79+
// compare
80+
CompareByContent(cmp, output, outputPath, "diff_redactLipsum_");
81+
}
82+
83+
/// <exception cref="System.IO.IOException"/>
84+
/// <exception cref="System.Exception"/>
85+
[NUnit.Framework.Test]
86+
[LogMessage(iText.IO.LogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX, Count = 2)]
87+
public virtual void RedactPdfWithNoninvertibleMatrix() {
88+
String input = inputPath + "noninvertibleMatrix.pdf";
89+
String output = outputPath + "redactPdfWithNoninvertibleMatrix.pdf";
90+
String cmp = inputPath + "cmp_redactPdfWithNoninvertibleMatrix.pdf";
91+
CompositeCleanupStrategy strategy = new CompositeCleanupStrategy();
92+
strategy.Add(new RegexBasedCleanupStrategy("Hello World!").SetRedactionColor(ColorConstants.GREEN));
93+
PdfDocument pdf = new PdfDocument(new PdfReader(input), new PdfWriter(output));
94+
// sweep
95+
PdfAutoSweep autoSweep = new PdfAutoSweep(strategy);
96+
autoSweep.CleanUp(pdf);
97+
pdf.Close();
98+
// compare
99+
CompareByContent(cmp, output, outputPath, "diff_redactPdfWithNoninvertibleMatrix_");
100+
}
101+
102+
/// <exception cref="System.IO.IOException"/>
103+
/// <exception cref="System.Exception"/>
104+
private void CompareByContent(String cmp, String output, String targetDir, String diffPrefix) {
105+
CompareTool cmpTool = new CompareTool();
106+
String errorMessage = cmpTool.CompareByContent(output, cmp, targetDir, diffPrefix + "_");
107+
if (errorMessage != null) {
108+
NUnit.Framework.Assert.Fail(errorMessage);
109+
}
110+
}
111+
}
112+
}

itext.tests/itext.cleanup.tests/itext/pdfcleanup/PdfCleanUpToolTest.cs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ public virtual void CleanUpTest12() {
220220
/// <exception cref="System.Exception"/>
221221
[NUnit.Framework.Test]
222222
public virtual void CleanUpTest13() {
223-
String input = inputPath + "smaskImage.pdf";
224-
String output = outputPath + "smaskImage.pdf";
225-
String cmp = inputPath + "cmp_smaskImage.pdf";
223+
String input = inputPath + "maskImage.pdf";
224+
String output = outputPath + "maskImage.pdf";
225+
String cmp = inputPath + "cmp_maskImage.pdf";
226226
IList<PdfCleanUpLocation> cleanUpLocations = JavaUtil.ArraysAsList(new PdfCleanUpLocation(1, new Rectangle
227227
(97f, 405f, 480f - 97f, 445f - 405f), ColorConstants.GRAY));
228228
CleanUp(input, output, cleanUpLocations);
@@ -650,6 +650,66 @@ public virtual void IncorrectBDCToBMCTest() {
650650
CompareByContent(cmp, output, outputPath, "diff_" + fileName);
651651
}
652652

653+
/// <exception cref="System.IO.IOException"/>
654+
/// <exception cref="System.Exception"/>
655+
[NUnit.Framework.Test]
656+
[LogMessage(iText.IO.LogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX)]
657+
public virtual void NoninvertibleMatrixRemoveAllTest() {
658+
String fileName = "noninvertibleMatrixRemoveAllTest";
659+
String input = inputPath + "noninvertibleMatrix.pdf";
660+
String output = outputPath + fileName + ".pdf";
661+
String cmp = inputPath + "cmp_" + fileName + ".pdf";
662+
PdfCleanUpLocation wholePageLocation = new PdfCleanUpLocation(1, new Rectangle(0, 0, 595, 842), null);
663+
CleanUp(input, output, JavaUtil.ArraysAsList(wholePageLocation));
664+
CompareByContent(cmp, output, outputPath, "diff_noninvertibleMatrixRemoveAllTest");
665+
}
666+
667+
/// <exception cref="System.IO.IOException"/>
668+
/// <exception cref="System.Exception"/>
669+
[NUnit.Framework.Test]
670+
[LogMessage(iText.IO.LogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX)]
671+
public virtual void NoninvertibleMatrixRemoveAllTest02() {
672+
String fileName = "noninvertibleMatrixRemoveAllTest02";
673+
String input = inputPath + "noninvertibleMatrix.pdf";
674+
String output = outputPath + fileName + ".pdf";
675+
String cmp = inputPath + "cmp_" + fileName + ".pdf";
676+
PdfCleanUpLocation wholePageLocation = new PdfCleanUpLocation(1, new Rectangle(-1000, -1000, 2000, 2000),
677+
null);
678+
CleanUp(input, output, JavaUtil.ArraysAsList(wholePageLocation));
679+
CompareByContent(cmp, output, outputPath, "diff_noninvertibleMatrixRemoveAllTest");
680+
}
681+
682+
/// <exception cref="System.IO.IOException"/>
683+
/// <exception cref="System.Exception"/>
684+
[NUnit.Framework.Test]
685+
[LogMessage(iText.IO.LogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX)]
686+
public virtual void NoninvertibleMatrixRemoveNothingTest() {
687+
String fileName = "noninvertibleMatrixRemoveNothingTest";
688+
String input = inputPath + "noninvertibleMatrix.pdf";
689+
String output = outputPath + fileName + ".pdf";
690+
String cmp = inputPath + "cmp_" + fileName + ".pdf";
691+
PdfCleanUpLocation dummyLocation = new PdfCleanUpLocation(1, new Rectangle(0, 0, 0, 0), null);
692+
CleanUp(input, output, JavaUtil.ArraysAsList(dummyLocation));
693+
CompareByContent(cmp, output, outputPath, "diff_noninvertibleMatrixRemoveNothingTest");
694+
}
695+
696+
/// <exception cref="System.IO.IOException"/>
697+
/// <exception cref="System.Exception"/>
698+
[NUnit.Framework.Test]
699+
[LogMessage(iText.IO.LogMessageConstant.FAILED_TO_PROCESS_A_TRANSFORMATION_MATRIX, Count = 7)]
700+
public virtual void PathAndIncorrectCMTest() {
701+
String fileName = "pathAndIncorrectCM";
702+
String input = inputPath + "pathAndIncorrectCM.pdf";
703+
String output = outputPath + fileName + ".pdf";
704+
String cmp = inputPath + "cmp_" + fileName + ".pdf";
705+
IList<PdfCleanUpLocation> dummyLocationsList = new List<PdfCleanUpLocation>();
706+
for (int i = 0; i < 3; i++) {
707+
dummyLocationsList.Add(new PdfCleanUpLocation(i + 1, new Rectangle(0, 0, 0, 0), null));
708+
}
709+
CleanUp(input, output, dummyLocationsList);
710+
CompareByContent(cmp, output, outputPath, "diff_pathAndIncorrectCMTest");
711+
}
712+
653713
/// <exception cref="System.IO.IOException"/>
654714
private void CleanUp(String input, String output, IList<PdfCleanUpLocation> cleanUpLocations) {
655715
PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(output));

0 commit comments

Comments
 (0)