Package com.itextpdf.text.pdf
Class PdfAStamper
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfStamper
-
- com.itextpdf.text.pdf.PdfAStamper
-
- All Implemented Interfaces:
PdfEncryptionSettings
,PdfViewerPreferences
public class PdfAStamper extends PdfStamper
Extension of PdfStamper that will attempt to keep a file in conformance with the PDF/A standard.- See Also:
PdfStamper
-
-
Field Summary
-
Fields inherited from class com.itextpdf.text.pdf.PdfStamper
hasSignature, sigApp, sigXmlApp, stamper
-
-
Constructor Summary
Constructors Constructor Description PdfAStamper(PdfReader reader, java.io.OutputStream os, char pdfVersion, boolean append, PdfAConformanceLevel conformanceLevel)
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.PdfAStamper(PdfReader reader, java.io.OutputStream os, char pdfVersion, PdfAConformanceLevel conformanceLevel)
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.PdfAStamper(PdfReader reader, java.io.OutputStream os, PdfAConformanceLevel conformanceLevel)
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PdfAStamper
createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, PdfAConformanceLevel conformanceLevel)
Applies a digital signature to a document.static PdfAStamper
createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, java.io.File tempFile, boolean append, PdfAConformanceLevel conformanceLevel)
Applies a digital signature to a document, possibly as a new revision, making possible multiple signatures.static PdfAStamper
createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, java.io.File tempFile, PdfAConformanceLevel conformanceLevel)
Applies a digital signature to a document.-
Methods inherited from class com.itextpdf.text.pdf.PdfStamper
addAnnotation, addComments, addFileAttachment, addFileAttachment, addJavaScript, addJavaScript, addNamedDestination, addSignature, addViewerPreference, close, createSignature, createSignature, createSignature, createXmlSignature, createXmpMetadata, flush, getAcroFields, getImportedPage, getLtvVerification, getMoreInfo, getOverContent, getPdfLayers, getReader, getSignatureAppearance, getUnderContent, getWriter, getXmlSignatureAppearance, getXmpWriter, insertPage, isFullCompression, isRotateContents, makePackage, makePackage, markUsed, mergeVerification, partialFormFlattening, replacePage, setAnnotationFlattening, setDuration, setEncryption, setEncryption, setEncryption, setEncryption, setEncryption, setFormFlattening, setFreeTextFlattening, setFullCompression, setMoreInfo, setOutlines, setPageAction, setRotateContents, setThumbnail, setTransition, setViewerPreferences, setXmpMetadata
-
-
-
-
Constructor Detail
-
PdfAStamper
public PdfAStamper(PdfReader reader, java.io.OutputStream os, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.- Parameters:
reader
- the original document. It cannot be reusedos
- the output streamconformanceLevel
- PDF/A conformance level of a new PDF document- Throws:
DocumentException
- on errorjava.io.IOException
- or error
-
PdfAStamper
public PdfAStamper(PdfReader reader, java.io.OutputStream os, char pdfVersion, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.- Parameters:
reader
- the original document. It cannot be reusedos
- the output streampdfVersion
- the new pdf version or '\0' to keep the same version as the original documentconformanceLevel
- PDF/A conformance level of a new PDF document- Throws:
DocumentException
- on errorjava.io.IOException
- or error
-
PdfAStamper
public PdfAStamper(PdfReader reader, java.io.OutputStream os, char pdfVersion, boolean append, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Starts the process of adding extra content to an existing PDF document keeping the document PDF/A conformant.- Parameters:
reader
- the original document. It cannot be reusedos
- the output streampdfVersion
- the new pdf version or '\0' to keep the same version as the original documentappend
- iftrue
appends the document changes as a new revision. This is only useful for multiple signatures as nothing is gained in speed or memoryconformanceLevel
- PDF/A conformance level of a new PDF document- Throws:
DocumentException
- on errorjava.io.IOException
- or error
-
-
Method Detail
-
createSignature
public static PdfAStamper createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, java.io.File tempFile, boolean append, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Applies a digital signature to a document, possibly as a new revision, making possible multiple signatures. The returned PdfStamper can be used normally as the signature is only applied when closing.A possible use for adding a signature without invalidating an existing one is:
KeyStore ks = KeyStore.getInstance("pkcs12"); ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray()); String alias = (String)ks.aliases().nextElement(); PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray()); Certificate[] chain = ks.getCertificateChain(alias); PdfReader reader = new PdfReader("original.pdf"); FileOutputStream fout = new FileOutputStream("signed.pdf"); PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0', new File("/temp"), true); PdfSignatureAppearance sap = stp.getSignatureAppearance(); sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.setReason("I'm the author"); sap.setLocation("Lisbon"); // comment next line to have an invisible signature sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null); stp.close();
- Parameters:
reader
- the original documentos
- the output stream ornull
to keep the document in the temporary filepdfVersion
- the new pdf version or '\0' to keep the same version as the original documenttempFile
- location of the temporary file. If it's a directory a temporary file will be created there. If it's a file it will be used directly. The file will be deleted on exit unlessos
is null. In that case the document can be retrieved directly from the temporary file. If it'snull
no temporary file will be created and memory will be usedappend
- iftrue
the signature and all the other content will be added as a new revision thus not invalidating existing signaturesconformanceLevel
- PDF/A conformance level of a new PDF document- Returns:
- a
PdfAStamper
- Throws:
DocumentException
- on errorjava.io.IOException
- on error
-
createSignature
public static PdfAStamper createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Applies a digital signature to a document. The returned PdfStamper can be used normally as the signature is only applied when closing.Note that the pdf is created in memory.
A possible use is:
KeyStore ks = KeyStore.getInstance("pkcs12"); ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray()); String alias = (String)ks.aliases().nextElement(); PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray()); Certificate[] chain = ks.getCertificateChain(alias); PdfReader reader = new PdfReader("original.pdf"); FileOutputStream fout = new FileOutputStream("signed.pdf"); PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0'); PdfSignatureAppearance sap = stp.getSignatureAppearance(); sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.setReason("I'm the author"); sap.setLocation("Lisbon"); // comment next line to have an invisible signature sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null); stp.close();
- Parameters:
reader
- the original documentos
- the output streampdfVersion
- the new pdf version or '\0' to keep the same version as the original documentconformanceLevel
- PDF/A conformance level of a new PDF document- Returns:
- a
PdfAStamper
- Throws:
DocumentException
- on errorjava.io.IOException
- on error
-
createSignature
public static PdfAStamper createSignature(PdfReader reader, java.io.OutputStream os, char pdfVersion, java.io.File tempFile, PdfAConformanceLevel conformanceLevel) throws DocumentException, java.io.IOException
Applies a digital signature to a document. The returned PdfStamper can be used normally as the signature is only applied when closing.A possible use is:
KeyStore ks = KeyStore.getInstance("pkcs12"); ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray()); String alias = (String)ks.aliases().nextElement(); PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray()); Certificate[] chain = ks.getCertificateChain(alias); PdfReader reader = new PdfReader("original.pdf"); FileOutputStream fout = new FileOutputStream("signed.pdf"); PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0', new File("/temp")); PdfSignatureAppearance sap = stp.getSignatureAppearance(); sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); sap.setReason("I'm the author"); sap.setLocation("Lisbon"); // comment next line to have an invisible signature sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null); stp.close();
- Parameters:
reader
- the original documentos
- the output stream ornull
to keep the document in the temporary filepdfVersion
- the new pdf version or '\0' to keep the same version as the original documenttempFile
- location of the temporary file. If it's a directory a temporary file will be created there. If it's a file it will be used directly. The file will be deleted on exit unlessos
is null. In that case the document can be retrieved directly from the temporary file. If it'snull
no temporary file will be created and memory will be usedconformanceLevel
- PDF/A conformance level of a new PDF document- Returns:
- a
PdfAStamper
- Throws:
DocumentException
- on errorjava.io.IOException
- on error
-
-