com.digisigner.api
Class PdfDocument

java.lang.Object
  extended by com.digisigner.api.PdfDocument

public class PdfDocument
extends Object

The PdfDocument class represents your PDF document and provides methods to digitally sign it. This class is the the entry point of the library.

The following code sample demonstrates how to create a simple visible signature in your document:

 // specify document to sign
 PdfDocument pdfDocument = new PdfDocument("sample.pdf");
		
 // specify key in the key store
 SigningData signingData = SigningData.fromPkcs12File("keystore.pfx", "keystore_pass", "key_alias");
		
 // specify rectangle for the signature
 signingData.setFieldRectangle(new Rectangle2D.Float(275, 50, 300, 100));
		
 // sign document
 pdfDocument.signDocument(signingData, "sample(signed).pdf");
 
 

Author:
DigiSigner Software

Constructor Summary
PdfDocument(byte[] pdfContent)
          Creates a PdfDocument object from a byte array with the content of the pdf document.
PdfDocument(File pdfFile)
          Creates a PdfDocument object from a File object.
PdfDocument(InputStream pdfInputStream)
          Creates a PdfDocument object from an InputStream.
PdfDocument(String pdfFilename)
          Creates a PdfDocument object from a file specified by name.
PdfDocument(URL pdfUrl)
          Creates a PdfDocument object from a URL.
 
Method Summary
 String getPassword()
          Returns the password of the PDF document.
 void setPassword(String password)
          Sets the password of the document.
 SignatureFieldData signDocument(SigningData signingData, OutputStream signedPdfOutputStream)
          Digitally signs the document and saves the signed result in the specified OutputStream.
 SignatureFieldData signDocument(SigningData signingData, String signedPdfFilename)
          Digitally signs the document and saves the signed result in the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfDocument

public PdfDocument(File pdfFile)
Creates a PdfDocument object from a File object.

Parameters:
pdfFile - PDF file

PdfDocument

public PdfDocument(String pdfFilename)
Creates a PdfDocument object from a file specified by name.

Parameters:
pdfFilename - PDF file name

PdfDocument

public PdfDocument(byte[] pdfContent)
Creates a PdfDocument object from a byte array with the content of the pdf document.

Parameters:
pdfContent - PDF document content

PdfDocument

public PdfDocument(InputStream pdfInputStream)
Creates a PdfDocument object from an InputStream.

Parameters:
pdfInputStream - input stream to read the PDF document content

PdfDocument

public PdfDocument(URL pdfUrl)
Creates a PdfDocument object from a URL.

Parameters:
pdfUrl - location of the PDF document content
Method Detail

getPassword

public String getPassword()
Returns the password of the PDF document. Note: this method just returns the value, that was set by the corresponding setter setPassword method. It doesn't try to find out the real document password.

Returns:
password of the PDF document

setPassword

public void setPassword(String password)
Sets the password of the document. This is the password that allows all changes on the document. You have to specify it only if your document is password protected.

Parameters:
password - of the PDF document

signDocument

public SignatureFieldData signDocument(SigningData signingData,
                                       String signedPdfFilename)
Digitally signs the document and saves the signed result in the specified file.

Parameters:
signingData - data required to sign the document
signedPdfFilename - name of the signed PDF file
Returns:
information about the signature field that was used to create the signature. This information can be useful in the cases, where the signature field is not explicitly specified and is therefore created automatically.
Throws:
TimeStampException - if cannot retrieve or parse time stamp information
CrlRetrievalException - if cannot retrieve or parse certificate revocation lists
OcspCheckException - if cannot retrieve or parse OCSP response
DigiRuntimeException - if general problem occurs

signDocument

public SignatureFieldData signDocument(SigningData signingData,
                                       OutputStream signedPdfOutputStream)
Digitally signs the document and saves the signed result in the specified OutputStream.

Parameters:
signingData - data required to sign the document
signedPdfOutputStream - output stream for the signed PDF document
Returns:
information about the signature field that was used to create the signature. This information can be useful in the cases, where the signature field is not explicitly specified and is therefore created automatically.
Throws:
TimeStampException - if cannot retrieve or parse time stamp information
CrlRetrievalException - if cannot retrieve or parse certificate revocation lists
OcspCheckException - if cannot retrieve or parse OCSP response
DigiRuntimeException - if general problem occurs