Skip to content

Commit

Permalink
Assign Form role to widget annotation only if it's not a part of Form…
Browse files Browse the repository at this point in the history
… role struct element already

It allows to create widget annotations with labels.

DEVSIX-7965

Autoported commit.
Original commit hash: [77ea061ee]
  • Loading branch information
vitali-pr authored and iText-CI committed Dec 15, 2023
1 parent cdd3448 commit f54feea
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
24 changes: 24 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/FormFieldsTaggingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ public virtual void FormFieldTaggingTest10() {
CompareOutput(outFileName, cmpFileName);
}

[NUnit.Framework.Test]
public virtual void FormFieldTaggingTest11() {
String outFileName = destinationFolder + "taggedPdfWithForms11.pdf";
String cmpFileName = sourceFolder + "cmp_taggedPdfWithForms11.pdf";
PdfWriter writer = new PdfWriter(outFileName);
PdfReader reader = new PdfReader(sourceFolder + "taggedDocWithFields.pdf");
PdfDocument pdfDoc = new PdfDocument(reader, writer);
pdfDoc.SetTagged();
PdfAcroForm acroForm = PdfFormCreator.GetAcroForm(pdfDoc, true);
PdfButtonFormField pushButton = new PushButtonFormFieldBuilder(pdfDoc, "push").SetWidgetRectangle(new Rectangle
(36, 650, 40, 20)).SetCaption("Button 1").CreatePushButton();
pushButton.SetFontSize(12f);
PdfButtonFormField pushButton2 = new PushButtonFormFieldBuilder(pdfDoc, "push 2").SetWidgetRectangle(new Rectangle
(36, 600, 40, 20)).SetCaption("Button 2").CreatePushButton();
pushButton.SetFontSize(12f);
TagTreePointer tagPointer = pdfDoc.GetTagStructureContext().GetAutoTaggingPointer();
tagPointer.MoveToKid(StandardRoles.DIV);
acroForm.AddField(pushButton);
tagPointer.MoveToKid(StandardRoles.FORM);
acroForm.AddField(pushButton2);
pdfDoc.Close();
CompareOutput(outFileName, cmpFileName);
}

private void AddFormFieldsToDocument(PdfDocument pdfDoc, PdfAcroForm acroForm) {
Rectangle rect = new Rectangle(36, 700, 20, 20);
Rectangle rect1 = new Rectangle(36, 680, 20, 20);
Expand Down
15 changes: 10 additions & 5 deletions itext.tests/itext.forms.tests/itext/forms/PdfUA2FormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.XMP;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Element;
using iText.Test;
using iText.Test.Pdfa;

Expand Down Expand Up @@ -77,7 +78,7 @@ public virtual void CheckFormFieldTest() {
}

[NUnit.Framework.Test]
public virtual void CheckTextAreaTest() {
public virtual void CheckTextAreaWithLabelTest() {
String outFile = DESTINATION_FOLDER + "textAreaTest.pdf";
String cmpFile = SOURCE_FOLDER + "cmp_textAreaTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFile, new WriterProperties().SetPdfVersion
Expand All @@ -87,12 +88,16 @@ public virtual void CheckTextAreaTest() {
.FORCE_EMBEDDED);
document.SetFont(font);
CreateSimplePdfUA2Document(pdfDocument);
TextArea formTextArea = new TextArea("form text area");
Paragraph paragraph = new Paragraph("Widget label").SetFont(font);
paragraph.GetAccessibilityProperties().SetRole(StandardRoles.LBL);
TextArea formTextArea = new TextArea("form text1");
formTextArea.SetProperty(FormProperty.FORM_FIELD_FLATTEN, false);
formTextArea.SetProperty(FormProperty.FORM_FIELD_VALUE, "form\ntext\narea");
document.Add(formTextArea);
PdfAcroForm form = PdfFormCreator.GetAcroForm(pdfDocument, true);
form.GetField("form text area").GetPdfObject().Put(PdfName.Contents, new PdfString("Description"));
Div div = new Div();
div.GetAccessibilityProperties().SetRole(StandardRoles.FORM);
div.Add(paragraph);
div.Add(formTextArea);
document.Add(div);
}
CompareAndValidate(outFile, cmpFile);
}
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public static void AddWidgetAnnotationToPage(PdfPage page, PdfAnnotation annotat
if (tagged) {
tagPointer = document.GetTagStructureContext().GetAutoTaggingPointer();
//TODO DEVSIX-4117 PrintField attributes
tagPointer.AddTag(StandardRoles.FORM);
if (!StandardRoles.FORM.Equals(tagPointer.GetRole())) {
tagPointer.AddTag(StandardRoles.FORM);
}
}
page.AddAnnotation(index, annotation, true);
if (tagged) {
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cd02c8ea9f548c039b2a0fb93872c5827912c247
77ea061eef277cb6792a11128ebf1e75cd395305

0 comments on commit f54feea

Please sign in to comment.