Package com.itextpdf.pdfa
Class PdfADocument
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfDocument
-
- com.itextpdf.pdfa.PdfADocument
-
- All Implemented Interfaces:
IEventDispatcher
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
PdfAAgnosticPdfDocument
public class PdfADocument extends PdfDocument
This class extendsPdfDocument
and is in charge of creating files that comply with the PDF/A standard. Client code is still responsible for making sure the file is actually PDF/A compliant: multiple steps must be undertaken (depending on thePdfAConformanceLevel
) to ensure that the PDF/A standard is followed. This class will throw exceptions, mostlyPdfAConformanceException
, and thus refuse to output a PDF/A file if at any point the document does not adhere to the PDF/A guidelines specified by thePdfAConformanceLevel
.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
alreadyLoggedThatObjectFlushingWasNotPerformed
private boolean
alreadyLoggedThatPageFlushingWasNotPerformed
protected PdfAChecker
checker
private boolean
isPdfADocument
private static IPdfPageFactory
pdfAPageFactory
-
Fields inherited from class com.itextpdf.kernel.pdf.PdfDocument
catalog, closed, closeReader, closeWriter, eventDispatcher, fingerPrint, flushUnusedObjects, info, isClosing, pdfVersion, properties, reader, serializeOptions, structParentIndex, structTreeRoot, tagStructureContext, trailer, writer, xmpMetadata
-
-
Constructor Summary
Constructors Constructor Description PdfADocument(PdfReader reader, PdfWriter writer)
Opens a PDF/A document in the stamping mode.PdfADocument(PdfReader reader, PdfWriter writer, StampingProperties properties)
Opens a PDF/A document in stamping mode.PdfADocument(PdfReader reader, PdfWriter writer, StampingProperties properties, boolean tolerant)
PdfADocument(PdfWriter writer, PdfAConformanceLevel conformanceLevel, PdfOutputIntent outputIntent)
Constructs a new PdfADocument for writing purposes, i.e.PdfADocument(PdfWriter writer, PdfAConformanceLevel conformanceLevel, PdfOutputIntent outputIntent, DocumentProperties properties)
Constructs a new PdfADocument for writing purposes, i.e.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCustomMetadataExtensions(XMPMeta xmpMeta)
Adds custom XMP metadata extension.void
addOutputIntent(PdfOutputIntent outputIntent)
AddsPdfOutputIntent
that shall specify the colour characteristics of output devices on which the document might be rendered.protected void
checkIsoConformance()
Checks whether PDF document conforms to a specific standard.void
checkIsoConformance(java.lang.Object obj, IsoKey key, PdfResources resources, PdfStream contentStream, java.lang.Object extra)
Checks whether PDF document conforms a specific standard.protected void
flushInfoDictionary(boolean appendMode)
Flush info dictionary if needed.protected void
flushObject(PdfObject pdfObject, boolean canBeInObjStm)
Flush an object.IConformanceLevel
getConformanceLevel()
Get theIConformanceLevel
private static PdfAChecker
getCorrectCheckerFromConformance(PdfAConformanceLevel conformanceLevel)
PdfFont
getDefaultFont()
No default font for PDF/A documents.protected IPdfPageFactory
getPageFactory()
Returns the factory for creating page instances.private static PdfVersion
getPdfVersionForPdfA(PdfAConformanceLevel conformanceLevel)
protected void
initTagStructureContext()
Initializes tagStructureContext to track necessary information of document's tag structure.(package private) boolean
isClosing()
(package private) void
logThatPdfAPageFlushingWasNotPerformed()
protected void
setChecker(PdfAConformanceLevel conformanceLevel)
Sets the checker that defines the requirements of the PDF/A standard depending on conformance level.protected void
setChecker(PdfAChecker checker)
private void
setCheckerIfChanged()
protected void
updateXmpMetadata()
Updates XMP metadata.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfDocument
addAssociatedFile, addEventHandler, addFileAttachment, addFont, addNamedDestination, addNamedDestination, addNewPage, addNewPage, addNewPage, addNewPage, addPage, addPage, checkAndAddPage, checkAndAddPage, checkClosingStatus, checkIsoConformance, checkIsoConformance, checkShowTextIsoConformance, close, copyPagesTo, copyPagesTo, copyPagesTo, copyPagesTo, copyPagesTo, copyPagesTo, copyPagesTo, copyPagesTo, createNextIndirectReference, dispatchEvent, dispatchEvent, findFont, flushCopiedObjects, flushFonts, getAssociatedFiles, getCatalog, getDefaultPageSize, getDiContainer, getDocumentFonts, getDocumentId, getDocumentIdWrapper, getDocumentInfo, getEncryptedPayloadDocument, getFingerPrint, getFirstPage, getFont, getLastPage, getMemoryLimitsAwareHandler, getModifiedDocumentId, getNextStructParentIndex, getNumberOfPages, getNumberOfPdfObjects, getOriginalDocumentId, getOutlines, getPage, getPage, getPageLabels, getPageNumber, getPageNumber, getPdfObject, getPdfVersion, getReader, getSerializeOptions, getStructTreeRoot, getTagStructureContext, getTrailer, getWriter, getXmpMetadata, getXmpMetadata, hasEventHandler, hasOutlines, initializeOutlines, isAppendMode, isClosed, isCloseReader, isCloseWriter, isFlushUnusedObjects, isTagged, listIndirectReferences, markObjectAsMustBeFlushed, markStreamAsEmbeddedFile, movePage, movePage, open, registerProduct, removeAllHandlers, removeEventHandler, removePage, removePage, setCloseReader, setCloseWriter, setDefaultPageSize, setEncryptedPayload, setFlushUnusedObjects, setSerializeOptions, setTagged, setUserProperties, setXmpMetadata, setXmpMetadata, setXmpMetadata, storeDestinationToReaddress, tryInitTagStructure, updateDefaultXmpMetadata
-
-
-
-
Field Detail
-
pdfAPageFactory
private static IPdfPageFactory pdfAPageFactory
-
checker
protected PdfAChecker checker
-
alreadyLoggedThatObjectFlushingWasNotPerformed
private boolean alreadyLoggedThatObjectFlushingWasNotPerformed
-
alreadyLoggedThatPageFlushingWasNotPerformed
private boolean alreadyLoggedThatPageFlushingWasNotPerformed
-
isPdfADocument
private boolean isPdfADocument
-
-
Constructor Detail
-
PdfADocument
public PdfADocument(PdfWriter writer, PdfAConformanceLevel conformanceLevel, PdfOutputIntent outputIntent)
Constructs a new PdfADocument for writing purposes, i.e. from scratch. A PDF/A file has a conformance level, and must have an explicit output intent.- Parameters:
writer
- thePdfWriter
object to write toconformanceLevel
- the generation and strictness level of the PDF/A that must be followed.outputIntent
- aPdfOutputIntent
-
PdfADocument
public PdfADocument(PdfWriter writer, PdfAConformanceLevel conformanceLevel, PdfOutputIntent outputIntent, DocumentProperties properties)
Constructs a new PdfADocument for writing purposes, i.e. from scratch. A PDF/A file has a conformance level, and must have an explicit output intent.- Parameters:
writer
- thePdfWriter
object to write toconformanceLevel
- the generation and strictness level of the PDF/A that must be followed.outputIntent
- aPdfOutputIntent
properties
- aDocumentProperties
-
PdfADocument
public PdfADocument(PdfReader reader, PdfWriter writer)
Opens a PDF/A document in the stamping mode.- Parameters:
reader
- PDF reader.writer
- PDF writer.
-
PdfADocument
public PdfADocument(PdfReader reader, PdfWriter writer, StampingProperties properties)
Opens a PDF/A document in stamping mode.- Parameters:
reader
- PDF reader.writer
- PDF writer.properties
- properties of the stamping process
-
PdfADocument
PdfADocument(PdfReader reader, PdfWriter writer, StampingProperties properties, boolean tolerant)
-
-
Method Detail
-
getDefaultFont
public PdfFont getDefaultFont()
No default font for PDF/A documents.- Overrides:
getDefaultFont
in classPdfDocument
- Returns:
null
.
-
getConformanceLevel
public IConformanceLevel getConformanceLevel()
Get theIConformanceLevel
- Overrides:
getConformanceLevel
in classPdfDocument
- Returns:
- the
IConformanceLevel
will be null if the document does not have a conformance level specified
-
addOutputIntent
public void addOutputIntent(PdfOutputIntent outputIntent)
AddsPdfOutputIntent
that shall specify the colour characteristics of output devices on which the document might be rendered.- Overrides:
addOutputIntent
in classPdfDocument
- Parameters:
outputIntent
-PdfOutputIntent
to add.- See Also:
PdfOutputIntent
-
logThatPdfAPageFlushingWasNotPerformed
void logThatPdfAPageFlushingWasNotPerformed()
-
addCustomMetadataExtensions
protected void addCustomMetadataExtensions(XMPMeta xmpMeta)
Description copied from class:PdfDocument
Adds custom XMP metadata extension. Useful for PDF/UA, ZUGFeRD, etc.- Overrides:
addCustomMetadataExtensions
in classPdfDocument
- Parameters:
xmpMeta
-XMPMeta
to add custom metadata to.
-
updateXmpMetadata
protected void updateXmpMetadata()
Description copied from class:PdfDocument
Updates XMP metadata. Shall be overridden.- Overrides:
updateXmpMetadata
in classPdfDocument
-
checkIsoConformance
protected void checkIsoConformance()
Description copied from class:PdfDocument
Checks whether PDF document conforms to a specific standard.- Overrides:
checkIsoConformance
in classPdfDocument
-
checkIsoConformance
public void checkIsoConformance(java.lang.Object obj, IsoKey key, PdfResources resources, PdfStream contentStream, java.lang.Object extra)
Description copied from class:PdfDocument
Checks whether PDF document conforms a specific standard.- Overrides:
checkIsoConformance
in classPdfDocument
- Parameters:
obj
- an object to conform.key
- type of object to conform.resources
-PdfResources
associated with an object to check.contentStream
- current content stream.extra
- extra data required for the check.
-
flushObject
protected void flushObject(PdfObject pdfObject, boolean canBeInObjStm) throws java.io.IOException
Description copied from class:PdfDocument
Flush an object.- Overrides:
flushObject
in classPdfDocument
- Parameters:
pdfObject
- object to flush.canBeInObjStm
- indicates whether object can be placed into object stream.- Throws:
java.io.IOException
- on error.
-
setChecker
protected void setChecker(PdfAConformanceLevel conformanceLevel)
Sets the checker that defines the requirements of the PDF/A standard depending on conformance level.- Parameters:
conformanceLevel
-PdfAConformanceLevel
-
setChecker
protected void setChecker(PdfAChecker checker)
-
setCheckerIfChanged
private void setCheckerIfChanged()
-
getCorrectCheckerFromConformance
private static PdfAChecker getCorrectCheckerFromConformance(PdfAConformanceLevel conformanceLevel)
-
initTagStructureContext
protected void initTagStructureContext()
Initializes tagStructureContext to track necessary information of document's tag structure.- Overrides:
initTagStructureContext
in classPdfDocument
-
getPageFactory
protected IPdfPageFactory getPageFactory()
Description copied from class:PdfDocument
Returns the factory for creating page instances.- Overrides:
getPageFactory
in classPdfDocument
- Returns:
- implementation of
IPdfPageFactory
for current document
-
flushInfoDictionary
protected void flushInfoDictionary(boolean appendMode)
Flush info dictionary if needed.- Overrides:
flushInfoDictionary
in classPdfDocument
- Parameters:
appendMode
-true
if the document is edited in append mode.
-
isClosing
boolean isClosing()
-
getPdfVersionForPdfA
private static PdfVersion getPdfVersionForPdfA(PdfAConformanceLevel conformanceLevel)
-
-