Package org.openpdf.text.pdf
Class PdfStamperImp
java.lang.Object
org.openpdf.text.DocWriter
org.openpdf.text.pdf.PdfWriter
org.openpdf.text.pdf.PdfStamperImp
- All Implemented Interfaces:
AutoCloseable,EventListener,DocListener,ElementListener,PdfAnnotations,PdfDocumentActions,PdfEncryptionSettings,PdfPageActions,PdfRunDirection,PdfVersion,PdfViewerPreferences,PdfXConformance
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.openpdf.text.pdf.PdfWriter
PdfWriter.PdfBody, PdfWriter.PdfTrailer -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AcroFieldsprotected boolean(package private) booleanprotected booleanprotected Map<PdfTemplate,Object> (package private) RandomAccessFileOrArrayprotected booleanprotected booleanprivate booleanprotected intprotected IntHashtableprivate Calendar(package private) IntHashtableprotected int[]protected PdfActionprivate PdfObject(package private) HashMap<PdfDictionary,PdfStamperImp.PageStamp> Integer(page number) -> PageStamp(package private) PdfReader(package private) HashMap<PdfReader,RandomAccessFileOrArray> (package private) HashMap<PdfReader,IntHashtable> private booleanHolds value of property rotateContents.protected intprivate booleanprivate booleanprotected booleanprotected PdfViewerPreferencesImpFields inherited from class org.openpdf.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, colorNumber, 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_V3, ENCRYPTION_MASK, ENCRYPTION_NONE, extraCatalog, FitWindow, fontNumber, formXObjects, formXObjectsCounter, fullCompression, GENERATION_MAX, group, HideMenubar, HideToolbar, HideWindowUI, imageDictionary, importedPages, JBIG2Globals, newBookmarks, NO_SPACE_CHAR_RATIO, NonFullScreenPageModeUseNone, NonFullScreenPageModeUseOC, NonFullScreenPageModeUseOutlines, NonFullScreenPageModeUseThumbs, OCGLocked, OCGRadioGroup, OCProperties, PAGE_CLOSE, PAGE_OPEN, 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, PDFA1A, PDFA1B, PDFX1A2001, PDFX32002, PDFXNONE, prevxref, PrintScalingNone, 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, structureTreeRoot, tabs, tagged, userunit, 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
ConstructorsConstructorDescriptionPdfStamperImp(PdfReader reader, OutputStream os, char pdfVersion, boolean append) Creates new PdfStamperImp. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(PdfAnnotation annot) Use this methods to add aPdfAnnotationor aPdfFormFieldto the document.voidaddAnnotation(PdfAnnotation annot, int page) (package private) voidaddAnnotation(PdfAnnotation annotation, PdfDictionary pageN) private voidAllows to add e.g.voidaddComments(FdfReader fdf) (package private) void(package private) void(package private) voidprivate voidRecursive method to reconstruct the documentOCGorder variable in the writer.voidaddViewerPreference(PdfName key, PdfObject value) Adds a viewer preference(package private) void(package private) void(package private) voidapplyRotation(PdfDictionary pageN, ByteBuffer out) (package private) void(package private) voidcorrectAcroFieldPages(int page) (package private) void(package private) void(package private) voidexpandFields(PdfFormField field, List<PdfAnnotation> annotations) (package private) static voidfindAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits) (package private) voidprivate void(package private) AcroFieldsUse this method to get the direct content for this document.Use this method to get the direct content under for this document.(package private) PdfDictionarygetInfoDictionary(PdfDictionary oldInfo, PdfDate modificationDate, String producer, Map<String, String> moreInfo) protected intgetNewObjectNumber(PdfReader reader, int number, int generation) (package private) PdfContentBytegetOverContent(int pageNum) getPageReference(int page) Use this method to get a reference to a page existing or not.(package private) PdfStamperImp.PageStampgetPageStamp(int pageNum) Gets the PdfLayer objects in an existing document as a Map with the names/titles of the layers as keys.(package private) RandomAccessFileOrArraygetReaderFile(PdfReader reader) (package private) PdfContentBytegetUnderContent(int pageNum) (package private) voidinsertPage(int pageNumber, Rectangle mediabox) (package private) booleanisAppend()Getter for property append.(package private) booleanbooleanThese methods are used by PdfStamper to override some PDF properties when signing PDF files.(package private) booleanGetter for property rotateContents.booleanboolean(package private) voidmakePackage(PdfCollection collection) Adds or replaces the Collection Dictionary in the Catalog.protected voidmarkUsed(int num) protected voidprivate static voidmoveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) private voidoutlineTravel(PRIndirectReference outline) (package private) booleanpartialFormFlattening(String name) protected voidReads the OCProperties dictionary from the catalog of the existing document and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter.voidregisterReader(PdfReader reader, boolean openFile) voidRemoves the encryption from the document (and also inherently the permissions)(package private) voidreplacePage(PdfReader r, int pageImported, int pageReplaced) voidsetAdditionalAction(PdfName actionType, PdfAction action) Additional-actions defining the actions to be taken in response to various trigger events affecting the document as a whole.voidsetDuration(int seconds) Always throws anUnsupportedOperationException.(package private) voidsetDuration(int seconds, int page) Sets the display duration for the page (for presentations)(package private) voidsetFormFlattening(boolean flat) (package private) voidsetFreeTextFlattening(boolean flat) voidsetIncludeFileID(boolean includeFileID) (package private) voidvoidsetModificationDate(Calendar modificationDate) voidsetOpenAction(String name) When the document opens it will jump to the destination with this name.voidsetOpenAction(PdfAction action) When the document opens thisactionwill be invoked.(package private) voidvoidsetOverrideFileId(PdfObject overrideFileId) voidsetPageAction(PdfName actionType, PdfAction action) Always throws anUnsupportedOperationException.(package private) voidsetPageAction(PdfName actionType, PdfAction action, int page) Sets the open and close page additional action.(package private) voidsetRotateContents(boolean rotateContents) Setter for property rotateContents.voidsetSigFlags(int f) Set the signature flags.voidsetThumbnail(Image image) Use this method to set the thumbnail image for the current page.(package private) voidsetThumbnail(Image image, int page) voidsetTransition(PdfTransition transition) Always throws anUnsupportedOperationException.(package private) voidsetTransition(PdfTransition transition, int page) Sets the transition for the pagevoidsetUpdateDocInfo(boolean updateDocInfo) voidsetUpdateMetadata(boolean updateMetadata) voidsetViewerPreferences(int preferences) Sets the viewer preferences.(package private) voidvoidunRegisterReader(PdfReader reader) Methods inherited from class org.openpdf.text.pdf.PdfWriter
add, add, add, addCalculationOrder, addDeveloperExtension, addDirectImageSimple, addDirectImageSimple, addDirectTemplateSimple, addFileAttachment, addFileAttachment, addFileAttachment, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addJavaScript, addLocalDestinations, addNamedDestination, addNamedDestinations, addOCGRadioGroup, addSharedObjectsToBody, addSimple, addSimple, addSimpleExtGState, addSimplePattern, addSimplePatternColorspace, addSimpleProperty, addSimpleShading, addSimpleShadingPattern, addToBody, addToBody, addToBody, addToBody, addToBody, addToBody, clearTextWrap, close, createXmpMetadata, eliminateFontSubset, fillOCProperties, fitsPage, fitsPage, freeReader, getAcroForm, getBoxSize, getCatalog, getColorspaceName, getCompressionLevel, getCurrentDocumentSize, getCurrentPage, getCurrentPageNumber, getDefaultColorspace, getEncryption, getExtraCatalog, getGroup, getImageReference, getImportedPage, getIndirectReferenceNumber, getInfo, getInstance, getInstance, getOCProperties, getOs, getPageEvent, getPageNumber, getPageSize, getPdfDocument, getPdfIndirectReference, getPdfVersion, getPDFXConformance, getReferenceJBIG2Globals, getRootOutline, getRunDirection, getSpaceCharRatio, getStructureTreeRoot, getTabs, getUserunit, getVerticalPosition, isFullCompression, isPageEmpty, isPdfA1, isPdfX, isRgbTransparencyBlending, isStrictImageSequence, isTagged, isUserProperties, lockLayer, open, propertyExists, registerLayer, releaseTemplate, reorderPages, resetContent, setAtLeastPdfVersion, setBoxSize, setCollection, setCompressionLevel, setCropBoxSize, setDefaultColorspace, setEncryption, setEncryption, setFullCompression, setGroup, setInitialLeading, setLinearPageMode, setOutlines, setOutputIntents, setOutputIntents, setOutputIntents, setPageEmpty, setPageEvent, setPageLabels, setPageXmpMetadata, setPdfVersion, setPdfVersion, setPDFXConformance, setRgbTransparencyBlending, setRunDirection, setSpaceCharRatio, setStrictImageSequence, setTabs, setTagged, setUserProperties, setUserunit, setXmpMetadata, writeOutlinesMethods inherited from class org.openpdf.text.DocWriter
add, addTabs, flush, getISOBytes, isCloseStream, isPaused, newPage, pause, resetFooter, resetHeader, resetPageCount, resume, setCloseStream, setFooter, setHeader, setMarginMirroring, setMarginMirroringTopBottom, setMargins, setPageCount, setPageSize, write, write, writeEnd, writeEnd, writeMarkupAttributes, writeStart
-
Field Details
-
acroFields
-
flat
protected boolean flat -
flatFreeText
protected boolean flatFreeText -
namePtr
protected int[] namePtr -
partialFlattening
-
useVp
protected boolean useVp -
viewerPreferences
-
fieldTemplates
-
fieldsAdded
protected boolean fieldsAdded -
sigFlags
protected int sigFlags -
append
protected boolean append -
marked
-
initialXrefSize
protected int initialXrefSize -
openAction
-
readers2intrefs
HashMap<PdfReader,IntHashtable> readers2intrefs -
readers2file
HashMap<PdfReader,RandomAccessFileOrArray> readers2file -
file
-
reader
PdfReader reader -
myXref
IntHashtable myXref -
pagesToContent
HashMap<PdfDictionary,PdfStamperImp.PageStamp> pagesToContentInteger(page number) -> PageStamp -
closed
boolean closed -
rotateContents
private boolean rotateContentsHolds value of property rotateContents. -
includeFileID
private boolean includeFileID -
overrideFileId
-
modificationDate
-
updateMetadata
private boolean updateMetadata -
updateDocInfo
private boolean updateDocInfo
-
-
Constructor Details
-
PdfStamperImp
PdfStamperImp(PdfReader reader, OutputStream os, char pdfVersion, boolean append) throws DocumentException, 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 errorIOException
-
-
Method Details
-
findAllObjects
-
moveRectangle
private static void moveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) -
close
- Throws:
IOException
-
getInfoDictionary
PdfDictionary getInfoDictionary(PdfDictionary oldInfo, PdfDate modificationDate, String producer, Map<String, String> moreInfo) -
applyRotation
-
alterContents
- Throws:
IOException
-
alterResources
-
getNewObjectNumber
- Overrides:
getNewObjectNumberin classPdfWriter
-
getReaderFile
- Overrides:
getReaderFilein classPdfWriter
-
removeEncryption
Removes the encryption from the document (and also inherently the permissions)- Throws:
DocumentException
-
registerReader
- Parameters:
reader-openFile-- Throws:
IOException
-
unRegisterReader
- Parameters:
reader-
-
addComments
- Parameters:
fdf-- Throws:
IOException
-
getPageStamp
-
getUnderContent
-
getOverContent
-
correctAcroFieldPages
void correctAcroFieldPages(int page) -
replacePage
-
insertPage
-
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) -
partialFormFlattening
-
flatFields
void flatFields() -
eliminateAcroformObjects
void eliminateAcroformObjects() -
sweepKids
-
flatFreeTextFields
private void flatFreeTextFields() -
getPageReference
Description copied from class:PdfWriterUse 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:
getPageReferencein classPdfWriter- Parameters:
page- the page number. The first page is 1- Returns:
- the reference to the page
- See Also:
-
addDocumentField
-
addFieldResources
- Throws:
IOException
-
expandFields
-
addAnnotation
-
addAnnotationToDocument
Allows to add e.g. a Radiogroup without specifying a page for the data field parent. The parent (data) form field isn't located on a page thus it doesn't make sense to specify one.- Parameters:
annot- annotation to be added
-
addAnnotation
- Overrides:
addAnnotationin classPdfWriter
-
addAnnotation
Description copied from interface:PdfAnnotationsUse this methods to add aPdfAnnotationor aPdfFormFieldto the document. Only the top parent of aPdfFormFieldneeds to be added.- Specified by:
addAnnotationin interfacePdfAnnotations- Overrides:
addAnnotationin classPdfWriter- Parameters:
annot- thePdfAnnotationor thePdfFormFieldto add- See Also:
-
outlineTravel
-
deleteOutlines
void deleteOutlines() -
setJavaScript
- Throws:
IOException
-
addFileAttachments
- Throws:
IOException
-
makePackage
Adds or replaces the Collection Dictionary in the Catalog.- Parameters:
collection- the new collection dictionary.
-
setOutlines
- Throws:
IOException
-
setViewerPreferences
public void setViewerPreferences(int preferences) Sets the viewer preferences.- Specified by:
setViewerPreferencesin interfacePdfViewerPreferences- Overrides:
setViewerPreferencesin classPdfWriter- Parameters:
preferences- the viewer preferences- See Also:
-
addViewerPreference
Adds a viewer preference- Specified by:
addViewerPreferencein interfacePdfViewerPreferences- Overrides:
addViewerPreferencein classPdfWriter- Parameters:
key- a key for a viewer preferencevalue- the value for the viewer preference- See Also:
-
setSigFlags
public void setSigFlags(int f) Set the signature flags.- Specified by:
setSigFlagsin interfacePdfAnnotations- Overrides:
setSigFlagsin classPdfWriter- Parameters:
f- the flags. This flags are ORed with current ones- See Also:
-
setPageAction
Always throws anUnsupportedOperationException.- Specified by:
setPageActionin interfacePdfPageActions- Overrides:
setPageActionin classPdfWriter- Parameters:
actionType- ignoreaction- ignore- Throws:
PdfException- ignore- See Also:
-
setPageAction
Sets the open and close page additional action.- Parameters:
actionType- the action type. It can bePdfWriter.PAGE_OPENorPdfWriter.PAGE_CLOSEaction- the action to performpage- the page where the action will be applied. The first page is 1- Throws:
PdfException- if the action type is invalid
-
setDuration
public void setDuration(int seconds) Always throws anUnsupportedOperationException.- Specified by:
setDurationin interfacePdfPageActions- Overrides:
setDurationin classPdfWriter- Parameters:
seconds- ignore- See Also:
-
setTransition
Always throws anUnsupportedOperationException.- Specified by:
setTransitionin interfacePdfPageActions- Overrides:
setTransitionin classPdfWriter- Parameters:
transition- ignore- See Also:
-
setDuration
void setDuration(int seconds, int page) Sets the display duration for the page (for presentations)- Parameters:
seconds- the number of seconds to display the page. A negative value removes the entrypage- the page where the duration will be applied. The first page is 1
-
setTransition
Sets the transition for the page- Parameters:
transition- the transition object. Anullremoves the transitionpage- the page where the transition will be applied. The first page is 1
-
markUsed
-
markUsed
protected void markUsed(int num) -
isAppend
boolean isAppend()Getter for property append.- Returns:
- Value of property append.
-
setAdditionalAction
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_PRINTandDID_PRINT.- Specified by:
setAdditionalActionin interfacePdfDocumentActions- Overrides:
setAdditionalActionin classPdfWriter- Parameters:
actionType- the action typeaction- the action to execute in response to the trigger- Throws:
PdfException- on invalid action type- See Also:
-
setOpenAction
Description copied from interface:PdfDocumentActionsWhen the document opens thisactionwill be invoked.- Specified by:
setOpenActionin interfacePdfDocumentActions- Overrides:
setOpenActionin classPdfWriter- Parameters:
action- the action to be invoked- See Also:
-
setOpenAction
Description copied from interface:PdfDocumentActionsWhen the document opens it will jump to the destination with this name.- Specified by:
setOpenActionin interfacePdfDocumentActions- Overrides:
setOpenActionin classPdfWriter- Parameters:
name- the name of the destination to jump to- See Also:
-
setThumbnail
Description copied from class:PdfWriterUse this method to set the thumbnail image for the current page.- Overrides:
setThumbnailin classPdfWriter- Parameters:
image- the image- See Also:
-
setThumbnail
- Throws:
DocumentException
-
getDirectContentUnder
Description copied from class:PdfWriterUse 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:
getDirectContentUnderin classPdfWriter- Returns:
- the direct content
-
getDirectContent
Description copied from class:PdfWriterUse 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:
getDirectContentin 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
-
addOrder
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
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
-
isIncludeFileID
public boolean isIncludeFileID()These methods are used by PdfStamper to override some PDF properties when signing PDF files. -
setIncludeFileID
public void setIncludeFileID(boolean includeFileID) -
getOverrideFileId
-
setOverrideFileId
-
getModificationDate
-
setModificationDate
-
isUpdateMetadata
public boolean isUpdateMetadata() -
setUpdateMetadata
public void setUpdateMetadata(boolean updateMetadata) -
isUpdateDocInfo
public boolean isUpdateDocInfo() -
setUpdateDocInfo
public void setUpdateDocInfo(boolean updateDocInfo)
-