Class PdfSignatureAppearance
- Namespace
- iTextSharp.text.pdf
- Assembly
- iTextSharp.LGPLv2.Core.dll
This class takes care of the cryptographic options and appearances that form a signature.
public class PdfSignatureAppearance
- Inheritance
-
PdfSignatureAppearance
- Inherited Members
Fields
CERTIFIED_FORM_FILLING
public const int CERTIFIED_FORM_FILLING = 2
Field Value
CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
public const int CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 3
Field Value
CERTIFIED_NO_CHANGES_ALLOWED
public const int CERTIFIED_NO_CHANGES_ALLOWED = 1
Field Value
NOT_CERTIFIED
public const int NOT_CERTIFIED = 0
Field Value
SelfSigned
The self signed filter.
public static PdfName SelfSigned
Field Value
VerisignSigned
The VeriSign filter.
public static PdfName VerisignSigned
Field Value
WincerSigned
The Windows Certificate Security.
public static PdfName WincerSigned
Field Value
questionMark
Commands to draw a yellow question mark in a stream content
public const string questionMark = "% DSUnknown\nq\n1 G\n1 g\n0.1 0 0 0.1 9 0 cm\n0 J 0 j 4 M []0 d\n1 i \n0 g\n313 292 m\n313 404 325 453 432 529 c\n478 561 504 597 504 645 c\n504 736 440 760 391 760 c\n286 760 271 681 265 626 c\n265 625 l\n100 625 l\n100 828 253 898 381 898 c\n451 898 679 878 679 650 c\n679 555 628 499 538 435 c\n488 399 467 376 467 292 c\n313 292 l\nh\n308 214 170 -164 re\nf\n0.44 G\n1.2 w\n1 1 0.4 rg\n287 318 m\n287 430 299 479 406 555 c\n451 587 478 623 478 671 c\n478 762 414 786 365 786 c\n260 786 245 707 239 652 c\n239 651 l\n74 651 l\n74 854 227 924 355 924 c\n425 924 653 904 653 676 c\n653 581 602 525 512 461 c\n462 425 441 402 441 318 c\n287 318 l\nh\n282 240 170 -164 re\nB\nQ\n"
Field Value
Properties
Acro6Layers
Acrobat 6.0 and higher recomends that only layer n2 and n4 be present. This method sets that mode.
public bool Acro6Layers { get; set; }
Property Value
CertChain
Gets the certificate chain.
public X509Certificate[] CertChain { get; }
Property Value
- X509Certificate[]
the certificate chain
CertificationLevel
Sets the document type to certified instead of simply signed. CERTIFIED_FORM_FILLING and CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
public int CertificationLevel { get; set; }
Property Value
Contact
Sets the signing contact.
public string Contact { get; set; }
Property Value
CrlList
Gets the certificate revocation list.
public object[] CrlList { get; }
Property Value
- object[]
the certificate revocation list
CryptoDictionary
Gets the user made signature dictionary. This is the dictionary at the /V key.
public PdfDictionary CryptoDictionary { get; set; }
Property Value
- PdfDictionary
the user made signature dictionary
FieldName
Gets the field name.
public string FieldName { get; }
Property Value
- string
the field name
Filter
Gets the filter used to sign the document.
public PdfName Filter { get; }
Property Value
- PdfName
the filter used to sign the document
Image
Sets the background image for the layer 2.
public Image Image { get; set; }
Property Value
ImageScale
Sets the scaling to be applied to the background image. If it's zero the image will fully fill the rectangle. If it's less than zero the image will fill the rectangle but will keep the proportions. If it's greater than zero that scaling will be applied. In any of the cases the image will always be centered. It's zero by default.
public float ImageScale { get; set; }
Property Value
Layer2Font
Sets the n2 and n4 layer font. If the font size is zero, auto-fit will be used.
public Font Layer2Font { get; set; }
Property Value
Layer2Text
Sets the signature text identifying the signer. a standard description will be used
public string Layer2Text { get; set; }
Property Value
Layer4Text
Sets the text identifying the signature status. the description "Signature Not Verified" will be used
public string Layer4Text { get; set; }
Property Value
Location
Sets the signing location.
public string Location { get; set; }
Property Value
Page
Gets the page number of the field.
public int Page { get; }
Property Value
- int
the page number of the field
PageRect
Gets the rectangle that represent the position and dimension of the signature in the page.
public Rectangle PageRect { get; }
Property Value
- Rectangle
the rectangle that represent the position and dimension of the signature in the page
PrivKey
Gets the private key.
public ICipherParameters PrivKey { get; }
Property Value
- ICipherParameters
the private key
RangeStream
Gets the document bytes that are hashable when using external signatures. The general sequence is: PreClose(), GetRangeStream() and Close().
public Stream RangeStream { get; }
Property Value
- Stream
the document bytes that are hashable
Reason
Sets the signing reason.
public string Reason { get; set; }
Property Value
Rect
Gets the rectangle representing the signature dimensions. or have zero width or height for invisible signatures
public Rectangle Rect { get; }
Property Value
- Rectangle
the rectangle representing the signature dimensions. It may be null
Render
Gets the rendering mode for this signature .
public PdfSignatureAppearance.SignatureRender Render { get; set; }
Property Value
- PdfSignatureAppearance.SignatureRender
the rectangle rendering mode for this signature.
RunDirection
Sets the run direction in the n2 and n4 layer.
public int RunDirection { get; set; }
Property Value
SigStandard
Gets the instance of the standard signature dictionary. This instance is only available after pre close. The main use is to insert external signatures.
public PdfSigGenericPkcs SigStandard { get; }
Property Value
- PdfSigGenericPkcs
the instance of the standard signature dictionary
SignDate
Gets the signature date.
public DateTime SignDate { get; set; }
Property Value
- DateTime
the signature date
SignatureEvent
Sets the signature event to allow modification of the signature dictionary.
public PdfSignatureAppearance.ISignatureEvent SignatureEvent { get; set; }
Property Value
SignatureGraphic
Sets the Image object to render when Render is set to SignatureRender.GraphicAndDescription to SignatureRender.Description
public Image SignatureGraphic { get; set; }
Property Value
Stamper
Gets the PdfStamper associated with this instance.
public PdfStamper Stamper { get; }
Property Value
- PdfStamper
the PdfStamper associated with this instance
TempFile
Gets the temporary file.
public string TempFile { get; }
Property Value
- string
the temporary file or null is the document is created in memory
Methods
Close(PdfDictionary)
This is the last method to be called when using external signatures. The general sequence is: PreClose(), GetDocumentBytes() and Close(). update is a PdfDictionary that must have exactly the same keys as the ones provided in {@link #preClose(Hashtable)}. in {@link #preClose(Hashtable)} @throws DocumentException on error @throws IOException on error
public void Close(PdfDictionary update)
Parameters
update
PdfDictionarya PdfDictionary with the key/value that will fill the holes defined
FitText(Font, string, Rectangle, float, int)
Fits the text to some rectangle adjusting the font size as needed.
public static float FitText(Font font, string text, Rectangle rect, float maxFontSize, int runDirection)
Parameters
font
Fontthe font to use
text
stringthe text
rect
Rectanglethe rectangle where the text must fit
maxFontSize
floatthe maximum font size
runDirection
intthe run direction
Returns
- float
the calculated font size that makes the text fit
GetAppearance()
Gets the main appearance layer. Consult PPKAppearances.pdf for further details. @throws DocumentException on error @throws IOException on error
public PdfTemplate GetAppearance()
Returns
- PdfTemplate
the main appearance layer
GetImage()
Gets the background image for the layer 2.
public Image GetImage()
Returns
- Image
the background image for the layer 2
GetLayer(int)
Gets a template layer to create a signature appearance. The layers can go from 0 to 4. Consult PPKAppearances.pdf for further details.
public PdfTemplate GetLayer(int layer)
Parameters
layer
intthe layer
Returns
- PdfTemplate
a template
GetNewSigName()
Gets a new signature fied name that doesn't clash with any existing name.
public string GetNewSigName()
Returns
- string
a new signature fied name
GetTopLayer()
Gets the template that aggregates all appearance layers. This corresponds to the /FRM resource. Consult PPKAppearances.pdf for further details.
public PdfTemplate GetTopLayer()
Returns
- PdfTemplate
the template that aggregates all appearance layers
IsInvisible()
Gets the visibility status of the signature.
public bool IsInvisible()
Returns
- bool
the visibility status of the signature
IsNewField()
Checks if a new field was created. an existing field or if the signature is invisible
public bool IsNewField()
Returns
- bool
true if a new field was created, false if signing
IsPreClosed()
Checks if the document is in the process of closing. false otherwise
public bool IsPreClosed()
Returns
- bool
true if the document is in the process of closing,
PreClose()
This is the first method to be called when using external signatures. The general sequence is: PreClose(), GetDocumentBytes() and Close(). If calling PreClose() dont't call PdfStamper.Close(). No external signatures are allowed if this methos is called. @throws IOException on error @throws DocumentException on error
public void PreClose()
PreClose(INullValueDictionary<PdfName, int>)
This is the first method to be called when using external signatures. The general sequence is: PreClose(), GetDocumentBytes() and Close(). If calling PreClose() dont't call PdfStamper.Close(). If using an external signature exclusionSizes must contain at least the PdfName.CONTENTS key with the size that it will take in the document. Note that due to the hex string coding this size should be byte_size*2+2. calculation. The key is a PdfName and the value an Integer . At least the PdfName.CONTENTS must be present @throws IOException on error @throws DocumentException on error
public void PreClose(INullValueDictionary<PdfName, int> exclusionSizes)
Parameters
exclusionSizes
INullValueDictionary<PdfName, int>a Hashtable with names and sizes to be excluded in the signature
SetCrypto(ICipherParameters, X509Certificate[], object[], PdfName)
Sets the cryptographic parameters.
public void SetCrypto(ICipherParameters privKey, X509Certificate[] certChain, object[] crlList, PdfName filter)
Parameters
privKey
ICipherParametersthe private key
certChain
X509Certificate[]the certificate chain
crlList
object[]the certificate revocation list. It may be null
filter
PdfNamethe crytographic filter type. It can be SELF_SIGNED, VERISIGN_SIGNED or WINCER_SIGNED
SetExternalDigest(byte[], byte[], string)
Sets the digest/signature to an external calculated value. is also null . If the digest is not null then it may be "RSA" or "DSA"
public void SetExternalDigest(byte[] digest, byte[] rsAdata, string digestEncryptionAlgorithm)
Parameters
digest
byte[]the digest. This is the actual signature
rsAdata
byte[]the extra data that goes into the data tag in PKCS#7
digestEncryptionAlgorithm
stringthe encryption algorithm. It may must be null if the digest
SetVisibleSignature(string)
Sets the signature to be visible. An empty signature field with the same name must already exist.
public void SetVisibleSignature(string fieldName)
Parameters
fieldName
stringthe existing empty signature field name
SetVisibleSignature(Rectangle, int, string)
Sets the signature to be visible. It creates a new visible signature field.
public void SetVisibleSignature(Rectangle pageRect, int page, string fieldName)