Package com.itextpdf.text.pdf
Class PdfAStamperImp
- java.lang.Object
-
- com.itextpdf.text.DocWriter
-
- com.itextpdf.text.pdf.PdfWriter
-
- com.itextpdf.text.pdf.PdfAStamperImp
-
- All Implemented Interfaces:
DocListener
,ElementListener
,PdfAnnotations
,PdfDocumentActions
,PdfEncryptionSettings
,PdfPageActions
,PdfRunDirection
,PdfVersion
,PdfViewerPreferences
,EventListener
public class PdfAStamperImp extends PdfWriter
Extension to PdfStamperImp that will attempt to keep a file in conformance with the PDF/A standard.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.itextpdf.text.pdf.PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer
-
-
Field Summary
Fields Modifier and Type Field Description protected AcroFields
acroFields
protected boolean
append
protected boolean
closed
protected Counter
COUNTER
protected boolean
fieldsAdded
protected HashSet<PdfTemplate>
fieldTemplates
protected RandomAccessFileOrArray
file
protected boolean
flat
protected boolean
flatannotations
protected boolean
flatFreeText
protected int
initialXrefSize
protected IntHashtable
marked
protected HashMap<Object,PdfObject>
namedDestinations
protected int[]
namePtr
protected PdfAction
openAction
protected HashSet<String>
partialFlattening
protected int
sigFlags
protected boolean
useVp
protected PdfViewerPreferencesImp
viewerPreferences
-
Fields inherited from class com.itextpdf.text.pdf.PdfWriter
ALLOW_ASSEMBLY, ALLOW_COPY, ALLOW_DEGRADED_PRINTING, ALLOW_FILL_IN, ALLOW_MODIFY_ANNOTATIONS, ALLOW_MODIFY_CONTENTS, ALLOW_PRINTING, ALLOW_SCREENREADERS, AllowAssembly, AllowCopy, AllowDegradedPrinting, AllowFillIn, AllowModifyAnnotations, AllowModifyContents, AllowPrinting, AllowScreenReaders, body, CenterWindow, colorNumber, colorProfile, compressionLevel, crypto, currentPageNumber, currentPdfReaderInstance, defaultColorspace, DID_PRINT, DID_SAVE, directContent, directContentUnder, DirectionL2R, DirectionR2L, DisplayDocTitle, DO_NOT_ENCRYPT_METADATA, DOCUMENT_CLOSE, documentColors, documentExtGState, documentFonts, documentOCG, documentOCGorder, documentPatterns, documentProperties, documentShadingPatterns, documentShadings, documentSpotPatterns, EMBEDDED_FILES_ONLY, ENCRYPTION_AES_128, ENCRYPTION_AES_256, extraCatalog, FitWindow, fontNumber, formXObjects, formXObjectsCounter, fullCompression, GENERATION_MAX, group, HideMenubar, HideToolbar, HideWindowUI, imageDictionary, JBIG2Globals, markAll, markInlineElementsOnly, newBookmarks, NO_SPACE_CHAR_RATIO, NonFullScreenPageModeUseNone, NonFullScreenPageModeUseOC, NonFullScreenPageModeUseOutlines, NonFullScreenPageModeUseThumbs, OCGLocked, OCGRadioGroup, OCProperties, originalFileID, PAGE_CLOSE, PAGE_OPEN, pageDictEntries, PageLayoutOneColumn, PageLayoutSinglePage, PageLayoutTwoColumnLeft, PageLayoutTwoColumnRight, PageLayoutTwoPageLeft, PageLayoutTwoPageRight, PageModeFullScreen, PageModeUseAttachments, PageModeUseNone, PageModeUseOC, PageModeUseOutlines, PageModeUseThumbs, pageReferences, patternColorspaceCMYK, patternColorspaceGRAY, patternColorspaceRGB, patternNumber, pdf, pdf_version, PDF_VERSION_1_2, PDF_VERSION_1_3, PDF_VERSION_1_4, PDF_VERSION_1_5, PDF_VERSION_1_6, PDF_VERSION_1_7, pdfIsoConformance, PDFX1A2001, PDFX32002, PDFXNONE, prevxref, PrintScalingNone, readerInstances, root, RUN_DIRECTION_DEFAULT, RUN_DIRECTION_LTR, RUN_DIRECTION_NO_BIDI, RUN_DIRECTION_RTL, runDirection, SIGNATURE_APPEND_ONLY, SIGNATURE_EXISTS, SPACE_CHAR_RATIO_DEFAULT, STANDARD_ENCRYPTION_128, STANDARD_ENCRYPTION_40, STRENGTH128BITS, STRENGTH40BITS, structureTreeRoot, tabs, tagged, taggingMode, ttfUnicodeWriter, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6, VERSION_1_7, WILL_PRINT, WILL_SAVE, xmpMetadata, xmpWriter
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnnotation(PdfAnnotation annot)
Use this methods to add aPdfAnnotation
or aPdfFormField
to the document.void
addComments(FdfReader fdf)
protected void
addFieldResources()
protected void
addFileAttachments()
void
addViewerPreference(PdfName key, PdfObject value)
Adds a viewer preferenceprotected void
alterContents()
protected void
cacheObject(PdfIndirectObject iobj)
Use this method for caching objects.protected void
close(PdfIndirectReference info, int skipInfo)
protected void
close(Map<String,String> moreInfo)
PdfAnnotation
createAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype)
A wrapper around PdfAnnotation constructor.PdfAnnotation
createAnnotation(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype)
A wrapper around PdfAnnotation constructor.PdfAnnotation
createAnnotation(Rectangle rect, PdfName subtype)
A wrapper around PdfAnnotation constructor.void
createXmpMetadata()
Use this method to creates XMP Metadata based on the metadata in the PdfDocument.protected XmpWriter
createXmpWriter(ByteArrayOutputStream baos, PdfDictionary info)
protected XmpWriter
createXmpWriter(ByteArrayOutputStream baos, HashMap<String,String> info)
protected void
flatFields()
protected void
flatFreeTextFields()
protected void
flattenAnnotations()
If setFlatAnnotations is set to true, iText will flatten all annotations with an appearance streamprotected Counter
getCounter()
PdfContentByte
getDirectContent()
Use this method to get the direct content for this document.PdfContentByte
getDirectContentUnder()
Use this method to get the direct content under for this document.protected HashMap<Object,PdfObject>
getNamedDestinations()
protected int
getNewObjectNumber(PdfReader reader, int number, int generation)
PdfIndirectReference
getPageReference(int page)
Use this method to get a reference to a page existing or not.Map<String,PdfLayer>
getPdfLayers()
Gets the PdfLayer objects in an existing document as a Map with the names/titles of the layers as keys.PdfReader
getPdfReader()
protected TtfUnicodeWriter
getTtfUnicodeWriter()
XMPMeta
getXmpMeta()
protected PdfIsoConformance
initPdfIsoConformance()
protected void
markUsed(int num)
protected void
markUsed(PdfObject obj)
protected void
readColorProfile()
protected void
readOCProperties()
Reads the OCProperties dictionary from the catalog of the existing document and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter.void
registerReader(PdfReader reader, boolean openFile)
void
setAdditionalAction(PdfName actionType, PdfAction action)
Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole.void
setDuration(int seconds)
Always throws anUnsupportedOperationException
.void
setFlatAnnotations(boolean flatAnnotations)
If true, annotations with an appearance stream will be flattened.protected void
setJavaScript()
void
setOpenAction(PdfAction action)
When the document opens thisaction
will be invoked.void
setOpenAction(String name)
When the document opens it will jump to the destination with this name.protected void
setOutlines()
void
setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile)
Sets the values of the output intent dictionary.void
setPageAction(PdfName actionType, PdfAction action)
Always throws anUnsupportedOperationException
.void
setPDFXConformance(int pdfx)
Always throws an exception since PDF/X conformance level cannot be set for PDF/A conformant documents.void
setSigFlags(int f)
Set the signature flags.void
setThumbnail(Image image)
Use this method to set the thumbnail image for the current page.void
setTransition(PdfTransition transition)
Always throws anUnsupportedOperationException
.protected void
setViewerPreferences()
void
setViewerPreferences(int preferences)
Sets the viewer preferences.void
unRegisterReader(PdfReader reader)
protected void
updateNamedDestinations()
-
Methods inherited from class com.itextpdf.text.pdf.PdfWriter
add, addCalculationOrder, addDeveloperExtension, addDirectImageSimple, addDirectImageSimple, addFileAttachment, addFileAttachment, addFileAttachment, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addNamedDestination, addNamedDestinations, addOCGRadioGroup, addPageDictEntry, addSharedObjectsToBody, addToBody, addToBody, addToBody, addToBody, addToBody, addToBody, addXFormsToBody, buildStructTreeRootForTagged, checkElementRole, checkPdfIsoConformance, checkPdfIsoConformance, clearTextWrap, close, fillOCProperties, flushAcroFields, flushTaggedObjects, freeReader, getAcroForm, getBoxSize, getBoxSize, getCatalog, getColorProfile, getCompressionLevel, getCurrentDocumentSize, getCurrentPageNumber, getDefaultColorspace, getExtraCatalog, getGroup, getImportedPage, getIndirectReferenceNumber, getInfo, getInstance, getInstance, getNameString, getOCProperties, getOs, getPageDictEntries, getPageEvent, getPageNumber, getPageSize, getPdfIndirectReference, getPdfReaderInstance, getPDFXConformance, getReferenceJBIG2Globals, getRootOutline, getRunDirection, getSpaceCharRatio, getStandardStructElems, getStructureTreeRoot, getTabs, getVerticalPosition, getXmpWriter, isFullCompression, isPageEmpty, isPdfIso, isPdfX, isRgbTransparencyBlending, isStrictImageSequence, isTagged, isUserProperties, lockLayer, needToBeMarkedInContent, open, releaseTemplate, reorderPages, resetPageDictEntries, setAtLeastPdfVersion, setBoxSize, setCollection, setCompressionLevel, setCropBoxSize, setDefaultColorspace, setEncryption, setEncryption, setEncryption, setEncryption, setEncryption, setFullCompression, setGroup, setInitialLeading, setLanguage, setLinearPageMode, setOutlines, setOutputIntents, setOutputIntents, setPageEmpty, setPageEvent, setPageLabels, setPageViewport, setPageXmpMetadata, setPdfVersion, setPdfVersion, setRgbTransparencyBlending, setRunDirection, setSpaceCharRatio, setStrictImageSequence, setTabs, setTagged, setTagged, setUserProperties, setUserunit, setXmpMetadata, useExternalCacheForTagStructure, writeKeyInfo, writeOutlines
-
Methods inherited from class com.itextpdf.text.DocWriter
add, addTabs, flush, getISOBytes, isCloseStream, isPaused, newPage, pause, resetPageCount, resume, setCloseStream, setMarginMirroring, setMarginMirroringTopBottom, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart
-
-
-
-
Field Detail
-
COUNTER
protected Counter COUNTER
-
file
protected RandomAccessFileOrArray file
-
closed
protected boolean closed
-
acroFields
protected AcroFields acroFields
-
flat
protected boolean flat
-
flatFreeText
protected boolean flatFreeText
-
flatannotations
protected boolean flatannotations
-
namePtr
protected int[] namePtr
-
useVp
protected boolean useVp
-
viewerPreferences
protected PdfViewerPreferencesImp viewerPreferences
-
fieldTemplates
protected HashSet<PdfTemplate> fieldTemplates
-
fieldsAdded
protected boolean fieldsAdded
-
sigFlags
protected int sigFlags
-
append
protected boolean append
-
marked
protected IntHashtable marked
-
initialXrefSize
protected int initialXrefSize
-
openAction
protected PdfAction openAction
-
-
Method Detail
-
readColorProfile
protected void readColorProfile()
-
setOutputIntents
public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) throws IOException
Description copied from class:PdfWriter
Sets the values of the output intent dictionary. Null values are allowed to suppress any key.- Overrides:
setOutputIntents
in classPdfWriter
- Parameters:
outputConditionIdentifier
- a valueoutputCondition
- a valueregistryName
- a valueinfo
- a valuecolorProfile
- a value- Throws:
IOException
- on error- See Also:
PdfWriter.setOutputIntents(String, String, String, String, ICC_Profile)
-
setPDFXConformance
public void setPDFXConformance(int pdfx)
Always throws an exception since PDF/X conformance level cannot be set for PDF/A conformant documents.- Overrides:
setPDFXConformance
in classPdfWriter
- Parameters:
pdfx
-- See Also:
PdfXConformance.setPDFXConformance(int)
-
getTtfUnicodeWriter
protected TtfUnicodeWriter getTtfUnicodeWriter()
- Overrides:
getTtfUnicodeWriter
in classPdfWriter
- See Also:
PdfWriter.getTtfUnicodeWriter()
-
createXmpWriter
protected XmpWriter createXmpWriter(ByteArrayOutputStream baos, PdfDictionary info) throws IOException
- Overrides:
createXmpWriter
in classPdfWriter
- Throws:
IOException
- See Also:
PdfWriter.createXmpWriter(java.io.ByteArrayOutputStream, com.itextpdf.text.pdf.PdfDictionary)
-
createXmpWriter
protected XmpWriter createXmpWriter(ByteArrayOutputStream baos, HashMap<String,String> info) throws IOException
- Overrides:
createXmpWriter
in classPdfWriter
- Throws:
IOException
-
initPdfIsoConformance
protected PdfIsoConformance initPdfIsoConformance()
- Overrides:
initPdfIsoConformance
in classPdfWriter
- See Also:
PdfWriter.initPdfIsoConformance()
-
getCounter
protected Counter getCounter()
-
cacheObject
protected void cacheObject(PdfIndirectObject iobj)
Description copied from class:PdfWriter
Use this method for caching objects.- Overrides:
cacheObject
in classPdfWriter
- See Also:
PdfIndirectObject
-
close
protected void close(Map<String,String> moreInfo) throws IOException
- Throws:
IOException
-
createAnnotation
public PdfAnnotation createAnnotation(Rectangle rect, PdfName subtype)
Description copied from class:PdfWriter
A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Overrides:
createAnnotation
in classPdfWriter
- Returns:
-
createAnnotation
public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfString title, PdfString content, PdfName subtype)
Description copied from class:PdfWriter
A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Overrides:
createAnnotation
in classPdfWriter
- Returns:
-
createAnnotation
public PdfAnnotation createAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype)
Description copied from class:PdfWriter
A wrapper around PdfAnnotation constructor. It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.- Overrides:
createAnnotation
in classPdfWriter
- Returns:
-
getXmpMeta
public XMPMeta getXmpMeta()
-
setViewerPreferences
protected void setViewerPreferences()
-
close
protected void close(PdfIndirectReference info, int skipInfo) throws IOException
- Throws:
IOException
-
alterContents
protected void alterContents() throws IOException
- Throws:
IOException
-
getNewObjectNumber
protected int getNewObjectNumber(PdfReader reader, int number, int generation)
- Overrides:
getNewObjectNumber
in classPdfWriter
-
registerReader
public void registerReader(PdfReader reader, boolean openFile) throws IOException
- Parameters:
reader
-openFile
-- Throws:
IOException
-
unRegisterReader
public void unRegisterReader(PdfReader reader)
- Parameters:
reader
-
-
addComments
public void addComments(FdfReader fdf) throws IOException
- Parameters:
fdf
-- Throws:
IOException
-
flatFields
protected void flatFields()
-
setFlatAnnotations
public void setFlatAnnotations(boolean flatAnnotations)
If true, annotations with an appearance stream will be flattened.- Parameters:
flatAnnotations
- boolean- Since:
- 5.5.3
-
flattenAnnotations
protected void flattenAnnotations()
If setFlatAnnotations is set to true, iText will flatten all annotations with an appearance stream- Since:
- 5.5.3
-
flatFreeTextFields
protected void flatFreeTextFields()
-
getPageReference
public PdfIndirectReference getPageReference(int page)
Description copied from class:PdfWriter
Use this method to get a reference to a page existing or not. If the page does not exist yet the reference will be created in advance. If on closing the document, a page number greater than the total number of pages was requested, an exception is thrown.- Overrides:
getPageReference
in classPdfWriter
- Parameters:
page
- the page number. The first page is 1- Returns:
- the reference to the page
- See Also:
PdfWriter.getPageReference(int)
-
addAnnotation
public void addAnnotation(PdfAnnotation annot)
Description copied from interface:PdfAnnotations
Use this methods to add aPdfAnnotation
or aPdfFormField
to the document. Only the top parent of aPdfFormField
needs to be added.- Specified by:
addAnnotation
in interfacePdfAnnotations
- Overrides:
addAnnotation
in classPdfWriter
- Parameters:
annot
- thePdfAnnotation
or thePdfFormField
to add- See Also:
PdfWriter.addAnnotation(com.itextpdf.text.pdf.PdfAnnotation)
-
addFieldResources
protected void addFieldResources() throws IOException
- Throws:
IOException
-
setJavaScript
protected void setJavaScript() throws IOException
- Throws:
IOException
-
addFileAttachments
protected void addFileAttachments() throws IOException
- Throws:
IOException
-
setOutlines
protected void setOutlines() throws IOException
- Throws:
IOException
-
setViewerPreferences
public void setViewerPreferences(int preferences)
Sets the viewer preferences.- Specified by:
setViewerPreferences
in interfacePdfViewerPreferences
- Overrides:
setViewerPreferences
in classPdfWriter
- Parameters:
preferences
- the viewer preferences- See Also:
PdfWriter.setViewerPreferences(int)
-
addViewerPreference
public void addViewerPreference(PdfName key, PdfObject value)
Adds a viewer preference- Specified by:
addViewerPreference
in interfacePdfViewerPreferences
- Overrides:
addViewerPreference
in classPdfWriter
- Parameters:
key
- a key for a viewer preferencevalue
- the value for the viewer preference- See Also:
PdfViewerPreferences.addViewerPreference(com.itextpdf.text.pdf.PdfName, com.itextpdf.text.pdf.PdfObject)
-
setSigFlags
public void setSigFlags(int f)
Set the signature flags.- Specified by:
setSigFlags
in interfacePdfAnnotations
- Overrides:
setSigFlags
in classPdfWriter
- Parameters:
f
- the flags. This flags are ORed with current ones- See Also:
PdfAnnotations.setSigFlags(int)
-
setPageAction
public void setPageAction(PdfName actionType, PdfAction action) throws PdfException
Always throws anUnsupportedOperationException
.- Specified by:
setPageAction
in interfacePdfPageActions
- Overrides:
setPageAction
in classPdfWriter
- Parameters:
actionType
- ignoreaction
- ignore- Throws:
PdfException
- ignore- See Also:
PdfStamper.setPageAction(PdfName, PdfAction, int)
-
setDuration
public void setDuration(int seconds)
Always throws anUnsupportedOperationException
.- Specified by:
setDuration
in interfacePdfPageActions
- Overrides:
setDuration
in classPdfWriter
- Parameters:
seconds
- ignore- See Also:
PdfPageActions.setDuration(int)
-
setTransition
public void setTransition(PdfTransition transition)
Always throws anUnsupportedOperationException
.- Specified by:
setTransition
in interfacePdfPageActions
- Overrides:
setTransition
in classPdfWriter
- Parameters:
transition
- ignore- See Also:
PdfPageActions.setTransition(com.itextpdf.text.pdf.PdfTransition)
-
markUsed
protected void markUsed(PdfObject obj)
-
markUsed
protected void markUsed(int num)
-
getPdfReader
public PdfReader getPdfReader()
-
setAdditionalAction
public void setAdditionalAction(PdfName actionType, PdfAction action) throws PdfException
Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole. The actions types allowed are:DOCUMENT_CLOSE
,WILL_SAVE
,DID_SAVE
,WILL_PRINT
andDID_PRINT
.- Specified by:
setAdditionalAction
in interfacePdfDocumentActions
- Overrides:
setAdditionalAction
in classPdfWriter
- Parameters:
actionType
- the action typeaction
- the action to execute in response to the trigger- Throws:
PdfException
- on invalid action type- See Also:
PdfDocumentActions.setAdditionalAction(com.itextpdf.text.pdf.PdfName, com.itextpdf.text.pdf.PdfAction)
-
setOpenAction
public void setOpenAction(PdfAction action)
Description copied from interface:PdfDocumentActions
When the document opens thisaction
will be invoked.- Specified by:
setOpenAction
in interfacePdfDocumentActions
- Overrides:
setOpenAction
in classPdfWriter
- Parameters:
action
- the action to be invoked- See Also:
PdfWriter.setOpenAction(com.itextpdf.text.pdf.PdfAction)
-
setOpenAction
public void setOpenAction(String name)
Description copied from interface:PdfDocumentActions
When the document opens it will jump to the destination with this name.- Specified by:
setOpenAction
in interfacePdfDocumentActions
- Overrides:
setOpenAction
in classPdfWriter
- Parameters:
name
- the name of the destination to jump to- See Also:
PdfWriter.setOpenAction(java.lang.String)
-
setThumbnail
public void setThumbnail(Image image)
Description copied from class:PdfWriter
Use this method to set the thumbnail image for the current page.- Overrides:
setThumbnail
in classPdfWriter
- Parameters:
image
- the image- See Also:
PdfWriter.setThumbnail(com.itextpdf.text.Image)
-
getDirectContentUnder
public PdfContentByte getDirectContentUnder()
Description copied from class:PdfWriter
Use this method to get the direct content under for this document. There is only one direct content, multiple calls to this method will always retrieve the same object.- Overrides:
getDirectContentUnder
in classPdfWriter
- Returns:
- the direct content
-
getDirectContent
public PdfContentByte getDirectContent()
Description copied from class:PdfWriter
Use this method to get the direct content for this document. There is only one direct content, multiple calls to this method will allways retrieve the same object.- Overrides:
getDirectContent
in classPdfWriter
- Returns:
- the direct content
-
readOCProperties
protected void readOCProperties()
Reads the OCProperties dictionary from the catalog of the existing document and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter. Note that the original OCProperties of the existing document can contain more information.- Since:
- 2.1.2
-
getPdfLayers
public Map<String,PdfLayer> getPdfLayers()
Gets the PdfLayer objects in an existing document as a Map with the names/titles of the layers as keys.- Returns:
- a Map with all the PdfLayers in the document (and the name/title of the layer as key)
- Since:
- 2.1.2
-
createXmpMetadata
public void createXmpMetadata()
Description copied from class:PdfWriter
Use this method to creates XMP Metadata based on the metadata in the PdfDocument.- Overrides:
createXmpMetadata
in classPdfWriter
-
updateNamedDestinations
protected void updateNamedDestinations() throws IOException
- Throws:
IOException
-
-