Class PdfSignature
java.lang.Object
com.codename1.pdf.PdfSignature
Describes the digital signature PdfDocument.sign(PdfSignature) embeds
when the document is saved.
The result is a PAdES baseline (B-B) signature: a detached CMS
SignedData over the whole file, SHA-256, with the signer's
certificate. Acrobat, Preview and pdfsig report it as signed; whether
they call it trusted depends on the certificate, which is the
application's choice, not this class's.
PrivateKey key = PrivateKey.fromPem(new String(Util.readInputStream(
CN.getResourceAsStream("/signer-key.pem")), "UTF-8"));
byte[] certificateDer = Util.readInputStream(CN.getResourceAsStream("/signer.der"));
PdfDocument doc = new PdfDocument();
doc.addPage(PdfPageSize.A4);
// ... draw the certificate of completion ...
doc.sign(new PdfSignature(PdfSigner.provider(key, certificateDer))
.setReason("Certificate of completion")
.setLocation("Lingo Academy")
.setVisible(doc.getPage(0), 380, 40, 180, 50));
byte[] signed = doc.toByteArray();
-
Constructor Summary
ConstructorsConstructorDescriptionPdfSignature(PdfSignatureProvider provider) A signature whose key material comes fromprovider. -
Method Summary
Modifier and TypeMethodDescriptionHow to reach the signer, or null.Where the document was signed, or null.getName()The signer's name, or null for the certificate's common name.The provider given to the constructor.Why the document was signed, or null.intThe space reserved for the CMS signature, in bytes.longThe claimed signing time.booleanTrue whensetVisible(PdfPage, float, float, float, float)placed the signature on a page.setContactInfo(String contactInfo) How to reach the signer.setLocation(String location) Where the document was signed.The signer's name as shown by viewers; defaults to the certificate's common name.Why the document was signed.setReservedBytes(int bytes) The space reserved in the file for the CMS signature, in bytes; 12 KB by default, enough for a signer certificate and two intermediates.setSigningTime(long millis) The claimed signing time, in milliseconds since the epoch; the current time by default.setVisible(PdfPage page, float x, float y, float width, float height) Shows the signature as a box at(x, y, width, height)onpage, in the page's top-left based coordinates, with the signer's name, the date and the reason.
-
Constructor Details
-
PdfSignature
A signature whose key material comes fromprovider.
-
-
Method Details
-
getProvider
The provider given to the constructor. -
setName
The signer's name as shown by viewers; defaults to the certificate's common name. -
getName
The signer's name, or null for the certificate's common name. -
setReason
Why the document was signed. -
getReason
Why the document was signed, or null. -
setLocation
Where the document was signed. -
getLocation
Where the document was signed, or null. -
setContactInfo
How to reach the signer. -
getContactInfo
How to reach the signer, or null. -
setSigningTime
The claimed signing time, in milliseconds since the epoch; the current time by default. It is the signer's claim, not a timestamp authority's. -
getSigningTime
public long getSigningTime()The claimed signing time. -
setVisible
Shows the signature as a box at(x, y, width, height)onpage, in the page's top-left based coordinates, with the signer's name, the date and the reason. Without this the signature is invisible and attached to the first page. -
isVisible
public boolean isVisible()True whensetVisible(PdfPage, float, float, float, float)placed the signature on a page. -
setReservedBytes
The space reserved in the file for the CMS signature, in bytes; 12 KB by default, enough for a signer certificate and two intermediates. Saving fails if the signature does not fit. -
getReservedBytes
public int getReservedBytes()The space reserved for the CMS signature, in bytes.
-