|
| 1 | +package com.itextpdf.signatures; |
| 2 | + |
| 3 | +import com.itextpdf.commons.utils.DateTimeUtil; |
| 4 | +import com.itextpdf.forms.PdfSigFieldLock; |
| 5 | +import com.itextpdf.forms.form.element.SignatureFieldAppearance; |
| 6 | +import com.itextpdf.kernel.geom.Rectangle; |
| 7 | + |
| 8 | +import java.util.Calendar; |
| 9 | + |
| 10 | +/** |
| 11 | + * Properties to be used in signing operations. |
| 12 | + */ |
| 13 | +public class SignerProperties { |
| 14 | + |
| 15 | + private PdfSigFieldLock fieldLock; |
| 16 | + private SignatureFieldAppearance appearance; |
| 17 | + private Calendar signDate = DateTimeUtil.getCurrentTimeCalendar(); |
| 18 | + private int certificationLevel = PdfSigner.NOT_CERTIFIED; |
| 19 | + private String fieldName; |
| 20 | + private int pageNumber = 1; |
| 21 | + private Rectangle pageRect = new Rectangle(0, 0); |
| 22 | + |
| 23 | + private String signatureCreator = ""; |
| 24 | + |
| 25 | + private String contact = ""; |
| 26 | + |
| 27 | + /** |
| 28 | + * Create instance of {@link SignerProperties}. |
| 29 | + */ |
| 30 | + public SignerProperties() { |
| 31 | + // Empty constructor. |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Gets the signature date. |
| 36 | + * |
| 37 | + * @return Calendar set to the signature date |
| 38 | + */ |
| 39 | + public java.util.Calendar getSignDate() { |
| 40 | + return signDate; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Sets the signature date. |
| 45 | + * |
| 46 | + * @param signDate the signature date |
| 47 | + */ |
| 48 | + public SignerProperties setSignDate(java.util.Calendar signDate) { |
| 49 | + this.signDate = signDate; |
| 50 | + return this; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Sets the signature field layout element to customize the appearance of the signature. Signer's sign date will |
| 55 | + * be set. |
| 56 | + * |
| 57 | + * @param appearance the {@link SignatureFieldAppearance} layout element. |
| 58 | + */ |
| 59 | + public SignerProperties setSignatureAppearance(SignatureFieldAppearance appearance) { |
| 60 | + this.appearance = appearance; |
| 61 | + return this; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Gets signature field layout element, which customizes the appearance of a signature. |
| 66 | + * |
| 67 | + * @return {@link SignatureFieldAppearance} layout element |
| 68 | + */ |
| 69 | + public SignatureFieldAppearance getSignatureAppearance() { |
| 70 | + return this.appearance; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the document's certification level. |
| 75 | + * For possible values see {@link #setCertificationLevel(int)}. |
| 76 | + * |
| 77 | + * @return The certified status. |
| 78 | + */ |
| 79 | + public int getCertificationLevel() { |
| 80 | + return this.certificationLevel; |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Sets the document's certification level. |
| 85 | + * |
| 86 | + * @param certificationLevel a new certification level for a document. |
| 87 | + * Possible values are: <ul> |
| 88 | + * <li>{@link PdfSigner#NOT_CERTIFIED} |
| 89 | + * <li>{@link PdfSigner#CERTIFIED_NO_CHANGES_ALLOWED} |
| 90 | + * <li>{@link PdfSigner#CERTIFIED_FORM_FILLING} |
| 91 | + * <li>{@link PdfSigner#CERTIFIED_FORM_FILLING_AND_ANNOTATIONS} |
| 92 | + * </ul> |
| 93 | + */ |
| 94 | + public SignerProperties setCertificationLevel(int certificationLevel) { |
| 95 | + this.certificationLevel = certificationLevel; |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Gets the field name. |
| 101 | + * |
| 102 | + * @return the field name |
| 103 | + */ |
| 104 | + public String getFieldName() { |
| 105 | + return fieldName; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Sets the name indicating the field to be signed. The field can already be presented in the |
| 110 | + * document but shall not be signed. If the field is not presented in the document, it will be created. |
| 111 | + * |
| 112 | + * @param fieldName The name indicating the field to be signed. |
| 113 | + */ |
| 114 | + public SignerProperties setFieldName(String fieldName) { |
| 115 | + this.fieldName = fieldName; |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Provides the page number of the signature field which this signature |
| 121 | + * appearance is associated with. |
| 122 | + * |
| 123 | + * @return The page number of the signature field which this signature |
| 124 | + * appearance is associated with. |
| 125 | + */ |
| 126 | + public int getPageNumber() { |
| 127 | + return this.pageNumber; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Sets the page number of the signature field which this signature |
| 132 | + * appearance is associated with. Implicitly calls {@link PdfSigner#setPageRect} |
| 133 | + * which considers page number to process the rectangle correctly. |
| 134 | + * |
| 135 | + * @param pageNumber The page number of the signature field which |
| 136 | + * this signature appearance is associated with. |
| 137 | + * |
| 138 | + * @return this instance to support fluent interface. |
| 139 | + */ |
| 140 | + public SignerProperties setPageNumber(int pageNumber) { |
| 141 | + this.pageNumber = pageNumber; |
| 142 | + return this; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Provides the rectangle that represent the position and dimension |
| 147 | + * of the signature field in the page. |
| 148 | + * |
| 149 | + * @return the rectangle that represent the position and dimension |
| 150 | + * of the signature field in the page |
| 151 | + */ |
| 152 | + public Rectangle getPageRect() { |
| 153 | + return this.pageRect; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Sets the rectangle that represent the position and dimension of |
| 158 | + * the signature field in the page. |
| 159 | + * |
| 160 | + * @param pageRect The rectangle that represents the position and |
| 161 | + * dimension of the signature field in the page. |
| 162 | + * |
| 163 | + * @return this instance to support fluent interface. |
| 164 | + */ |
| 165 | + public SignerProperties setPageRect(Rectangle pageRect) { |
| 166 | + this.pageRect = pageRect; |
| 167 | + return this; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Getter for the field lock dictionary. |
| 172 | + * |
| 173 | + * @return Field lock dictionary. |
| 174 | + */ |
| 175 | + public PdfSigFieldLock getFieldLockDict() { |
| 176 | + return fieldLock; |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * Setter for the field lock dictionary. |
| 181 | + * <p> |
| 182 | + * <strong>Be aware:</strong> if a signature is created on an existing signature field, |
| 183 | + * then its /Lock dictionary takes the precedence (if it exists). |
| 184 | + * |
| 185 | + * @param fieldLock Field lock dictionary |
| 186 | + */ |
| 187 | + public SignerProperties setFieldLockDict(PdfSigFieldLock fieldLock) { |
| 188 | + this.fieldLock = fieldLock; |
| 189 | + return this; |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * Returns the signature creator. |
| 194 | + * |
| 195 | + * @return The signature creator. |
| 196 | + */ |
| 197 | + public String getSignatureCreator() { |
| 198 | + return this.signatureCreator; |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Sets the name of the application used to create the signature. |
| 203 | + * |
| 204 | + * @param signatureCreator A new name of the application signing a document. |
| 205 | + * |
| 206 | + * @return this instance to support fluent interface. |
| 207 | + */ |
| 208 | + public SignerProperties setSignatureCreator(String signatureCreator) { |
| 209 | + this.signatureCreator = signatureCreator; |
| 210 | + return this; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Returns the signing contact. |
| 215 | + * |
| 216 | + * @return The signing contact. |
| 217 | + */ |
| 218 | + public String getContact() { |
| 219 | + return this.contact; |
| 220 | + } |
| 221 | + |
| 222 | + /** |
| 223 | + * Sets the signing contact. |
| 224 | + * |
| 225 | + * @param contact A new signing contact. |
| 226 | + * |
| 227 | + * @return this instance to support fluent interface. |
| 228 | + */ |
| 229 | + public SignerProperties setContact(String contact) { |
| 230 | + this.contact = contact; |
| 231 | + return this; |
| 232 | + } |
| 233 | +} |
0 commit comments