Skip to content

Commit f323e64

Browse files
committed
Merge branch 'develop' into devsecops
2 parents 8889ab8 + bb60f30 commit f323e64

File tree

22 files changed

+221
-369
lines changed

22 files changed

+221
-369
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using iText.Forms.Fields;
25+
using iText.Kernel.Geom;
26+
using iText.Kernel.Pdf;
27+
using iText.Kernel.Utils;
28+
using iText.Test;
29+
30+
namespace iText.Forms {
31+
[NUnit.Framework.Category("IntegrationTest")]
32+
public class RectangleIntegrationTest {
33+
private static readonly String DESTINATION_FOLDER = TestUtil.GetOutputPath() + "/forms/RectangleTest/";
34+
35+
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
36+
.CurrentContext.TestDirectory) + "/resources/itext/forms/RectangleTest/";
37+
38+
[NUnit.Framework.OneTimeSetUp]
39+
public static void InitDestinationFolder() {
40+
ITextTest.CreateOrClearDestinationFolder(DESTINATION_FOLDER);
41+
}
42+
43+
[NUnit.Framework.Test]
44+
public virtual void CreatePdfWithSignatureFields() {
45+
String outPdf = DESTINATION_FOLDER + "RectangleTest.pdf";
46+
String cmpPdf = SOURCE_FOLDER + "cmp_RectangleTest.pdf";
47+
PdfWriter writer = new PdfWriter(DESTINATION_FOLDER + "RectangleTest.pdf");
48+
PdfDocument pdfDoc = new PdfDocument(writer);
49+
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
50+
for (int i = 0; i <= 3; i++) {
51+
int rotation = 90 * i;
52+
PdfPage page = pdfDoc.AddNewPage();
53+
page.SetRotation(rotation);
54+
float x = 20;
55+
float y = 500;
56+
float width = 100;
57+
float height = 50;
58+
float spacing = 50;
59+
for (int j = 1; j <= 3; j++) {
60+
Rectangle rect = new Rectangle(x, y, width, height);
61+
String fieldName = "page" + i + "_Signature" + j;
62+
PdfFormField signatureField = new SignatureFormFieldBuilder(pdfDoc, fieldName).SetPage(page).SetWidgetRectangle
63+
(rect).CreateSignature();
64+
form.AddField(signatureField);
65+
x += width + spacing;
66+
}
67+
}
68+
pdfDoc.Close();
69+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
70+
));
71+
}
72+
}
73+
}

itext.tests/itext.forms.tests/itext/forms/xfa/XFAFormTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public virtual void ExtractXFADataTest() {
123123
NUnit.Framework.Assert.AreEqual("Number1", node.Name.LocalName);
124124
}
125125

126+
[NUnit.Framework.Test]
127+
public virtual void ExtractXfaDataFromDatasetTest()
128+
{
129+
String inFileName = sourceFolder + "xfaFormWithDataset2.pdf";
130+
PdfDocument doc = new PdfDocument(new PdfReader(inFileName));
131+
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, false);
132+
XfaForm xfa = form.GetXfaForm();
133+
String actualfieldValue = xfa.GetXfaFieldValue("Subform_Order.TextField_CompanyName");
134+
NUnit.Framework.Assert.AreEqual("Giedi Prime", actualfieldValue);
135+
}
136+
126137
[NUnit.Framework.Test]
127138
public virtual void ExtractNodeTextByPathText() {
128139
String inFileName = sourceFolder + "TextField1.pdf";
Binary file not shown.
Binary file not shown.

itext.tests/itext.kernel.tests/itext/kernel/geom/RectangleTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ public virtual void TranslateOnRotatedPageTest01() {
443443
NUnit.Framework.Assert.IsTrue(PageSize.A4.EqualsWithEpsilon(page.GetPageSize()));
444444
// Test rectangle
445445
Rectangle testRectangle = new Rectangle(200, 200, 100, 200);
446+
Rectangle testRectangle2 = new Rectangle(20, 500, 100, 50);
447+
Rectangle testRectangle3 = new Rectangle(170, 500, 100, 50);
448+
Rectangle testRectangle4 = new Rectangle(320, 500, 100, 50);
446449
NUnit.Framework.Assert.AreEqual(0, page.GetRotation());
447450
NUnit.Framework.Assert.IsTrue(new Rectangle(200, 200, 100, 200).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage
448451
(testRectangle, page)));
@@ -458,6 +461,12 @@ public virtual void TranslateOnRotatedPageTest01() {
458461
NUnit.Framework.Assert.AreEqual(270, page.GetRotation());
459462
NUnit.Framework.Assert.IsTrue(new Rectangle(200, 542, 200, 100).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage
460463
(testRectangle, page)));
464+
NUnit.Framework.Assert.IsTrue(new Rectangle(500, 722, 50, 100).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage
465+
(testRectangle2, page)));
466+
NUnit.Framework.Assert.IsTrue(new Rectangle(500, 572, 50, 100).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage
467+
(testRectangle3, page)));
468+
NUnit.Framework.Assert.IsTrue(new Rectangle(500, 422, 50, 100).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage
469+
(testRectangle4, page)));
461470
page.SetRotation(360);
462471
NUnit.Framework.Assert.AreEqual(0, page.GetRotation());
463472
NUnit.Framework.Assert.IsTrue(new Rectangle(200, 200, 100, 200).EqualsWithEpsilon(Rectangle.GetRectangleOnRotatedPage

itext.tests/itext.kernel.tests/itext/kernel/pdf/XMPMetadataTest.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ namespace iText.Kernel.Pdf {
3232
[NUnit.Framework.Category("IntegrationTest")]
3333
public class XMPMetadataTest : ExtendedITextTest {
3434
public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
35-
.CurrentContext.TestDirectory) + "/resources/itext/kernel/pdf/XmpWriterTest/";
35+
.CurrentContext.TestDirectory) + "/resources/itext/kernel/pdf/XMPMetadataTest/";
3636

37-
public static readonly String DESTINATION_FOLDER = TestUtil.GetOutputPath() + "/kernel/pdf/XmpWriterTest/";
37+
public static readonly String DESTINATION_FOLDER = TestUtil.GetOutputPath() + "/kernel/pdf/XMPMetadataTest/";
3838

3939
[NUnit.Framework.OneTimeSetUp]
4040
public static void BeforeClass() {
@@ -289,5 +289,42 @@ public virtual void ListParsingTest() {
289289
NUnit.Framework.Assert.Catch(typeof(XMPException), () => XMPMetaFactory.ParseFromBuffer(xmp.GetBytes(System.Text.Encoding
290290
.UTF8)));
291291
}
292+
293+
[NUnit.Framework.Test]
294+
public virtual void ReadDocumentWithControlCharactersInXMPMetadata() {
295+
String src = SOURCE_FOLDER + "docWithControlCharactersInXmp.pdf";
296+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
297+
())) {
298+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_A_3A, document.GetConformance());
299+
}
300+
}
301+
302+
[NUnit.Framework.Test]
303+
public virtual void ReadDocumentWithBrokenControlCharactersInXMPMetadata() {
304+
String src = SOURCE_FOLDER + "docWithBrokenControlCharactersInXmp.pdf";
305+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
306+
())) {
307+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_A_3A, document.GetConformance());
308+
}
309+
}
310+
311+
[NUnit.Framework.Test]
312+
public virtual void ReadDocumentWithInvalidConformance() {
313+
String src = SOURCE_FOLDER + "docWithInvalidConformance.pdf";
314+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
315+
())) {
316+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_NONE_CONFORMANCE, document.GetConformance());
317+
}
318+
}
319+
320+
[LogMessage(iText.IO.Logs.IoLogMessageConstant.EXCEPTION_WHILE_UPDATING_XMPMETADATA)]
321+
[NUnit.Framework.Test]
322+
public virtual void ReadDocumentWithInvalidXMPMetadata() {
323+
String src = SOURCE_FOLDER + "docWithInvalidMetadata.pdf";
324+
using (PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(new MemoryStream()), new StampingProperties
325+
())) {
326+
NUnit.Framework.Assert.AreEqual(PdfConformance.PDF_NONE_CONFORMANCE, document.GetConformance());
327+
}
328+
}
292329
}
293330
}

0 commit comments

Comments
 (0)