Skip to content

Commit c4f8cfa

Browse files
committed
Add PdfAStampingModeTest and signature field tests
Refactor pdfa tests resource files location DEVSIX-3736
1 parent ae44901 commit c4f8cfa

22 files changed

+136
-12
lines changed

pdfa/src/test/java/com/itextpdf/pdfa/PdfA2EmbeddedFilesCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void fileSpecCheckTest02() throws IOException, InterruptedException {
143143
.endText()
144144
.restoreState();
145145

146-
FileInputStream fis = new FileInputStream(sourceFolder + "pdfa.pdf");
146+
FileInputStream fis = new FileInputStream(sourceFolder + "pdfs/pdfa.pdf");
147147
ByteArrayOutputStream os = new ByteArrayOutputStream();
148148
byte[] buffer = new byte[1024];
149149
int length;

pdfa/src/test/java/com/itextpdf/pdfa/PdfABigNumberTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public void runTest() throws Exception {
8888
div.setBackgroundColor(ColorConstants.LIGHT_GRAY);
8989
document.add(div);
9090
}
91-
Assert.assertNull(new CompareTool().compareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder, "diff_"));
91+
Assert.assertNull(new CompareTool().compareByContent(filename, sourceFolder + "cmp/PdfABigNumberTest/cmp_" + file, destinationFolder, "diff_"));
9292
}
9393
}

pdfa/src/test/java/com/itextpdf/pdfa/PdfAFormFieldTest.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public void pdfAButtonFieldTest() throws Exception {
149149

150150
pdf.close();
151151
Assert.assertNull(
152-
new CompareTool().compareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder, "diff_"));
152+
new CompareTool().compareByContent(filename, sourceFolder + "cmp/PdfAFormFieldTest/cmp_" + file, destinationFolder, "diff_"));
153153
}
154154

155155
static class PdfAButtonFieldTestRenderer extends ParagraphRenderer {
@@ -199,7 +199,7 @@ public void draw(DrawContext context) {
199199
public void pdfA1DocWithPdfA1ButtonFieldTest() throws IOException, InterruptedException {
200200
String name = "pdfA1DocWithPdfA1ButtonField";
201201
String fileName = destinationFolder + name + ".pdf";
202-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1ButtonField.pdf";
202+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ButtonField.pdf";
203203

204204
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
205205

@@ -225,7 +225,7 @@ public void pdfA1DocWithPdfA1ButtonFieldTest() throws IOException, InterruptedEx
225225
public void pdfA1DocWithPdfA1CheckBoxFieldTest() throws IOException, InterruptedException {
226226
String name = "pdfA1DocWithPdfA1CheckBoxField";
227227
String fileName = destinationFolder + name + ".pdf";
228-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1CheckBoxField.pdf";
228+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1CheckBoxField.pdf";
229229

230230
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
231231

@@ -249,7 +249,7 @@ public void pdfA1DocWithPdfA1CheckBoxFieldTest() throws IOException, Interrupted
249249
public void pdfA1DocWithPdfA1ChoiceFieldTest() throws IOException, InterruptedException {
250250
String name = "pdfA1DocWithPdfA1ChoiceField";
251251
String fileName = destinationFolder + name + ".pdf";
252-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1ChoiceField.pdf";
252+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ChoiceField.pdf";
253253

254254
PdfFont fontFreeSans = PdfFontFactory.createFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true);
255255
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
@@ -275,7 +275,7 @@ public void pdfA1DocWithPdfA1ChoiceFieldTest() throws IOException, InterruptedEx
275275
public void pdfA1DocWithPdfA1ComboBoxFieldTest() throws IOException, InterruptedException {
276276
String name = "pdfA1DocWithPdfA1ComboBoxField";
277277
String fileName = destinationFolder + name + ".pdf";
278-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1ComboBoxField.pdf";
278+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ComboBoxField.pdf";
279279

280280
PdfFont fontCJK = PdfFontFactory
281281
.createFont(sourceFolder + "NotoSansCJKtc-Light.otf", PdfEncodings.IDENTITY_H, true);
@@ -302,7 +302,7 @@ public void pdfA1DocWithPdfA1ComboBoxFieldTest() throws IOException, Interrupted
302302
public void pdfA1DocWithPdfA1ListFieldTest() throws IOException, InterruptedException {
303303
String name = "pdfA1DocWithPdfA1ListField";
304304
String fileName = destinationFolder + name + ".pdf";
305-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1ListField.pdf";
305+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1ListField.pdf";
306306

307307
PdfFont fontFreeSans = PdfFontFactory.createFont(sourceFolder + "FreeSans.ttf",
308308
"WinAnsi", true);
@@ -334,7 +334,7 @@ public void pdfA1DocWithPdfA1ListFieldTest() throws IOException, InterruptedExce
334334
public void pdfA1DocWithPdfA1PushButtonFieldTest() throws IOException, InterruptedException {
335335
String name = "pdfA1DocWithPdfA1PushButtonField";
336336
String fileName = destinationFolder + name + ".pdf";
337-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1PushButtonField.pdf";
337+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1PushButtonField.pdf";
338338

339339
PdfFont fontFreeSans = PdfFontFactory.createFont(sourceFolder + "FreeSans.ttf",
340340
"WinAnsi", true);
@@ -360,7 +360,7 @@ public void pdfA1DocWithPdfA1PushButtonFieldTest() throws IOException, Interrupt
360360
public void pdfA1DocWithPdfA1RadioButtonFieldTest() throws IOException, InterruptedException {
361361
String name = "pdfA1DocWithPdfA1RadioButtonField";
362362
String fileName = destinationFolder + name + ".pdf";
363-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1RadioButtonField.pdf";
363+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1RadioButtonField.pdf";
364364

365365
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
366366

@@ -389,7 +389,7 @@ public void pdfA1DocWithPdfA1RadioButtonFieldTest() throws IOException, Interrup
389389
public void pdfA1DocWithPdfA1TextFieldTest() throws IOException, InterruptedException {
390390
String name = "pdfA1DocWithPdfA1TextField";
391391
String fileName = destinationFolder + name + ".pdf";
392-
String cmp = sourceFolder + "cmp_pdfA1DocWithPdfA1TextField.pdf";
392+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1TextField.pdf";
393393

394394
PdfFont fontFreeSans = PdfFontFactory.createFont(sourceFolder + "FreeSans.ttf",
395395
"WinAnsi", true);
@@ -411,4 +411,31 @@ public void pdfA1DocWithPdfA1TextFieldTest() throws IOException, InterruptedExce
411411
Assert.assertNull(new CompareTool().compareByContent(fileName, cmp, destinationFolder));
412412
Assert.assertNull(new VeraPdfValidator().validate(fileName));
413413
}
414+
415+
@Test
416+
public void pdfA1DocWithPdfA1SignatureFieldTest() throws IOException, InterruptedException {
417+
String name = "pdfA1DocWithPdfA1SignatureField";
418+
String fileName = destinationFolder + name + ".pdf";
419+
String cmp = sourceFolder + "cmp/PdfAFormFieldTest/cmp_pdfA1DocWithPdfA1SignatureField.pdf";
420+
421+
PdfFont fontFreeSans = PdfFontFactory.createFont(sourceFolder + "FreeSans.ttf",
422+
"WinAnsi", true);
423+
fontFreeSans.setSubset(false);
424+
425+
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
426+
427+
PdfAConformanceLevel conformanceLevel = PdfAConformanceLevel.PDF_A_1B;
428+
PdfADocument pdfDoc = new PdfADocument(new PdfWriter(fileName), conformanceLevel,
429+
new PdfOutputIntent("Custom", "",
430+
"http://www.color.org", "sRGB IEC61966-2.1", is));
431+
432+
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
433+
form.addField(PdfFormField.createSignature(pdfDoc, conformanceLevel).setFieldName("signature")
434+
.setFont(fontFreeSans).setFontSize(20));
435+
436+
pdfDoc.close();
437+
438+
Assert.assertNull(new CompareTool().compareByContent(fileName, cmp, destinationFolder));
439+
Assert.assertNull(new VeraPdfValidator().validate(fileName));
440+
}
414441
}

pdfa/src/test/java/com/itextpdf/pdfa/PdfALongStringTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ public void runTest() throws Exception {
9494
p.setFont(font);
9595
document.add(p);
9696
}
97-
Assert.assertNull(new CompareTool().compareByContent(filename, sourceFolder + "cmp_" + file, destinationFolder, "diff_"));
97+
Assert.assertNull(new CompareTool().compareByContent(filename, sourceFolder + "cmp/PdfALongStringTest/cmp_" + file, destinationFolder, "diff_"));
9898
}
9999
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 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+
package com.itextpdf.pdfa;
44+
45+
import com.itextpdf.forms.PdfAcroForm;
46+
import com.itextpdf.kernel.pdf.PdfReader;
47+
import com.itextpdf.kernel.pdf.PdfWriter;
48+
import com.itextpdf.kernel.utils.CompareTool;
49+
import com.itextpdf.test.ExtendedITextTest;
50+
import com.itextpdf.test.annotations.type.IntegrationTest;
51+
import com.itextpdf.test.pdfa.VeraPdfValidator;
52+
53+
import java.io.IOException;
54+
import org.junit.Assert;
55+
import org.junit.BeforeClass;
56+
import org.junit.Test;
57+
import org.junit.experimental.categories.Category;
58+
59+
@Category(IntegrationTest.class)
60+
public class PdfAStampingModeTest extends ExtendedITextTest {
61+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/pdfa/";
62+
public static final String destinationFolder = "./target/test/com/itextpdf/pdfa/PdfAStampingModeTest/";
63+
public static final String cmpFolder = sourceFolder + "cmp/PdfAStampingModeTest/";
64+
65+
@BeforeClass
66+
public static void beforeClass() {
67+
createOrClearDestinationFolder(destinationFolder);
68+
}
69+
70+
@Test
71+
public void pdfA1FieldStampingModeTest01() throws IOException, InterruptedException {
72+
String fileName = "pdfA1FieldStampingModeTest01.pdf";
73+
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "pdfs/pdfA1DocumentWithPdfA1Fields01.pdf"), new PdfWriter(destinationFolder + fileName));
74+
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false);
75+
form.getField("checkBox").setValue("0");
76+
pdfDoc.close();
77+
78+
CompareTool compareTool = new CompareTool();
79+
Assert.assertNull(compareTool.compareByContent(destinationFolder + fileName, cmpFolder + "cmp_" + fileName, destinationFolder, "diff_"));
80+
Assert.assertNull(compareTool.compareXmp(destinationFolder + fileName, cmpFolder + "cmp_" + fileName, true));
81+
Assert.assertNull(new VeraPdfValidator().validate(destinationFolder + fileName));
82+
}
83+
84+
@Test
85+
public void pdfA2FieldStampingModeTest01() throws IOException, InterruptedException {
86+
String fileName = "pdfA2FieldStampingModeTest01.pdf";
87+
PdfADocument pdfDoc = new PdfADocument(new PdfReader(sourceFolder + "pdfs/pdfA2DocumentWithPdfA2Fields01.pdf"), new PdfWriter(destinationFolder + fileName));
88+
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, false);
89+
form.getField("checkBox").setValue("0");
90+
pdfDoc.close();
91+
92+
CompareTool compareTool = new CompareTool();
93+
Assert.assertNull(compareTool.compareByContent(destinationFolder + fileName, cmpFolder + "cmp_" + fileName, destinationFolder, "diff_"));
94+
Assert.assertNull(compareTool.compareXmp(destinationFolder + fileName, cmpFolder + "cmp_" + fileName, true));
95+
Assert.assertNull(new VeraPdfValidator().validate(destinationFolder + fileName));
96+
}
97+
}

0 commit comments

Comments
 (0)