Package com.aowagie.text.pdf
Class PdfStamperImp
- java.lang.Object
-
- com.aowagie.text.DocWriter
-
- com.aowagie.text.pdf.PdfWriter
-
- com.aowagie.text.pdf.PdfStamperImp
-
- All Implemented Interfaces:
DocListener
,ElementListener
,PdfAnnotations
,PdfDocumentActions
,PdfEncryptionSettings
,PdfPageActions
,PdfRunDirection
,PdfVersion
,PdfViewerPreferences
,PdfXConformance
,java.util.EventListener
public class PdfStamperImp extends PdfWriter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
PdfStamperImp.PageStamp
-
Nested classes/interfaces inherited from class com.aowagie.text.pdf.PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer
-
-
Field Summary
Fields Modifier and Type Field Description private AcroFields
acroFields
private boolean
append
private boolean
closed
private boolean
fieldsAdded
private java.util.HashMap
fieldTemplates
private RandomAccessFileOrArray
file
private boolean
flat
private boolean
flatFreeText
private int
initialXrefSize
private IntHashtable
marked
private IntHashtable
myXref
private int[]
namePtr
private PdfAction
openAction
private java.util.HashMap
pagesToContent
Integer(page number) -> PageStampprivate java.util.HashSet
partialFlattening
private PdfObject
pdfFileID
(package private) PdfReader
reader
private java.util.HashMap
readers2file
private java.util.HashMap
readers2intrefs
private boolean
rotateContents
Holds value of property rotateContents.private int
sigFlags
private boolean
useVp
private PdfViewerPreferencesImp
viewerPreferences
-
Fields inherited from class com.aowagie.text.pdf.PdfWriter
ALLOW_ASSEMBLY, ALLOW_COPY, ALLOW_DEGRADED_PRINTING, ALLOW_FILL_IN, ALLOW_MODIFY_ANNOTATIONS, ALLOW_MODIFY_CONTENTS, ALLOW_PRINTING, ALLOW_SCREENREADERS, body, CenterWindow, compressionLevel, crypto, currentPdfReaderInstance, DID_PRINT, DID_SAVE, DirectionL2R, DirectionR2L, DisplayDocTitle, DO_NOT_ENCRYPT_METADATA, DOCUMENT_CLOSE, documentOCG, EMBEDDED_FILES_ONLY, ENCRYPTION_AES_128, ENCRYPTION_MASK, FitWindow, fullCompression, GENERATION_MAX, HideMenubar, HideToolbar, HideWindowUI, newBookmarks, NonFullScreenPageModeUseNone, NonFullScreenPageModeUseOC, NonFullScreenPageModeUseOutlines, NonFullScreenPageModeUseThumbs, OCGLocked, OCGRadioGroup, OCProperties, PageLayoutOneColumn, PageLayoutSinglePage, PageLayoutTwoColumnLeft, PageLayoutTwoColumnRight, PageLayoutTwoPageLeft, PageLayoutTwoPageRight, PageModeFullScreen, PageModeUseAttachments, PageModeUseNone, PageModeUseOC, PageModeUseOutlines, PageModeUseThumbs, 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, PDFA1A, PDFA1B, PDFA2A, PDFA2B, PDFX1A2001, PDFX32002, PDFXNONE, prevxref, PrintScalingNone, root, RUN_DIRECTION_DEFAULT, RUN_DIRECTION_LTR, RUN_DIRECTION_NO_BIDI, RUN_DIRECTION_RTL, STANDARD_ENCRYPTION_128, STANDARD_ENCRYPTION_40, VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_1_6, VERSION_1_7, WILL_PRINT, WILL_SAVE, xmpMetadata
-
-
Constructor Summary
Constructors Constructor Description PdfStamperImp(PdfReader reader, java.io.OutputStream os, char pdfVersion, boolean append, java.util.Calendar globalDate)
Creates new PdfStamperImp.
-
Method Summary
All Methods Static 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.(package private) void
addAnnotation(PdfAnnotation annot, int page)
(package private) void
addAnnotation(PdfAnnotation annot, PdfDictionary pageN)
private void
addDocumentField(PdfIndirectReference ref)
private void
addFieldResources()
private void
addFileAttachments()
private void
addOrder(PdfLayer parent, PdfArray arr, java.util.Map ocgmap)
Recursive method to reconstruct the documentOCGorder variable in the writer.void
addViewerPreference(PdfName key, PdfObject value)
Adds a viewer preferenceprivate void
alterContents()
private void
alterResources(PdfStamperImp.PageStamp ps)
private void
applyRotation(PdfDictionary pageN, ByteBuffer out)
(package private) void
close(java.util.Map moreInfo, java.util.Calendar globalDate)
private void
correctAcroFieldPages(int page)
private void
deleteOutlines()
private void
eliminateAcroformObjects()
private void
expandFields(PdfFormField field, java.util.ArrayList allAnnots)
private static void
findAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits)
private void
flatFields()
private void
flatFreeTextFields()
(package private) AcroFields
getAcroFields()
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.PdfObject
getFileID()
protected int
getNewObjectNumber(PdfReader reader, int number, int generation)
(package private) PdfContentByte
getOverContent(int pageNum)
PdfIndirectReference
getPageReference(int page)
Use this method to get a reference to a page existing or not.private PdfStamperImp.PageStamp
getPageStamp(int pageNum)
java.util.Map
getPdfLayers()
Gets the PdfLayer objects in an existing document as a Map with the names/titles of the layers as keys.(package private) RandomAccessFileOrArray
getReaderFile(PdfReader reader)
(package private) void
insertPage(int pageNumber, Rectangle mediabox)
(package private) boolean
isAppend()
Getter for property append.(package private) boolean
isContentWritten()
(package private) boolean
isRotateContents()
Getter for property rotateContents.protected void
markUsed(PdfObject obj)
private static void
moveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, java.lang.String name)
private void
outlineTravel(PRIndirectReference outline)
private void
readOCProperties()
Reads the OCProperties dictionary from the catalog of the existing document and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter.private 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
.(package private) void
setFormFlattening(boolean flat)
(package private) void
setFreeTextFlattening(boolean flat)
private void
setJavaScript()
void
setOpenAction(PdfAction action)
When the document opens thisaction
will be invoked.void
setOpenAction(java.lang.String name)
When the document opens it will jump to the destination with this name.private void
setOutlines()
void
setPageAction(PdfName actionType, PdfAction action)
Always throws anUnsupportedOperationException
.(package private) void
setRotateContents(boolean rotateContents)
Setter for property rotateContents.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
.void
setViewerPreferences(int preferences)
Sets the viewer preferences.private void
sweepKids(PdfObject obj)
-
Methods inherited from class com.aowagie.text.pdf.PdfWriter
add, addDeveloperExtension, addDirectImageSimple, addDirectTemplateSimple, addFileAttachment, addFileAttachment, addJavaScript, addLocalDestinations, addSharedObjectsToBody, addSimple, addSimple, addSimpleExtGState, addSimplePattern, addSimplePatternColorspace, addSimpleProperty, addSimpleShading, addSimpleShadingPattern, addToBody, addToBody, addToBody, addToBody, addToBody, addToBody, close, createXmpMetadata, eliminateFontSubset, fillOCProperties, freeReader, getAcroForm, getCatalog, getColorspaceName, getCompressionLevel, getCurrentDocumentSize, getCurrentPage, getCurrentPageNumber, getDefaultColorspace, getEncryption, getExtraCatalog, getGroup, getImageReference, getImportedPage, getIndirectReferenceNumber, getInfo, getInstance, getOCProperties, getPageEvent, getPageNumber, getPageSize, getPdfDocument, getPdfIndirectReference, getPdfVersion, getPDFXConformance, getReferenceJBIG2Globals, getRootOutline, getRunDirection, getSpaceCharRatio, getStructureTreeRoot, getTabs, getUserunit, isFullCompression, isPdfX, isRgbTransparencyBlending, isStrictImageSequence, isTagged, isUserProperties, open, propertyExists, registerLayer, releaseTemplate, resetContent, setAtLeastPdfVersion, setCollection, setCompressionLevel, setCropBoxSize, setEncryption, setEncryption, setFullCompression, setGroup, setInitialLeading, setOutlines, setOutputIntents, setPageEmpty, setPageEvent, setPageLabels, setPageXmpMetadata, setPdfVersion, setPdfVersion, setPDFXConformance, setRgbTransparencyBlending, setRunDirection, setSpaceCharRatio, setStrictImageSequence, setTabs, setTagged, setUserProperties, setUserunit, setXmpMetadata, writeOutlines
-
Methods inherited from class com.aowagie.text.DocWriter
add, getISOBytes, isCloseStream, isPaused, newPage, resetFooter, resetHeader, resetPageCount, setCloseStream, setFooter, setHeader, setMarginMirroring, setMarginMirroringTopBottom, setMargins, setPageCount, setPageSize
-
-
-
-
Field Detail
-
pdfFileID
private PdfObject pdfFileID
-
readers2intrefs
private final java.util.HashMap readers2intrefs
-
readers2file
private final java.util.HashMap readers2file
-
file
private final RandomAccessFileOrArray file
-
reader
PdfReader reader
-
myXref
private final IntHashtable myXref
-
pagesToContent
private final java.util.HashMap pagesToContent
Integer(page number) -> PageStamp
-
closed
private boolean closed
-
rotateContents
private boolean rotateContents
Holds value of property rotateContents.
-
acroFields
private AcroFields acroFields
-
flat
private boolean flat
-
flatFreeText
private boolean flatFreeText
-
namePtr
private final int[] namePtr
-
partialFlattening
private final java.util.HashSet partialFlattening
-
useVp
private boolean useVp
-
viewerPreferences
private final PdfViewerPreferencesImp viewerPreferences
-
fieldTemplates
private final java.util.HashMap fieldTemplates
-
fieldsAdded
private boolean fieldsAdded
-
sigFlags
private int sigFlags
-
append
private final boolean append
-
marked
private IntHashtable marked
-
initialXrefSize
private final int initialXrefSize
-
openAction
private PdfAction openAction
-
-
Constructor Detail
-
PdfStamperImp
PdfStamperImp(PdfReader reader, java.io.OutputStream os, char pdfVersion, boolean append, java.util.Calendar globalDate) throws DocumentException, java.io.IOException
Creates new PdfStamperImp.- Parameters:
reader
- the read PDFos
- the output destinationpdfVersion
- the new pdf version or '\0' to keep the same version as the original documentappend
-- Throws:
DocumentException
- on errorjava.io.IOException
-
-
Method Detail
-
close
void close(java.util.Map moreInfo, java.util.Calendar globalDate) throws java.io.IOException
- Throws:
java.io.IOException
-
applyRotation
private void applyRotation(PdfDictionary pageN, ByteBuffer out)
-
alterContents
private void alterContents() throws java.io.IOException
- Throws:
java.io.IOException
-
alterResources
private void alterResources(PdfStamperImp.PageStamp ps)
-
getNewObjectNumber
protected int getNewObjectNumber(PdfReader reader, int number, int generation)
- Overrides:
getNewObjectNumber
in classPdfWriter
-
getReaderFile
RandomAccessFileOrArray getReaderFile(PdfReader reader)
- Overrides:
getReaderFile
in classPdfWriter
-
registerReader
private void registerReader(PdfReader reader, boolean openFile) throws java.io.IOException
- Parameters:
reader
-openFile
-- Throws:
java.io.IOException
-
findAllObjects
private static void findAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits)
-
getPageStamp
private PdfStamperImp.PageStamp getPageStamp(int pageNum)
-
getOverContent
PdfContentByte getOverContent(int pageNum)
-
correctAcroFieldPages
private void correctAcroFieldPages(int page)
-
moveRectangle
private static void moveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, java.lang.String name)
-
insertPage
void insertPage(int pageNumber, Rectangle mediabox)
-
isRotateContents
boolean isRotateContents()
Getter for property rotateContents.- Returns:
- Value of property rotateContents.
-
setRotateContents
void setRotateContents(boolean rotateContents)
Setter for property rotateContents.- Parameters:
rotateContents
- New value of property rotateContents.
-
isContentWritten
boolean isContentWritten()
-
getAcroFields
AcroFields getAcroFields()
-
setFormFlattening
void setFormFlattening(boolean flat)
-
setFreeTextFlattening
void setFreeTextFlattening(boolean flat)
-
flatFields
private void flatFields()
-
eliminateAcroformObjects
private void eliminateAcroformObjects()
-
sweepKids
private void sweepKids(PdfObject obj)
-
flatFreeTextFields
private 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.aowagie.text.pdf.PdfAnnotation)
-
addDocumentField
private void addDocumentField(PdfIndirectReference ref)
-
addFieldResources
private void addFieldResources() throws java.io.IOException
- Throws:
java.io.IOException
-
expandFields
private void expandFields(PdfFormField field, java.util.ArrayList allAnnots)
-
addAnnotation
void addAnnotation(PdfAnnotation annot, PdfDictionary pageN)
-
addAnnotation
void addAnnotation(PdfAnnotation annot, int page)
- Overrides:
addAnnotation
in classPdfWriter
-
outlineTravel
private void outlineTravel(PRIndirectReference outline)
-
deleteOutlines
private void deleteOutlines()
-
setJavaScript
private void setJavaScript() throws java.io.IOException
- Throws:
java.io.IOException
-
addFileAttachments
private void addFileAttachments() throws java.io.IOException
- Throws:
java.io.IOException
-
setOutlines
private void setOutlines() throws java.io.IOException
- Throws:
java.io.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.aowagie.text.pdf.PdfName, com.aowagie.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
.- Overrides:
setPageAction
in classPdfWriter
- Parameters:
actionType
- ignoreaction
- ignore- Throws:
PdfException
- ignore
-
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.aowagie.text.pdf.PdfTransition)
-
markUsed
protected void markUsed(PdfObject obj)
-
isAppend
boolean isAppend()
Getter for property append.- Returns:
- Value of property append.
-
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
.- Overrides:
setAdditionalAction
in classPdfWriter
- Parameters:
actionType
- the action typeaction
- the action to execute in response to the trigger- Throws:
PdfException
- on invalid action type
-
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.aowagie.text.pdf.PdfAction)
-
setOpenAction
public void setOpenAction(java.lang.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.aowagie.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
private 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
-
addOrder
private void addOrder(PdfLayer parent, PdfArray arr, java.util.Map ocgmap)
Recursive method to reconstruct the documentOCGorder variable in the writer.- Parameters:
parent
- a parent PdfLayer (can be null)arr
- an array possibly containing children for the parent PdfLayerocgmap
- a HashMap with indirect reference Strings as keys and PdfLayer objects as values.- Since:
- 2.1.2
-
getPdfLayers
public java.util.Map 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
-
getFileID
public PdfObject getFileID()
-
-