Package com.pd4ml.pdf.sign
Class PdfSigner
- java.lang.Object
-
- com.pd4ml.pdf.sign.PdfSigner
-
public final class PdfSigner extends java.lang.ObjectPublic entry point of the PD4ML PDF signing API.Applies a PKCS#7/CMS ("PAdES-compatible") digital signature to a PDF document as a raw incremental update, built entirely on the pd4ml
com.pd4ml.pdf.cosobject model/parser (no PDFBox, no other PDF library) plus BouncyCastle for the CMS/PKCS#7 cryptography. Supports invisible and visible signatures, PDF "certification" (DocMDP), and optional RFC 3161 timestamping.Thread-safety: a
PdfSignerinstance holds no mutable state and may be reused/shared across threads; eachsign(...)call is independent.Example
CertificateUtils.SigningIdentity identity = CertificateUtils.loadFromPkcs12(new File("signer.p12"), "password".toCharArray()); SigningOptions options = new SigningOptions() .setReason("Approved") .setSignerName("Jane Doe"); new PdfSigner().sign(new File("input.pdf"), new File("signed.pdf"), identity, options);
-
-
Constructor Summary
Constructors Constructor Description PdfSigner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]sign(byte[] inputPdfBytes, CertificateUtils.SigningIdentity identity, SigningOptions options)Signs an in-memory PDF, returning the signed document's bytes.voidsign(java.io.File inputPdf, java.io.File outputPdf, CertificateUtils.SigningIdentity identity, SigningOptions options)SignsinputPdf, writing the signed document tooutputPdf.voidsign(java.io.InputStream input, java.io.OutputStream output, CertificateUtils.SigningIdentity identity, SigningOptions options)Signs the PDF read frominput, writing the signed bytes tooutput.SignResultsignForResult(byte[] inputPdfBytes, CertificateUtils.SigningIdentity identity, SigningOptions options)Likesign(byte[], CertificateUtils.SigningIdentity, SigningOptions), but returns the fullSignResult-- signed PDF bytes plus the raw CMS/PKCS#7 signature that was embedded.
-
-
-
Method Detail
-
sign
public void sign(java.io.File inputPdf, java.io.File outputPdf, CertificateUtils.SigningIdentity identity, SigningOptions options) throws PdfSigningExceptionSignsinputPdf, writing the signed document tooutputPdf. Digital signatures are always applied as an incremental update over the ENTIRE original file, so the whole input is read into memory first;outputPdfmay equalinputPdf(the input is fully buffered before anything is written).- Throws:
PdfSigningException
-
sign
public void sign(java.io.InputStream input, java.io.OutputStream output, CertificateUtils.SigningIdentity identity, SigningOptions options) throws PdfSigningExceptionSigns the PDF read frominput, writing the signed bytes tooutput. Neither stream is closed by this method. The input is fully buffered in memory (a digital signature's byte-range hash covers the whole file, so streaming isn't possible).- Throws:
PdfSigningException
-
sign
public byte[] sign(byte[] inputPdfBytes, CertificateUtils.SigningIdentity identity, SigningOptions options) throws PdfSigningExceptionSigns an in-memory PDF, returning the signed document's bytes.- Throws:
PdfSigningException
-
signForResult
public SignResult signForResult(byte[] inputPdfBytes, CertificateUtils.SigningIdentity identity, SigningOptions options) throws PdfSigningException
Likesign(byte[], CertificateUtils.SigningIdentity, SigningOptions), but returns the fullSignResult-- signed PDF bytes plus the raw CMS/PKCS#7 signature that was embedded. Callers doing LTV (seecom.pd4ml.pdf.sign.ltv) need the CMS bytes to compute the PAdES/VRIdictionary key without re-parsing the output.- Throws:
PdfSigningException
-
-