From 41cd0676b1de2673e73bfd50d3e3a2b048705a50 Mon Sep 17 00:00:00 2001 From: Angelina Pavlovets Date: Mon, 22 Jan 2024 15:30:31 +0000 Subject: [PATCH] Pass signature appearance properties to the newly created field DEVSIX-8037 Autoported commit. Original commit hash: [ecf88c810] --- .../sign/PdfSignatureAppearanceTest.cs | 73 ++++++++++---- .../cmp_signatureFieldAppearanceTest.pdf | Bin 0 -> 28100 bytes .../renderer/AbstractFormFieldRenderer.cs | 61 ------------ .../renderer/AbstractTextFieldRenderer.cs | 3 +- .../forms/form/renderer/CheckBoxRenderer.cs | 3 +- .../forms/form/renderer/RadioRenderer.cs | 2 +- .../renderer/SelectFieldComboBoxRenderer.cs | 3 +- .../renderer/SelectFieldListBoxRenderer.cs | 3 +- .../itext/forms/util/BorderStyleUtil.cs | 93 ++++++++++++++++++ .../signatures/PdfSignatureAppearance.cs | 6 +- .../itext.sign/itext/signatures/PdfSigner.cs | 32 +++++- port-hash | 2 +- 12 files changed, 188 insertions(+), 93 deletions(-) create mode 100644 itext.tests/itext.sign.tests/resources/itext/signatures/sign/PdfSignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf create mode 100644 itext/itext.forms/itext/forms/util/BorderStyleUtil.cs diff --git a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfSignatureAppearanceTest.cs b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfSignatureAppearanceTest.cs index e987008887..542178fdad 100644 --- a/itext.tests/itext.sign.tests/itext/signatures/sign/PdfSignatureAppearanceTest.cs +++ b/itext.tests/itext.sign.tests/itext/signatures/sign/PdfSignatureAppearanceTest.cs @@ -37,6 +37,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Pdf.Canvas; using iText.Kernel.Pdf.Xobject; using iText.Kernel.Utils; +using iText.Layout.Borders; using iText.Layout.Properties; using iText.Signatures; using iText.Signatures.Testutils; @@ -132,10 +133,11 @@ public virtual void TestSigningInAppendModeWithHybridDocument() { String cmp = SOURCE_FOLDER + "cmp_signed_hybrid.pdf"; PdfSigner signer = new PdfSigner(new PdfReader(src), new FileStream(dest, FileMode.Create), new StampingProperties ().UseAppendMode()); - PdfSignatureAppearance appearance = signer.GetSignatureAppearance(); - appearance.SetLayer2FontSize(13.8f).SetPageRect(new Rectangle(36, 748, 200, 100)).SetPageNumber(1).SetReason - ("Test").SetLocation("Nagpur"); - signer.SetFieldName("Sign1"); + String fieldName = "Sign1"; + SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetFontSize(13.8f); + signer.SetFieldName(fieldName); + signer.SetReason("Test").SetLocation("Nagpur").SetPageRect(new Rectangle(36, 748, 200, 100)).SetPageNumber + (1).SetSignatureAppearance(appearance); signer.SetCertificationLevel(PdfSigner.NOT_CERTIFIED); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); @@ -154,10 +156,10 @@ public virtual void FontColorTest01() { String src = SOURCE_FOLDER + "simpleDocument.pdf"; PdfSigner signer = new PdfSigner(new PdfReader(src), new FileStream(dest, FileMode.Create), new StampingProperties ()); - // Creating the appearance - signer.GetSignatureAppearance().SetLayer2FontColor(ColorConstants.RED).SetLayer2Text("Verified and signed by me." - ).SetPageRect(rect); signer.SetFieldName("Signature1"); + // Creating the appearance + signer.SetPageRect(rect).SetSignatureAppearance(new SignatureFieldAppearance(signer.GetFieldName()).SetFontColor + (ColorConstants.RED).SetContent("Verified and signed by me.")); // Creating the signature IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); @@ -197,9 +199,10 @@ public virtual void SignExistingNotMergedFieldNotReusedAPTest() { PdfReader reader = new PdfReader(src); PdfSigner signer = new PdfSigner(reader, new FileStream(dest, FileMode.Create), new StampingProperties()); signer.SetCertificationLevel(PdfSigner.NOT_CERTIFIED); - signer.GetSignatureAppearance().SetLayer2Text("Verified and signed by me.").SetReason("Test 1").SetLocation - ("TestCity").SetReuseAppearance(false); signer.SetFieldName("Signature1"); + signer.SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(new SignatureFieldAppearance(signer + .GetFieldName()).SetContent("Verified and signed by me.")); + signer.GetSignatureField().SetReuseAppearance(false); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(dest, SOURCE_FOLDER + "cmp_" + fileName, DESTINATION_FOLDER @@ -216,9 +219,11 @@ public virtual void SignExistingNotMergedFieldReusedAPTest() { PdfSigner signer = new PdfSigner(reader, new FileStream(dest, FileMode.Create), new StampingProperties()); signer.SetCertificationLevel(PdfSigner.NOT_CERTIFIED); signer.SetFieldName("Signature1"); - signer.GetSignatureAppearance().SetLayer2Text("SIGNED").SetLayer2FontColor(ColorConstants.GREEN).SetReason - ("Test 1").SetLocation("TestCity").SetReuseAppearance(true).GetSignatureAppearance().SetProperty(Property - .VERTICAL_ALIGNMENT, VerticalAlignment.MIDDLE); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetFieldName()).SetContent("SIGNED" + ).SetFontColor(ColorConstants.GREEN); + appearance.SetProperty(Property.VERTICAL_ALIGNMENT, VerticalAlignment.MIDDLE); + signer.SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(appearance); + signer.GetSignatureField().SetReuseAppearance(true); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(dest, SOURCE_FOLDER + "cmp_" + fileName, DESTINATION_FOLDER @@ -234,9 +239,10 @@ public virtual void SignExistingNotMergedFieldReusedAPEntryNDicTest() { PdfReader reader = new PdfReader(src); PdfSigner signer = new PdfSigner(reader, new FileStream(dest, FileMode.Create), new StampingProperties()); signer.SetCertificationLevel(PdfSigner.NOT_CERTIFIED); - signer.GetSignatureAppearance().SetLayer2Text("Verified and signed by me.").SetReason("Test 1").SetLocation - ("TestCity").SetReuseAppearance(true); signer.SetFieldName("Signature1"); + signer.SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance(new SignatureFieldAppearance(signer + .GetFieldName()).SetContent("Verified and signed by me.")); + signer.GetSignatureField().SetReuseAppearance(true); IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(dest, SOURCE_FOLDER + "cmp_" + fileName, DESTINATION_FOLDER @@ -372,18 +378,20 @@ public virtual void Layer2Test() { public virtual void CreateAndSignSignatureFieldTest() { String src = SOURCE_FOLDER + "noSignatureField.pdf"; String dest = DESTINATION_FOLDER + "createdAndSignedSignatureField.pdf"; + String fieldName = "Signature1"; String unsignedDoc = DESTINATION_FOLDER + "unsignedSignatureField.pdf"; PdfDocument document = new PdfDocument(new PdfReader(src), new PdfWriter(unsignedDoc)); - PdfSignatureFormField field = new SignatureFormFieldBuilder(document, "Signature1").SetPage(1).SetWidgetRectangle + PdfSignatureFormField field = new SignatureFormFieldBuilder(document, fieldName).SetPage(1).SetWidgetRectangle (new Rectangle(45, 509, 517, 179)).CreateSignature(); PdfFormCreator.GetAcroForm(document, true).AddField(field); document.Close(); PdfSigner signer = new PdfSigner(new PdfReader(unsignedDoc), new FileStream(dest, FileMode.Create), new StampingProperties ()); + signer.SetFieldName(fieldName); // Creating the appearance - signer.GetSignatureAppearance().SetReason("Appearance is tested").SetLocation("TestCity").SetLayer2Text("Test signature field appearance. Test signature field appearance. " + SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent("Test signature field appearance. Test signature field appearance. " + "Test signature field appearance. Test signature field appearance"); - signer.SetFieldName("Signature1"); + signer.SetReason("Appearance is tested").SetLocation("TestCity").SetSignatureAppearance(appearance); // Signing IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); @@ -397,11 +405,12 @@ public virtual void SignExistedSignatureFieldTest() { String dest = DESTINATION_FOLDER + fileName; PdfSigner signer = new PdfSigner(new PdfReader(src), new FileStream(dest, FileMode.Create), new StampingProperties ()); - // Creating the appearance - signer.GetSignatureAppearance().SetReason("Appearance is tested").SetLocation("TestCity").SetReuseAppearance - (true).SetLayer2Text("Test signature field appearance. Test signature field appearance. " + "Test signature field appearance. Test signature field appearance" - ); signer.SetFieldName("Signature1"); + // Creating the appearance + SignatureFieldAppearance appearance = new SignatureFieldAppearance(signer.GetFieldName()).SetContent("Test signature field appearance. Test signature field appearance. " + + "Test signature field appearance. Test signature field appearance"); + signer.SetReason("Appearance is tested").SetLocation("TestCity").SetSignatureAppearance(appearance); + signer.GetSignatureField().SetReuseAppearance(true); // Signing IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); @@ -446,6 +455,28 @@ public virtual void DeprecatedLayersTest() { TestLayers(src, fileName, true); } + [NUnit.Framework.Test] + public virtual void SignatureFieldAppearanceTest() { + String fileName = "signatureFieldAppearanceTest.pdf"; + String src = SOURCE_FOLDER + "noSignatureField.pdf"; + String cmp = SOURCE_FOLDER + "cmp_" + fileName; + String dest = DESTINATION_FOLDER + fileName; + String fieldName = "Signature1"; + PdfSigner signer = new PdfSigner(new PdfReader(src), new FileStream(dest, FileMode.Create), new StampingProperties + ()); + signer.SetFieldName(fieldName); + SignatureFieldAppearance appearance = new SignatureFieldAppearance(fieldName).SetContent("Signature field" + ).SetBackgroundColor(ColorConstants.GREEN).SetBorder(new SolidBorder(ColorConstants.LIGHT_GRAY, 3)).SetFontColor + (ColorConstants.DARK_GRAY).SetFontSize(20).SetTextAlignment(TextAlignment.CENTER); + signer.SetPageRect(new Rectangle(250, 500, 100, 100)).SetReason("Test 1").SetLocation("TestCity").SetSignatureAppearance + (appearance); + // Signing + IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA256); + signer.SignDetached(pks, chain, null, null, null, 0, PdfSigner.CryptoStandard.CADES); + NUnit.Framework.Assert.IsNull(SignaturesCompareTool.CompareSignatures(dest, cmp)); + NUnit.Framework.Assert.IsNull(new CompareTool().CompareVisually(dest, cmp, DESTINATION_FOLDER, "diff_")); + } + private static void CompareSignatureAppearances(String outPdf, String cmpPdf) { ITextTest.PrintOutCmpPdfNameAndDir(outPdf, cmpPdf); using (PdfDocument outDoc = new PdfDocument(new PdfReader(outPdf))) { diff --git a/itext.tests/itext.sign.tests/resources/itext/signatures/sign/PdfSignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf b/itext.tests/itext.sign.tests/resources/itext/signatures/sign/PdfSignatureAppearanceTest/cmp_signatureFieldAppearanceTest.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3b4b50654a735616ae8891015b8ea1725360419a GIT binary patch literal 28100 zcmeHw2{=`2`?qAKqLM~!Dk-+ThCQq$V}^{8S@W8<$ds7|NfMO?G)PEuLYa~jrOBbF zXizE*B1sz1Am6h!ob$ftocH^m|95@YcYXhBZ`Zcg-s^sb`*+{>?|z=W_j;abj^>tZ zSdXtT?dh|++X{$)1+fB19|Z#g&g{q##)PvKF!a4;~z| z0RIqz3bFPV258S1e8u>O1hWiK2tyzqgF$=Fq{$!ezx*&J%d5*gRSs|pf4nl!a-{&j|Y0dhe16&E)PXv7_|B>o3UE`UV9XMh~I011D|5#S~EyBv@LngA)0{>(2a z5=aStm*NU}e{K=|w-!MkK|evS03^T~;4&A5P#i_TpXdl|Ao}AGFa~Ua489UcVBj2B z>yHvB^gkaZ;6pG1kooSDfASVsbiHM$rNcqfrc) z6=o;|xTgT6_zXkwxIzlYV2V%EFoVMs#uZ=;f{-{k-~s{%4hunChJm?!iic4QC179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F*nmOpD zW|V%cyl5%wd8&wmWet56(mp3AulMM_Zak-Kvz-2|BFUDksQ<3;fE;=?TjuuVUULUt>$}Ti8eEeKsz+NjKbPY>&$T>rf4J|I z5j%#Fx9?6_;Q0Q7>ht|MiYG3Zye^%}p1vm8uWGKu*;_ZsRw@1hEukuP&rhRk+`2oR zE&V}0$<0Az@-F9zk4?|Eek>cPeOuM-Z{*+GyH(HF#Xvp(<(JO(RbTts+M8Qme(H{R z|F)&de@$JN-tBkGl`10BEppTPOQFnZwgW9b?^|A!pBs2_VruKo$Cfv$Mw!;!i#~U) zXXr(A&H1Q{dmfE4o1}o)my}$|x&Ec|&9ejFW?gyP8WHi(I3OIY7~iD7D&kzE@xZsO z>K{t+$uHk`a-MZmb@vOsG9QJuA8hV!j4XWc$f)^oSKqOYR)dOxd7e+-=TFRxRvi~T zpFfSYL-N}&yY8WFfBsw@{m-APTbr{M7~o*b5gynX1#Doz1^cytEqYL}i3}v#0R<;% z5-~CW+Z2!_*swsfu??RFtNVjpU1;zElq0!(uzv&CVFm2#LxT1H`CwNBSRjOGn2&-D zalke)U?&`~^8rqR?OlKnigN{EBL=X$5z6C(T~ffdU3`=T`()vy=yzWX26ln~8xnw> zU2p>IG$RC?>5x35MI38?nh||jiejR3VF38fRP=q^&uJ{!fr{f45D>zGzyAi)**l5> zvOm57bz+1Z_XRKuVIhnDFt??aE~O1=!=TuPIU^imlWUDi5P^OLat zx1sG%yq3}-pQUaclcVuhv6t4zoKQBCk-4(XpQUne$jIdNyDtvYj4+W>+xSFE<+YMh zfwJdt%dE(y2P!3WuUr~iE_W^Djl{@P?lJ45<+sUg8=`VL#=M7;k&!4FHeBJ)_L?^M mlUKIr7q9Gp{l%*S_z7H4NJJ1L1RJ&SVO(L_Gz$kyh5rS#_9deL literal 0 HcmV?d00001 diff --git a/itext/itext.forms/itext/forms/form/renderer/AbstractFormFieldRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/AbstractFormFieldRenderer.cs index 9111f9ca51..ebca19f677 100644 --- a/itext/itext.forms/itext/forms/form/renderer/AbstractFormFieldRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/AbstractFormFieldRenderer.cs @@ -24,17 +24,14 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using Microsoft.Extensions.Logging; using iText.Commons; -using iText.Forms.Fields; using iText.Forms.Form; using iText.Forms.Form.Element; using iText.Forms.Logs; using iText.Kernel.Geom; using iText.Kernel.Pdf; -using iText.Kernel.Pdf.Annot; using iText.Kernel.Pdf.Tagging; using iText.Kernel.Pdf.Tagutils; using iText.Layout; -using iText.Layout.Borders; using iText.Layout.Layout; using iText.Layout.Minmaxwidth; using iText.Layout.Properties; @@ -300,64 +297,6 @@ internal virtual void ApplyProperties(IDictionary properties) { } } - /// Applies the border property. - /// the annotation to set border characteristics to. - internal virtual void ApplyBorderProperty(PdfFormAnnotation annotation) { - ApplyBorderProperty(this, annotation); - } - - /// Applies the border property to the renderer. - /// renderer to apply border properties to. - /// the annotation to set border characteristics to. - internal static void ApplyBorderProperty(IRenderer renderer, PdfFormAnnotation annotation) { - Border border = renderer.GetProperty(Property.BORDER); - if (border == null) { - // For now, we set left border to an annotation, but appropriate borders for an element will be drawn. - border = renderer.GetProperty(Property.BORDER_LEFT); - } - if (border != null) { - annotation.SetBorderStyle(TransformBorderTypeToBorderStyleDictionary(border.GetBorderType())); - annotation.SetBorderColor(border.GetColor()); - annotation.SetBorderWidth(border.GetWidth()); - } - } - - private static PdfDictionary TransformBorderTypeToBorderStyleDictionary(int borderType) { - PdfDictionary bs = new PdfDictionary(); - PdfName style; - switch (borderType) { - case 1001: { - style = PdfAnnotation.STYLE_UNDERLINE; - break; - } - - case 1002: { - style = PdfAnnotation.STYLE_BEVELED; - break; - } - - case 1003: { - style = PdfAnnotation.STYLE_INSET; - break; - } - - case Border.DASHED_FIXED: - case Border.DASHED: - case Border.DOTTED: { - // Default dash array will be used. - style = PdfAnnotation.STYLE_DASHED; - break; - } - - default: { - style = PdfAnnotation.STYLE_SOLID; - break; - } - } - bs.Put(PdfName.S, style); - return bs; - } - private void ProcessLangAttribute() { IPropertyContainer propertyContainer = flatRenderer.GetModelElement(); String lang = GetLang(); diff --git a/itext/itext.forms/itext/forms/form/renderer/AbstractTextFieldRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/AbstractTextFieldRenderer.cs index 92443b6db5..28ead4187c 100644 --- a/itext/itext.forms/itext/forms/form/renderer/AbstractTextFieldRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/AbstractTextFieldRenderer.cs @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using iText.Forms.Fields; using iText.Forms.Form.Element; +using iText.Forms.Util; using iText.Kernel.Font; using iText.Kernel.Geom; using iText.Kernel.Pdf.Annot; @@ -74,7 +75,7 @@ internal virtual void ApplyDefaultFieldProperties(PdfFormField inputField) { inputField.SetColor(color.GetColor()); } inputField.SetJustification(this.GetProperty(Property.TEXT_ALIGNMENT)); - ApplyBorderProperty(inputField.GetFirstFormAnnotation()); + BorderStyleUtil.ApplyBorderProperty(this, inputField.GetFirstFormAnnotation()); Background background = this.GetProperty(Property.BACKGROUND); if (background != null) { inputField.GetFirstFormAnnotation().SetBackgroundColor(background.GetColor()); diff --git a/itext/itext.forms/itext/forms/form/renderer/CheckBoxRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/CheckBoxRenderer.cs index 1c55bc398b..3d95148ad4 100644 --- a/itext/itext.forms/itext/forms/form/renderer/CheckBoxRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/CheckBoxRenderer.cs @@ -27,6 +27,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Forms.Form; using iText.Forms.Form.Element; using iText.Forms.Form.Renderer.Checkboximpl; +using iText.Forms.Util; using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Layout.Borders; @@ -182,7 +183,7 @@ protected internal override void ApplyAcroField(DrawContext drawContext) { } PdfButtonFormField checkBox = builder.CreateCheckBox(); checkBox.DisableFieldRegeneration(); - ApplyBorderProperty(checkBox.GetFirstFormAnnotation()); + BorderStyleUtil.ApplyBorderProperty(this, checkBox.GetFirstFormAnnotation()); Background background = this.modelElement.GetProperty(Property.BACKGROUND); if (background != null) { checkBox.GetFirstFormAnnotation().SetBackgroundColor(background.GetColor()); diff --git a/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs index eafff69200..60bb2e9c83 100644 --- a/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs @@ -172,7 +172,7 @@ protected internal override void ApplyAcroField(DrawContext drawContext) { if (background != null) { radio.SetBackgroundColor(background.GetColor()); } - ApplyBorderProperty(radio); + BorderStyleUtil.ApplyBorderProperty(this, radio); radio.SetFormFieldElement((Radio)modelElement); radioGroup.AddKid(radio); radioGroup.EnableFieldRegeneration(); diff --git a/itext/itext.forms/itext/forms/form/renderer/SelectFieldComboBoxRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/SelectFieldComboBoxRenderer.cs index 1853dceb76..c903a8f869 100644 --- a/itext/itext.forms/itext/forms/form/renderer/SelectFieldComboBoxRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/SelectFieldComboBoxRenderer.cs @@ -28,6 +28,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Forms.Fields; using iText.Forms.Form; using iText.Forms.Form.Element; +using iText.Forms.Util; using iText.Kernel.Font; using iText.Kernel.Geom; using iText.Kernel.Pdf; @@ -104,7 +105,7 @@ protected internal override void ApplyAcroField(DrawContext drawContext) { if (background != null) { comboBoxField.GetFirstFormAnnotation().SetBackgroundColor(background.GetColor()); } - AbstractFormFieldRenderer.ApplyBorderProperty(this, comboBoxField.GetFirstFormAnnotation()); + BorderStyleUtil.ApplyBorderProperty(this, comboBoxField.GetFirstFormAnnotation()); UnitValue fontSize = GetFontSize(); if (fontSize != null) { comboBoxField.SetFontSize(fontSize.GetValue()); diff --git a/itext/itext.forms/itext/forms/form/renderer/SelectFieldListBoxRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/SelectFieldListBoxRenderer.cs index 17fe00c95d..108740551a 100644 --- a/itext/itext.forms/itext/forms/form/renderer/SelectFieldListBoxRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/SelectFieldListBoxRenderer.cs @@ -28,6 +28,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Forms.Fields; using iText.Forms.Form; using iText.Forms.Form.Element; +using iText.Forms.Util; using iText.Kernel.Colors; using iText.Kernel.Font; using iText.Kernel.Geom; @@ -184,7 +185,7 @@ protected internal override void ApplyAcroField(DrawContext drawContext) { choiceField.SetColor(color.GetColor()); } choiceField.SetJustification(this.GetProperty(Property.TEXT_ALIGNMENT)); - AbstractFormFieldRenderer.ApplyBorderProperty(this, choiceField.GetFirstFormAnnotation()); + BorderStyleUtil.ApplyBorderProperty(this, choiceField.GetFirstFormAnnotation()); Background background = this.GetProperty(Property.BACKGROUND); if (background != null) { choiceField.GetFirstFormAnnotation().SetBackgroundColor(background.GetColor()); diff --git a/itext/itext.forms/itext/forms/util/BorderStyleUtil.cs b/itext/itext.forms/itext/forms/util/BorderStyleUtil.cs new file mode 100644 index 0000000000..12403d087b --- /dev/null +++ b/itext/itext.forms/itext/forms/util/BorderStyleUtil.cs @@ -0,0 +1,93 @@ +/* +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 . +*/ +using iText.Forms.Fields; +using iText.Kernel.Pdf; +using iText.Kernel.Pdf.Annot; +using iText.Layout; +using iText.Layout.Borders; +using iText.Layout.Properties; + +namespace iText.Forms.Util { + /// This file is a helper class for the internal usage only. + /// + /// This file is a helper class for the internal usage only. + /// Be aware that its API and functionality may be changed in the future. + /// + public sealed class BorderStyleUtil { + /// Applies the border property to the annotation. + /// property container to apply border properties from. + /// the annotation to set border characteristics to. + public static void ApplyBorderProperty(IPropertyContainer container, PdfFormAnnotation annotation) { + Border border = container.GetProperty(Property.BORDER); + if (border == null) { + // For now, we set left border to an annotation, but appropriate borders for an element will be drawn. + border = container.GetProperty(Property.BORDER_LEFT); + } + if (border != null) { + annotation.SetBorderStyle(TransformBorderTypeToBorderStyleDictionary(border.GetBorderType())); + annotation.SetBorderColor(border.GetColor()); + annotation.SetBorderWidth(border.GetWidth()); + } + } + + private static PdfDictionary TransformBorderTypeToBorderStyleDictionary(int borderType) { + PdfDictionary bs = new PdfDictionary(); + PdfName style; + switch (borderType) { + case 1001: { + style = PdfAnnotation.STYLE_UNDERLINE; + break; + } + + case 1002: { + style = PdfAnnotation.STYLE_BEVELED; + break; + } + + case 1003: { + style = PdfAnnotation.STYLE_INSET; + break; + } + + case Border.DASHED_FIXED: + case Border.DASHED: + case Border.DOTTED: { + // Default dash array will be used. + style = PdfAnnotation.STYLE_DASHED; + break; + } + + default: { + style = PdfAnnotation.STYLE_SOLID; + break; + } + } + bs.Put(PdfName.S, style); + return bs; + } + + private BorderStyleUtil() { + } + // Private constructor. + } +} diff --git a/itext/itext.sign/itext/signatures/PdfSignatureAppearance.cs b/itext/itext.sign/itext/signatures/PdfSignatureAppearance.cs index 53f54cec26..58b9efa650 100644 --- a/itext/itext.sign/itext/signatures/PdfSignatureAppearance.cs +++ b/itext/itext.sign/itext/signatures/PdfSignatureAppearance.cs @@ -215,7 +215,7 @@ public virtual iText.Signatures.PdfSignatureAppearance SetPageRect(Rectangle pag /// /// /// layer 0. - [System.ObsoleteAttribute(@"will be deleted in the next major release. See iText.Forms.Fields.PdfSignatureFormField.SetBackgroundLayer(iText.Kernel.Pdf.Xobject.PdfFormXObject) ." + [System.ObsoleteAttribute(@"will be deleted in the next major release. See iText.Forms.Fields.PdfSignatureFormField.SetBackgroundLayer(iText.Kernel.Pdf.Xobject.PdfFormXObject) . Note that it should be called for the field retrieved with PdfSigner.GetSignatureField() method." )] public virtual PdfFormXObject GetLayer0() { if (n0 == null) { @@ -233,7 +233,7 @@ public virtual PdfFormXObject GetLayer0() { /// /// /// layer 2. - [System.ObsoleteAttribute(@"will be deleted in the next major release. See iText.Forms.Fields.PdfSignatureFormField.SetSignatureAppearanceLayer(iText.Kernel.Pdf.Xobject.PdfFormXObject) ." + [System.ObsoleteAttribute(@"will be deleted in the next major release. See iText.Forms.Fields.PdfSignatureFormField.SetSignatureAppearanceLayer(iText.Kernel.Pdf.Xobject.PdfFormXObject) . Note that it should be called for the field retrieved with PdfSigner.GetSignatureField() method." )] public virtual PdfFormXObject GetLayer2() { if (n2 == null) { @@ -393,7 +393,7 @@ public virtual iText.Signatures.PdfSignatureAppearance SetSignatureGraphic(Image /// Indicates that the existing appearances needs to be reused as a background layer. /// is an appearances reusing flag value to set. /// this instance to support fluent interface. - [System.ObsoleteAttribute(@"in favour of iText.Forms.Fields.PdfSignatureFormField.SetReuseAppearance(bool) ." + [System.ObsoleteAttribute(@"in favour of iText.Forms.Fields.PdfSignatureFormField.SetReuseAppearance(bool) . Note that it should be called for the field retrieved with PdfSigner.GetSignatureField() method." )] public virtual iText.Signatures.PdfSignatureAppearance SetReuseAppearance(bool reuseAppearance) { this.reuseAppearance = reuseAppearance; diff --git a/itext/itext.sign/itext/signatures/PdfSigner.cs b/itext/itext.sign/itext/signatures/PdfSigner.cs index 1fe4df4979..7026046a1f 100644 --- a/itext/itext.sign/itext/signatures/PdfSigner.cs +++ b/itext/itext.sign/itext/signatures/PdfSigner.cs @@ -30,12 +30,15 @@ You should have received a copy of the GNU Affero General Public License using iText.Forms; using iText.Forms.Fields; using iText.Forms.Form.Element; +using iText.Forms.Util; using iText.IO.Source; using iText.IO.Util; using iText.Kernel.Exceptions; +using iText.Kernel.Font; using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Kernel.Pdf.Annot; +using iText.Layout.Properties; using iText.Pdfa; using iText.Signatures.Cms; using iText.Signatures.Exceptions; @@ -1062,7 +1065,7 @@ protected internal virtual PdfSigFieldLock CreateNewSignatureFormField(PdfAcroFo sigField.DisableFieldRegeneration(); sigField.SetReuseAppearance(appearance.IsReuseAppearance()).SetSignatureAppearanceLayer(appearance.GetSignatureAppearanceLayer ()).SetBackgroundLayer(appearance.GetBackgroundLayer()); - sigField.GetFirstFormAnnotation().SetFormFieldElement(appearance.GetSignatureAppearance()); + ApplyDefaultPropertiesForTheNewField(sigField); sigField.EnableFieldRegeneration(); acroForm.AddField(sigField, document.GetPage(pagen)); if (acroForm.GetPdfObject().IsIndirect()) { @@ -1318,7 +1321,6 @@ private bool IsDocumentPdf2() { private PdfSignature CreateSignatureDictionary(bool includeDate) { PdfSignature dic = new PdfSignature(); - PdfSignatureAppearance appearance = GetSignatureAppearance(); dic.SetReason(GetReason()); dic.SetLocation(GetLocation()); dic.SetSignatureCreator(GetSignatureCreator()); @@ -1330,6 +1332,32 @@ private PdfSignature CreateSignatureDictionary(bool includeDate) { return dic; } + private void ApplyDefaultPropertiesForTheNewField(PdfSignatureFormField sigField) { + SignatureFieldAppearance formFieldElement = appearance.GetSignatureAppearance(); + PdfFormAnnotation annotation = sigField.GetFirstFormAnnotation(); + annotation.SetFormFieldElement(formFieldElement); + // Apply default field properties: + sigField.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_NONE); + sigField.SetJustification(formFieldElement.GetProperty(Property.TEXT_ALIGNMENT)); + Object retrievedFont = formFieldElement.GetProperty(Property.FONT); + if (retrievedFont is PdfFont) { + sigField.SetFont((PdfFont)retrievedFont); + } + UnitValue fontSize = formFieldElement.GetProperty(Property.FONT_SIZE); + if (fontSize != null && fontSize.IsPointValue()) { + sigField.SetFontSize(fontSize.GetValue()); + } + TransparentColor color = formFieldElement.GetProperty(Property.FONT_COLOR); + if (color != null) { + sigField.SetColor(color.GetColor()); + } + BorderStyleUtil.ApplyBorderProperty(formFieldElement, annotation); + Background background = formFieldElement.GetProperty(Property.BACKGROUND); + if (background != null) { + sigField.GetFirstFormAnnotation().SetBackgroundColor(background.GetColor()); + } + } + /// An interface to retrieve the signature dictionary for modification. public interface ISignatureEvent { /// Allows modification of the signature dictionary. diff --git a/port-hash b/port-hash index ca523e832c..372f185e3a 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -d89c0a8ccde6a80a3d53726a492d5bd17bdf386b +ecf88c810539f222870c3596432d09afa3911d4a