Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Nov 23, 2024
2 parents 6cd6776 + 78a5af1 commit f14e241
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 10 deletions.
17 changes: 17 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/PdfChoiceFieldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,22 @@ public virtual void LongOptionWrappedIntoTwoLinesTest() {
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
));
}

[NUnit.Framework.Test]
public virtual void SetFontSizeChoiceFieldTest() {
String outPdf = destinationFolder + "setFontSizeChoiceField.pdf";
String cmpPdf = sourceFolder + "cmp_setFontSizeChoiceField.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
Rectangle rectangle = new Rectangle(150, 500, 200, 150);
PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle
(rectangle).SetOptions(new String[] { "option1", "option2", "option3" }).CreateList();
choiceBoxField.SetFontSize(40);
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
acroForm.AddField(choiceBoxField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_"
));
}
}
}
62 changes: 62 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/PdfPushButtonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2024 Apryse Group NV
Authors: Apryse Software.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using iText.Forms.Fields;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Test;

namespace iText.Forms {
[NUnit.Framework.Category("IntegrationTest")]
public class PdfPushButtonTest : ExtendedITextTest {
public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/forms/PdfPushButtonTest/";

public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/forms/PdfPushButtonTest/";

[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[NUnit.Framework.Test]
public virtual void SetFontSizePushButtonWithDisplayTest() {
String outPdf = DESTINATION_FOLDER + "pushButtonWithDisplay.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_pushButtonWithDisplay.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
Rectangle rectangle = new Rectangle(150, 400, 400, 100);
PdfButtonFormField button = new PushButtonFormFieldBuilder(doc, "button").SetWidgetRectangle(rectangle).SetPage
(1).CreatePushButton();
button.SetFontSize(50);
button.SetValue("value", "some display text");
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
acroForm.AddField(button);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}
}
}
135 changes: 135 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/fields/FieldsRotationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections.Generic;
using iText.Commons.Utils;
using iText.Forms;
using iText.Forms.Fields.Properties;
using iText.Forms.Form.Element;
using iText.Kernel.Colors;
using iText.Kernel.Geom;
Expand Down Expand Up @@ -99,6 +100,140 @@ private void FillForm(int[] pageRotation, int[] fieldRotation, bool ignorePageRo
}
}

[NUnit.Framework.Test]
public virtual void FillRotated90TextFormFieldTest() {
String inPdf = SOURCE_FOLDER + "rotated90TextFormField.pdf";
String outPdf = DESTINATION_FOLDER + "filledRotated90TextFormField.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_filledRotated90TextFormField.pdf";
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inPdf), CompareTool.CreateTestPdfWriter(outPdf))
) {
IDictionary<String, String> fieldValues = new Dictionary<String, String>();
fieldValues.Put("textForm", "some text");
FillAndFlattenForm(pdfDoc, fieldValues);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void FillRotated270TextFormFieldTest() {
String inPdf = SOURCE_FOLDER + "rotated270TextFormField.pdf";
String outPdf = DESTINATION_FOLDER + "filledRotated270TextFormField.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_filledRotated270TextFormField.pdf";
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inPdf), CompareTool.CreateTestPdfWriter(outPdf))
) {
IDictionary<String, String> fieldValues = new Dictionary<String, String>();
fieldValues.Put("textForm", "some text");
FillAndFlattenForm(pdfDoc, fieldValues);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void RotatedButtonWithDisplayValueTest() {
String outPdf = DESTINATION_FOLDER + "rotatedButtonWithDisplayValue.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_rotatedButtonWithDisplayValue.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
Rectangle rectangle = new Rectangle(150, 300, 150, 400);
PdfDictionary chars = new PdfDictionary();
chars.Put(PdfName.R, new PdfNumber(90));
PdfButtonFormField button = new PushButtonFormFieldBuilder(doc, "button").SetWidgetRectangle(rectangle).SetPage
(1).CreatePushButton();
button.GetWidgets()[0].SetAppearanceCharacteristics(chars);
button.SetFontSize(0);
button.SetValue("value", "this text should take all space");
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
acroForm.AddField(button);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void RotatedCheckBoxTest() {
String outPdf = DESTINATION_FOLDER + "rotatedCheckBox.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_rotatedCheckBox.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
PdfDictionary chars = new PdfDictionary();
chars.Put(PdfName.R, new PdfNumber(90));
Rectangle rectangle1 = new Rectangle(0, 300, 100, 100);
PdfButtonFormField box1 = new CheckBoxFormFieldBuilder(doc, "checkBox1").SetPage(1).SetWidgetRectangle(rectangle1
).CreateCheckBox();
box1.GetWidgets()[0].SetAppearanceCharacteristics(chars);
box1.SetCheckType(CheckBoxType.CHECK);
box1.SetValue("ON");
box1.SetFontSize(0);
acroForm.AddField(box1);
Rectangle rectangle2 = new Rectangle(100, 300, 100, 100);
PdfButtonFormField box2 = new CheckBoxFormFieldBuilder(doc, "checkBox2").SetPage(1).SetWidgetRectangle(rectangle2
).CreateCheckBox();
box2.GetWidgets()[0].SetAppearanceCharacteristics(chars);
box2.SetCheckType(CheckBoxType.STAR);
box2.SetValue("ON");
box2.SetFontSize(0);
acroForm.AddField(box2);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void RotatedChoiceBoxTest() {
String outPdf = DESTINATION_FOLDER + "rotatedChoiceBox.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_rotatedChoiceBox.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
Rectangle rectangle = new Rectangle(150, 500, 200, 150);
PdfDictionary chars = new PdfDictionary();
chars.Put(PdfName.R, new PdfNumber(90));
PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle
(rectangle).SetOptions(new String[] { "option1", "option2", "option3", "option4", "option5" }).CreateList
();
choiceBoxField.GetWidgets()[0].SetAppearanceCharacteristics(chars);
choiceBoxField.SetFontSize(0);
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
acroForm.AddField(choiceBoxField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void RotatedComboBoxTest() {
String outPdf = DESTINATION_FOLDER + "rotatedComboBox.pdf";
String cmpPdf = SOURCE_FOLDER + "cmp_rotatedComboBox.pdf";
using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) {
doc.AddNewPage();
Rectangle rectangle = new Rectangle(150, 500, 75, 150);
PdfDictionary chars = new PdfDictionary();
chars.Put(PdfName.R, new PdfNumber(90));
PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle
(rectangle).SetOptions(new String[] { "option1", "option2", "longOption", "option3", "option4", "option5"
}).CreateComboBox();
choiceBoxField.GetWidgets()[0].SetAppearanceCharacteristics(chars);
choiceBoxField.SetValue("option1", true);
choiceBoxField.SetFontSize(0);
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true);
acroForm.AddField(choiceBoxField);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_"
));
}

private static void FillAndFlattenForm(PdfDocument document, IDictionary<String, String> fields) {
PdfAcroForm form = PdfAcroForm.GetAcroForm(document, true);
form.SetNeedAppearances(true);
foreach (KeyValuePair<String, String> field in fields) {
PdfFormField acroField = form.GetField(field.Key);
acroField.SetValue(field.Value);
}
form.FlattenFields();
}

private String GenerateCaption(int pageRotation, int fieldRotation) {
String caption = ", page rotation: " + pageRotation + ", field rotation: " + fieldRotation;
for (int i = 0; i < 3; ++i) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f14e241

Please sign in to comment.