public final class PdfFileSignature extends SaveableFacade
Represents a class to sign a pdf file with a certificate.
Constructor and Description |
---|
PdfFileSignature()
The constructor of PdfFileSignature class.
|
PdfFileSignature(IDocument document)
Initializes new
PdfFileSignature object on base of the document . |
PdfFileSignature(IDocument document,
String outputFile)
Deprecated.
|
PdfFileSignature(String inputFile)
Deprecated.
|
PdfFileSignature(String inputFile,
String outputFile)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
bindPdf(InputStream inputStream)
Binds a Pdf stream for editing.
|
void |
bindPdf(String inputFile)
Binds a Pdf file for editing.
|
void |
certify(int page,
String SigReason,
String SigContact,
String SigLocation,
boolean visible,
Rectangle annotRect,
DocMDPSignature docMdpSignature)
Certify the document with the MDP signature.
|
void |
close()
Closes the facade.
|
boolean |
containsSignature()
Checks if the pdf has a digital signature or not.
|
boolean |
containsUsageRights()
Checks if the pdf has a usage rights or not.
|
boolean |
coversWholeDocument(String signName)
Checks if the signature covers the whole document.
|
void |
dispose()
Closes the facade.
|
InputStream |
extractCertificate(String signName)
Extracts signature's single X.509 certificate as a stream.
|
InputStream |
extractImage(String signName)
Extracts signature's image.
|
int |
getAccessPermissions()
Returns the access permissions value of certified document by the MDP signature type.
|
List<String> |
getBlankSignNames()
Gets the names of all empty signature fields.
|
String |
getContactInfo(String signName)
Gets the contact information of a signature.
|
Date |
getDateTime(String signName)
Gets the signature's datetime.
|
String |
getLocation(String signName)
Gets the location of a signature.
|
String |
getReason(String signName)
Gets the reason of a signature.
|
int |
getRevision(String signName)
Gets the revision of a signature.
|
String |
getSignatureAppearance()
Gets a graphic appearance for the signature.
|
InputStream |
getSignatureAppearanceStream()
Gets a graphic appearance for the signature.
|
String |
getSignerName(String signName)
Gets the name of person or organization who signing the pdf document.
|
List<String> |
getSignNames()
Gets the names of all not empty signatures.
|
int |
getTotalRevision()
Gets the toltal revision.
|
boolean |
isCertified()
Gets the flag determining whether a document is certified or not.
|
boolean |
isContainSignature()
Deprecated.
|
boolean |
isCoversWholeDocument(String signName)
Deprecated.
|
void |
removeSignature(String signName)
Remove the signature according to the name of the signature.
|
void |
removeSignature(String signName,
boolean removeField)
Removes the signature according to the name of the signature.
|
void |
removeUsageRights()
Removes the usage rights entry.
|
void |
save()
Deprecated.
|
void |
save(OutputStream outputStream)
Saves the result PDF to stream.
|
void |
save(String outputFile)
Saves the result PDF to file.
|
void |
setCertificate(String pfx,
String pass)
Set certificate file and password for signing routine.
|
void |
setSignatureAppearance(String value)
Sets a graphic appearance for the signature.
|
void |
setSignatureAppearanceStream(InputStream value)
Sets a graphic appearance for the signature.
|
void |
sign(int page,
boolean visible,
Rectangle annotRect,
Signature sig)
Sign the document with the given type signature.
|
void |
sign(int page,
String SigReason,
String SigContact,
String SigLocation,
boolean visible,
Rectangle annotRect)
Make a signature on the pdf document.
|
void |
sign(int page,
String SigReason,
String SigContact,
String SigLocation,
boolean visible,
Rectangle annotRect,
Signature sig)
Sign the document with the given type signature.
|
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.
|
void |
sign(String SigName,
Signature sig)
Sign the document with the given type signature which is placed in already presented
signature field.
|
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.
|
boolean |
verifySignature(String signName)
Checks the validity of a signature.
|
boolean |
verifySigned(String signName)
Checks the validity of a signature.
|
bindPdf, bindPdf, bindPdf, getDocument
public PdfFileSignature()
The constructor of PdfFileSignature class.
@Deprecated public PdfFileSignature(String inputFile)
The constructor of PdfFileSignature class.
inputFile
- The input file for signature.@Deprecated public PdfFileSignature(String inputFile, String outputFile)
The constructor of PdfFileSignature class.
inputFile
- The input file for signature.outputFile
- The output file.public PdfFileSignature(IDocument document)
Initializes new PdfFileSignature
object on base of the document
.
document
- Pdf document.@Deprecated public PdfFileSignature(IDocument document, String outputFile)
Initializes new PdfFileSignature
object on base of the document
.
document
- Pdf document.outputFile
- The output file.public String getSignatureAppearance()
Gets a graphic appearance for the signature. Property value represents image file name.
public void setSignatureAppearance(String value)
Sets a graphic appearance for the signature. Property value represents image file name.
value
- String valuepublic void bindPdf(String inputFile)
Binds a Pdf file for editing.
public void bindPdf(InputStream inputStream)
Binds a Pdf stream for editing.
public void save(String outputFile)
Saves the result PDF to file.
save
in interface ISaveableFacade
save
in class SaveableFacade
outputFile
- output pdf filepublic void save(OutputStream outputStream)
Saves the result PDF to stream.
save
in interface ISaveableFacade
save
in class SaveableFacade
outputStream
- output pdf streampublic 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);
page
- The page number on which signature is made.SigReason
- The reason of signature.SigContact
- The contact of signature.SigLocation
- The location of signature.visible
- The visiblity of signature.annotRect
- The rect of signature.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();
page
- The page number on which signature is made.SigReason
- The reason of signature.SigContact
- The contact of signature.SigLocation
- The location of signature.visible
- The visiblity of signature.annotRect
- The rect of signature.sig
- The type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.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();
page
- The page number on which signature is made.visible
- The visiblity of signature.annotRect
- The rect of signature.sig
- The 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).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();
SigName
- The name of the signature field.SigReason
- The reason of signature.SigContact
- The contact of signature.SigLocation
- The location of signature.sig
- The type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.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);
page
- The page number on which signature is made.SigName
- The name of the signature field.SigReason
- The reason of signature.SigContact
- The contact of signature.SigLocation
- The location of signature.visible
- The visiblity of signature.annotRect
- The rect of signature.sig
- The type of the signature, could be PKCS1, PKCS7 and PKCS7Detached.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();
SigName
- The name of the signature field.sig
- The type of the signature, could be PKCS1 (Pkcs1Signature object), PKCS7 and PKCS7 detached
(Pkcs7Signature object)public boolean isCertified()
Gets the flag determining whether a document is certified or not.
public int getAccessPermissions()
Returns the access permissions value of certified document by the MDP signature type.
DocMDPAccessPermissions
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.
page
- The page on which signature is made.SigReason
- The reason of signature.SigContact
- The contact of signature.SigLocation
- The location of signature.visible
- The visiblity of signature.annotRect
- The rect of signature.docMdpSignature
- The document MDP type of the signature.public List<String> getSignNames()
Gets the names of all not empty signatures.
String inFile=TestPath + "example1.pdf"; PdfFileSignature pdfSign=new PdfFileSignature(); pdfSign.bindPdf(inFile); ArrayList names=pdfSign.getSignNames(); 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());
public List<String> getBlankSignNames()
Gets the names of all empty signature fields.
@Deprecated public boolean isContainSignature()
Checks if the pdf has a digital signature or not.
public boolean containsSignature()
Checks if the pdf has a digital signature or not.
public boolean containsUsageRights()
Checks if the pdf has a usage rights or not.
@Deprecated public boolean isCoversWholeDocument(String signName)
Checks if the signature covers the whole document.
signName
- The name of signature.public boolean coversWholeDocument(String signName)
Checks if the signature covers the whole document.
signName
- The name of signature.public int getRevision(String signName)
Gets the revision of a signature.
signName
- The name of signature.public int getTotalRevision()
Gets the toltal revision.
public void removeUsageRights()
Removes the usage rights entry.
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");
signName
- The name of signature.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");
signName
- The name of signature.removeField
- If set to true, than removes both of signature and field from document; otherwise, signature
only.public boolean verifySigned(String signName)
Checks the validity of a signature.
signName
- The name of signature.public String getSignerName(String signName)
Gets the name of person or organization who signing the pdf document.
signName
- The name of signature.public Date getDateTime(String signName)
Gets the signature's datetime.
signName
- The name of signature.public String getReason(String signName)
Gets the reason of a signature.
signName
- The name of signature.public String getLocation(String signName)
Gets the location of a signature.
signName
- The name of signature.public String getContactInfo(String signName)
Gets the contact information of a signature.
signName
- The name of signature.public boolean verifySignature(String signName)
Checks the validity of a signature.
signName
- The name of signature.public InputStream extractImage(String signName)
Extracts signature's image.
signName
- The name of signature.public InputStream extractCertificate(String signName)
Extracts signature's single X.509 certificate as a stream.
signName
- The name of signature.@Deprecated public void save()
Save signed pdf file. Output filename must be provided before with the help of coresponding PdfFileSignature constructor.
public void setCertificate(String pfx, String pass)
Set certificate file and password for signing routine.
pfx
- PKCS #12 certificate file.pass
- Password to get access for the certificate private key.public InputStream getSignatureAppearanceStream()
Gets a graphic appearance for the signature. Property value represents image stream.
public void setSignatureAppearanceStream(InputStream value)
Sets a graphic appearance for the signature. Property value represents image stream.
value
- InputStream elementpublic void close()