PdfFileSignature

Inheritance: java.lang.Object, com.aspose.pdf.facades.IVentureLicenseTarget, com.aspose.pdf.facades.Facade, com.aspose.pdf.facades.SaveableFacade

public final class PdfFileSignature extends SaveableFacade

Represents a class to sign a pdf file with a certificate.

Constructors

ConstructorDescription
PdfFileSignature()The constructor of PdfFileSignature class.
PdfFileSignature(String inputFile)The constructor of PdfFileSignature class.
PdfFileSignature(String inputFile, String outputFile)The constructor of PdfFileSignature class.
PdfFileSignature(IDocument document)Initializes new PdfFileSignature object on base of the document .
PdfFileSignature(IDocument document, String outputFile)Initializes new PdfFileSignature object on base of the document .

Methods

MethodDescription
getSignatureAppearance()Gets a graphic appearance for the signature.
setSignatureAppearance(String value)Sets a graphic appearance for the signature.
isLtvEnabled()Gets the LTV enabled flag.
bindPdf(String inputFile)Binds a Pdf file for editing.
bindPdf(InputStream inputStream)Binds a Pdf stream for editing.
save(String outputFile)Saves the result PDF to file.
save(OutputStream outputStream)Saves the result PDF to stream.
sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect)Make a signature on the pdf document.
sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)Sign the document with the given type signature.
sign(int page, boolean visible, Rectangle annotRect, Signature sig)Sign the document with the given type signature.
sign(String SigName, String SigReason, String SigContact, String SigLocation, Signature sig)Sign the document with the given type signature which is placed in already presented signature field.
sign(int page, String SigName, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)Sign the document with the given type signature which is placed in already presented signature field.
sign(String SigName, Signature sig)Sign the document with the given type signature which is placed in already presented signature field.
isCertified()Gets the flag determining whether a document is certified or not.
getAccessPermissions()Returns the access permissions value of certified document by the MDP signature type.
certify(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, DocMDPSignature docMdpSignature)Certify the document with the MDP signature.
certify(String sigName, DocMDPSignature docMdpSignature)Certify the document with the MDP signature which is placed in already presented signature field.
getSignNames()Gets the names of all not empty signatures.
getSignNames(boolean onlyActive)Gets the names of all not empty signatures.
getBlankSignNames()Gets the names of all empty signature fields.
isContainSignature()Checks if the pdf has a digital signature or not.
containsSignature()Checks if the pdf has a digital signature or not.
containsUsageRights()Checks if the pdf has a usage rights or not.
isCoversWholeDocument(String signName)Checks if the signature covers the whole document.
coversWholeDocument(String signName)Checks if the signature covers the whole document.
getRevision(String signName)Gets the revision of a signature.
getTotalRevision()Gets the toltal revision.
removeUsageRights()Removes the usage rights entry.
removeSignature(String signName)Remove the signature according to the name of the signature.
removeSignature(String signName, boolean removeField)Removes the signature according to the name of the signature.
removeSignatures()Removes all signatures.
verifySigned(String signName)Checks the validity of a signature.
getSignerName(String signName)Gets the name of person or organization who signing the pdf document.
getDateTime(String signName)Gets the signature’s datetime.
getReason(String signName)Gets the reason of a signature.
getLocation(String signName)Gets the location of a signature.
getContactInfo(String signName)Gets the contact information of a signature.
verifySignature(String signName)Checks the validity of a signature.
extractImage(String signName)Extracts signature’s image.
extractCertificate(String signName)Extracts signature’s single X.509 certificate as a stream.
save()Save signed pdf file.
setCertificate(String pfx, String pass)Set certificate file and password for signing routine.
getSignatureAppearanceStream()Gets a graphic appearance for the signature.
setSignatureAppearanceStream(InputStream value)Sets a graphic appearance for the signature.
close()Closes the facade.
dispose()Closes the facade.

PdfFileSignature()

public PdfFileSignature()

The constructor of PdfFileSignature class.

PdfFileSignature(String inputFile)

public PdfFileSignature(String inputFile)

The constructor of PdfFileSignature class.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file for signature.

PdfFileSignature(String inputFile, String outputFile)

public PdfFileSignature(String inputFile, String outputFile)

The constructor of PdfFileSignature class.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe input file for signature.
outputFilejava.lang.StringThe output file.

PdfFileSignature(IDocument document)

public PdfFileSignature(IDocument document)

Initializes new PdfFileSignature object on base of the document .

Parameters:

ParameterTypeDescription
documentIDocumentPdf document.

PdfFileSignature(IDocument document, String outputFile)

public PdfFileSignature(IDocument document, String outputFile)

Initializes new PdfFileSignature object on base of the document .

Parameters:

ParameterTypeDescription
documentIDocumentPdf document.
outputFilejava.lang.StringThe output file.

getSignatureAppearance()

public String getSignatureAppearance()

Gets a graphic appearance for the signature. Property value represents image file name.

Returns: java.lang.String - String value

setSignatureAppearance(String value)

public void setSignatureAppearance(String value)

Sets a graphic appearance for the signature. Property value represents image file name.

Parameters:

ParameterTypeDescription
valuejava.lang.StringString value

isLtvEnabled()

public final boolean isLtvEnabled()

Gets the LTV enabled flag.

Returns: boolean - boolean value

bindPdf(String inputFile)

public void bindPdf(String inputFile)

Binds a Pdf file for editing.

Parameters:

ParameterTypeDescription
inputFilejava.lang.StringThe pdf file to be edited.

bindPdf(InputStream inputStream)

public void bindPdf(InputStream inputStream)

Binds a Pdf stream for editing.

Parameters:

ParameterTypeDescription
inputStreamjava.io.InputStreamThe pdf stream to be edited.

save(String outputFile)

public void save(String outputFile)

Saves the result PDF to file.

Parameters:

ParameterTypeDescription
outputFilejava.lang.Stringoutput pdf file

save(OutputStream outputStream)

public void save(OutputStream outputStream)

Saves the result PDF to stream.

Parameters:

ParameterTypeDescription
outputStreamjava.io.OutputStreamoutput pdf stream

sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect)

public void sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect)

Make a signature on the pdf document.

String inFile = TestPath + "example1.pdf";
 String outFile = TestPath + "signature.pdf";
 PdfFileSignature pdfSign = new PdfFileSignature();
 pdfSign.bindPdf(inFile);
 Rectangle rect = new Rectangle(100, 100, 200, 200);
 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg");
 pdfSign.setCertificate("certificate.pfx", "password");
 pdfSign.sign(2, "Allen", "success", "ChangSha", true, rect);
 pdfSign.save(outFile);

Parameters:

ParameterTypeDescription
pageintThe page number on which signature is made.
SigReasonjava.lang.StringThe reason of signature.
SigContactjava.lang.StringThe contact of signature.
SigLocationjava.lang.StringThe location of signature.
visiblebooleanThe visiblity of signature.
annotRectjava.awt.RectangleThe rect of signature.

sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)

public void sign(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)

Sign the document with the given type signature.


String inFile = TestPath + "example1.pdf";
 String outFile = TestPath + "signature.pdf";
 PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile);
 Rectangle rect = new Rectangle(100, 100, 200, 100);
 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg");
 pdfSign.sign(2, "Allen", "success", "ChangSha", true, rect, new PKCS1("certificate.pfx", "password"));
 pdfSign.save();

Parameters:

ParameterTypeDescription
pageintThe page number on which signature is made.
SigReasonjava.lang.StringThe reason of signature.
SigContactjava.lang.StringThe contact of signature.
SigLocationjava.lang.StringThe location of signature.
visiblebooleanThe visiblity of signature.
annotRectjava.awt.RectangleThe rect of signature.
sigSignatureThe type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.

sign(int page, boolean visible, Rectangle annotRect, Signature sig)

public void sign(int page, boolean visible, Rectangle annotRect, Signature sig)

Sign the document with the given type signature.


String inFile = TestPath + "example1.pdf";
 String outFile = TestPath + "signature.pdf";
 PKCS1 sig = new PKCS1("certificate.pfx", "password");
 sig.setReason ( "Some reason");
 sig.setContact ( "Smith");
 sig.setLocation ( "New York");
 PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile);
 Rectangle rect = new Rectangle(100, 100, 200, 100);
 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg");
 pdfSign.sign(2, true, rect, sig);
 pdfSign.save();

Parameters:

ParameterTypeDescription
pageintThe page number on which signature is made.
visiblebooleanThe visiblity of signature.
annotRectjava.awt.RectangleThe rect of signature.
sigSignatureThe type of the signature, could be PKCS1, PKCS7 and PKCS7Detached. Such data as signature reason, contact and location must be already present in this object (see corresponding properties).

sign(String SigName, String SigReason, String SigContact, String SigLocation, Signature sig)

public void sign(String SigName, String SigReason, String SigContact, String SigLocation, Signature sig)

Sign the document with the given type signature which is placed in already presented signature field. Before signing signature field must be empty, i.e. field must not contain signature dictionary. Thus pdf document already has signature field, you should not supply the place to stamp the signature, corresponding page and rectangle are taken from signature field which is found by signature name (see SigName parameter).


String inFile = TestPath + "example1.pdf";
 String outFile = TestPath + "signature.pdf";
 PKCS1 sig = new PKCS1("certificate.pfx", "password");
 PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile);
 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg");
 pdfSign.sign("Signature1", "Allen", "success", "ChangSha", sig);
 pdfSign.save();

Parameters:

ParameterTypeDescription
SigNamejava.lang.StringThe name of the signature field.
SigReasonjava.lang.StringThe reason of signature.
SigContactjava.lang.StringThe contact of signature.
SigLocationjava.lang.StringThe location of signature.
sigSignatureThe type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.

sign(int page, String SigName, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)

public void sign(int page, String SigName, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, Signature sig)

Sign the document with the given type signature which is placed in already presented signature field. Before signing pdf document should already has signature field, corresponding page and rectangle are taken from signature field which is found by signature name (see SigName parameter).


String inFile = TestPath + "blankWithSignature.pdf";
 String outFile = TestPath + "signature.pdf";
 PKCS7 sig = new PKCS7("certificate.pfx", "password");
 PdfFileSignature pdfSign = new PdfFileSignature(inFile);
 Rectangle rect = new Rectangle(100, 100, 100, 100);
 pdfSign.setSignatureAppearance( TestPath + "butterfly.jpg");
 pdfSign.sign(1, "Signature1", "ReasonToTest", "ContactMe", "SomeLocation", true, rect, sig);
 pdfSign.save(outFile);

Parameters:

ParameterTypeDescription
pageintThe page number on which signature is made.
SigNamejava.lang.StringThe name of the signature field.
SigReasonjava.lang.StringThe reason of signature.
SigContactjava.lang.StringThe contact of signature.
SigLocationjava.lang.StringThe location of signature.
visiblebooleanThe visiblity of signature.
annotRectjava.awt.RectangleThe rect of signature.
sigSignatureThe type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.

sign(String SigName, Signature sig)

public void sign(String SigName, Signature sig)

Sign the document with the given type signature which is placed in already presented signature field. Before signing signature field must be empty, i.e. field must not contain signature dictionary. Thus pdf document already has signature field, you should not supply the place to stamp the signature, corresponding page and rectangle are taken from signature field which is found by signature name (see SigName parameter). Such data as signature reason, contact and location must be provided by corresponding properties of the Signature object sig.


String inFile = TestPath + "example1.pdf";
 String outFile = TestPath + "signature.pdf";
 PKCS1 sig = new PKCS1("certificate.pfx", "password");
 sig.setReason ( "Some reason");
 sig.setContact ( "Smith");
 sig.setLocation ( "New York");
 PdfFileSignature pdfSign = new PdfFileSignature(inFile, outFile);
 pdfSign.setSignatureAppearance ( TestPath + "butterfly.jpg");
 pdfSign.sign("Signature1", sig);
 pdfSign.save();

Parameters:

ParameterTypeDescription
SigNamejava.lang.StringThe name of the signature field.
sigSignatureThe type of the signature, could be PKCS1 (Pkcs1Signature object), PKCS7 and PKCS7 detached (Pkcs7Signature object)

isCertified()

public boolean isCertified()

Gets the flag determining whether a document is certified or not.

Returns: boolean - boolean value

getAccessPermissions()

public int getAccessPermissions()

Returns the access permissions value of certified document by the MDP signature type.

Returns: int - If the document is being certified, than returns access permissions value; otherwise, is thrown.

certify(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, DocMDPSignature docMdpSignature)

public void certify(int page, String SigReason, String SigContact, String SigLocation, boolean visible, Rectangle annotRect, DocMDPSignature docMdpSignature)

Certify the document with the MDP signature. Such data as signature reason, contact and location must be provided by corresponding properties of the Signature object sig.

Parameters:

ParameterTypeDescription
pageintThe page on which signature is made.
SigReasonjava.lang.StringThe reason of signature.
SigContactjava.lang.StringThe contact of signature.
SigLocationjava.lang.StringThe location of signature.
visiblebooleanThe visiblity of signature.
annotRectjava.awt.RectangleThe rect of signature.
docMdpSignatureDocMDPSignatureThe document MDP type of the signature.

certify(String sigName, DocMDPSignature docMdpSignature)

public final void certify(String sigName, DocMDPSignature docMdpSignature)

Certify the document with the MDP signature which is placed in already presented signature field. Before signing signature field must be empty, i.e. field must not contain signature dictionary. Thus pdf document already has signature field, you should not supply the place to stamp the signature, corresponding page and rectangle are taken from signature field which is found by signature name (see sigName parameter).

Parameters:

ParameterTypeDescription
sigNamejava.lang.StringThe name of the signature field.
docMdpSignatureDocMDPSignatureThe type of the signature, could be PKCS1, PKCS7 and PKCS7Detached

getSignNames()

public final List<String> getSignNames()

Gets the names of all not empty signatures.


Returns: java.util.List<java.lang.String> - Return a arrayList.

getSignNames(boolean onlyActive)

public List<String> getSignNames(boolean onlyActive)

Gets the names of all not empty signatures.


String inFile=TestPath + "example1.pdf";
  PdfFileSignature pdfSign=new PdfFileSignature();
  pdfSign.bindPdf(inFile);
  ArrayList names=pdfSign.getSignNames(true);
 for(int i=0;i<names.Count;i++)
 {
   System.out.println("signature name:"+(String)names[i]);
   System.out.println("coverswholedocument:"+pdfSign.IsCoversWholeDocument((String)names[i]));
   System.out.println("revision:"+pdfSign.GetRevision((String)names[i]));
   System.out.println("verifysigned:"+pdfSign.VerifySigned((String)names[i]));
   System.out.println("reason:"+pdfSign.GetReason((String)names[i]));
   System.out.println("location:"+pdfSign.GetLocation((String)names[i]));
   System.out.println("datatime:"+pdfSign.GetDateTime((String)names[i]));
  }
  System.out.println("totalvision:"+pdfSign.GetTotalRevision());

Parameters:

ParameterTypeDescription
onlyActivebooleanboolean value, if true, return only active signatures; otherwise, return all signatures.

Returns: java.util.List<java.lang.String> - Return a arrayList.

getBlankSignNames()

public List<String> getBlankSignNames()

Gets the names of all empty signature fields.

Returns: java.util.List<java.lang.String> - Return a arrayList.

isContainSignature()

public boolean isContainSignature()

Checks if the pdf has a digital signature or not.

Returns: boolean - Return a result of bool type.

containsSignature()

public boolean containsSignature()

Checks if the pdf has a digital signature or not.

Returns: boolean - Return a result of bool type.

containsUsageRights()

public boolean containsUsageRights()

Checks if the pdf has a usage rights or not.

Returns: boolean - Returns a result of bool type.

isCoversWholeDocument(String signName)

public boolean isCoversWholeDocument(String signName)

Checks if the signature covers the whole document.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: boolean - Return a result of bool type.

coversWholeDocument(String signName)

public boolean coversWholeDocument(String signName)

Checks if the signature covers the whole document.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: boolean - Return a result of bool type.

getRevision(String signName)

public int getRevision(String signName)

Gets the revision of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: int - Return the number of signature revision.

getTotalRevision()

public int getTotalRevision()

Gets the toltal revision.

Returns: int - Return the total number of signature revision.

removeUsageRights()

public void removeUsageRights()

Removes the usage rights entry.

removeSignature(String signName)

public void removeSignature(String signName)

Remove the signature according to the name of the signature.


String inFile = TestPath + "example1.pdf";
 PdfFileSignature pdfSign = new PdfFileSignature();
 pdfSign.bindPdf(inFile);
 List names = pdfSign.getSignNames();
 for(int i = 0; i < names.size(); i++)
 {
    pdfSign.removeSignature((String)names.get(i));
 }
 pdfSign.save(TestPath + "signed_removed.pdf");

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

removeSignature(String signName, boolean removeField)

public void removeSignature(String signName, boolean removeField)

Removes the signature according to the name of the signature.


String inFile = TestPath + "example1.pdf";
 PdfFileSignature pdfSign = new PdfFileSignature();
 pdfSign.BindPdf(inFile);
 List names = pdfSign.getSignNames();
 for(int i = 0; i < names.size(); i++)
 {
    pdfSign.removeSignature((String)names.get(i), false);
 }
 pdfSign.save(TestPath + "signed_removed.pdf");

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.
removeFieldbooleanIf set to true, than removes both of signature and field from document; otherwise, signature only.

removeSignatures()

public final void removeSignatures()

Removes all signatures.

string inFile = TestPath + "example1.pdf";
 var pdfSign = new PdfFileSignature();
 pdfSign.bindPdf(inFile);
 pdfSign.removeSignatures();
 pdfSign.save(TestPath + "signed_removed.pdf");

verifySigned(String signName)

public boolean verifySigned(String signName)

Checks the validity of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: boolean - Return a result of bool type.

getSignerName(String signName)

public String getSignerName(String signName)

Gets the name of person or organization who signing the pdf document.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.lang.String - Returns the result of the signer’s name.

getDateTime(String signName)

public Date getDateTime(String signName)

Gets the signature’s datetime.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: Date - Return the result of DateTime type.

getReason(String signName)

public String getReason(String signName)

Gets the reason of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.lang.String - Returns a result of String type.

getLocation(String signName)

public String getLocation(String signName)

Gets the location of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.lang.String - Returns a result of String type.

getContactInfo(String signName)

public String getContactInfo(String signName)

Gets the contact information of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.lang.String - Returns a result of String type.

verifySignature(String signName)

public boolean verifySignature(String signName)

Checks the validity of a signature.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: boolean - Return a result of bool type.

extractImage(String signName)

public InputStream extractImage(String signName)

Extracts signature’s image.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.io.InputStream - If image was successfully found than returns stream object; otherwise, null.

extractCertificate(String signName)

public InputStream extractCertificate(String signName)

Extracts signature’s single X.509 certificate as a stream.

Parameters:

ParameterTypeDescription
signNamejava.lang.StringThe name of signature.

Returns: java.io.InputStream - If certificate was found returns X.509 single certificate; otherwise, null.

save()

public void save()

Save signed pdf file. Output filename must be provided before with the help of coresponding PdfFileSignature constructor.

setCertificate(String pfx, String pass)

public void setCertificate(String pfx, String pass)

Set certificate file and password for signing routine.

Parameters:

ParameterTypeDescription
pfxjava.lang.StringPKCS #12 certificate file.
passjava.lang.StringPassword to get access for the certificate private key.

getSignatureAppearanceStream()

public InputStream getSignatureAppearanceStream()

Gets a graphic appearance for the signature. Property value represents image stream.

Returns: java.io.InputStream - InputStream element

setSignatureAppearanceStream(InputStream value)

public void setSignatureAppearanceStream(InputStream value)

Sets a graphic appearance for the signature. Property value represents image stream.

Parameters:

ParameterTypeDescription
valuejava.io.InputStreamInputStream element

close()

public void close()

Closes the facade.

dispose()

public void dispose()

Closes the facade. This method is obsolete, use close() instead.