Skip to content

Commit 7f1cc60

Browse files
kevinwillems1993iText-CI
authored andcommitted
Fix Checkbox field appearance stream for PDF/A
DEVSIX-2172 Autoported commit. Original commit hash: [def5fdf6e]
1 parent c68337c commit 7f1cc60

24 files changed

+526
-19
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.IO;
3+
using iText.Forms;
4+
using iText.Forms.Fields;
5+
using iText.Kernel.Colors;
6+
using iText.Kernel.Geom;
7+
using iText.Kernel.Pdf;
8+
using iText.Kernel.Utils;
9+
using iText.Test;
10+
11+
namespace iText.Pdfa {
12+
public class PdfA1bCheckfieldAppearanceTest : ExtendedITextTest {
13+
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
14+
.CurrentContext.TestDirectory) + "/resources/itext/pdfa/";
15+
16+
public static readonly String cmpFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
17+
.CurrentContext.TestDirectory) + "/resources/itext/pdfa/cmp/PdfA1bCheckfieldAppearanceTest/";
18+
19+
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
20+
+ "/test/itext/pdfa/PdfA1bCheckfieldAppearanceTest/";
21+
22+
[NUnit.Framework.OneTimeSetUp]
23+
public static void BeforeClass() {
24+
CreateDestinationFolder(destinationFolder);
25+
}
26+
27+
/// <exception cref="System.IO.IOException"/>
28+
/// <exception cref="System.Exception"/>
29+
[NUnit.Framework.Test]
30+
public virtual void PdfA1bCheckFieldOffAppearanceTest() {
31+
String name = "pdfA1b_checkFieldOffAppearance";
32+
String outPath = destinationFolder + name + ".pdf";
33+
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
34+
String diff = "diff_" + name + "_";
35+
PdfWriter writer = new PdfWriter(outPath);
36+
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
37+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
38+
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
39+
doc.AddNewPage();
40+
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
41+
PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "Off", PdfFormField
42+
.TYPE_CHECK, PdfAConformanceLevel.PDF_A_1B);
43+
chk.SetBorderColor(ColorConstants.BLACK);
44+
chk.SetBorderWidth(1);
45+
form.AddField(chk);
46+
doc.Close();
47+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
48+
));
49+
}
50+
51+
/// <exception cref="System.IO.IOException"/>
52+
/// <exception cref="System.Exception"/>
53+
[NUnit.Framework.Test]
54+
public virtual void PdfA1bCheckFieldOnAppearanceTest() {
55+
String name = "pdfA1b_checkFieldOnAppearance";
56+
String outPath = destinationFolder + name + ".pdf";
57+
String cmpPath = cmpFolder + "cmp_" + name + ".pdf";
58+
String diff = "diff_" + name + "_";
59+
PdfWriter writer = new PdfWriter(outPath);
60+
Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
61+
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", ""
62+
, "http://www.color.org", "sRGB IEC61966-2.1", @is));
63+
doc.AddNewPage();
64+
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
65+
PdfFormField chk = PdfFormField.CreateCheckBox(doc, new Rectangle(100, 500, 50, 50), "name", "On", PdfFormField
66+
.TYPE_CHECK, PdfAConformanceLevel.PDF_A_1B);
67+
chk.SetBorderColor(ColorConstants.BLACK);
68+
chk.SetBorderWidth(1);
69+
form.AddField(chk);
70+
doc.Close();
71+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPath, cmpPath, destinationFolder, diff
72+
));
73+
}
74+
}
75+
}

itext.tests/itext.pdfa.tests/itext/pdfa/PdfACheckfieldTest.cs

Lines changed: 423 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)