Class PdfDocument
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
PdfADocument, PdfSigner.PdfSignerDocument, PdfUADocument
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PdfCatalogDocument catalog.protected booleanprotected booleanprotected booleanprotected DefaultFontStrategyprivate PageSizeDefault page size.private final DIContainerprivate final Map<PdfIndirectReference, PdfFont> private final Set<IEventHandler> private final SequenceIdprotected DocumentInfoHelperprivate EncryptedEmbeddedStreamsHandlerprotected FingerPrintprotected booleanflag determines whether to write unused objects to result documentprivate PdfDocumentInfoDocument info.protected booleanprivate static final org.slf4j.Logger(package private) MemoryLimitsAwareHandlerHandler which will be used for decompression of pdf streams.private PdfStringThe original modified (second) id when the document is read initially.private PdfStringThe original (first) id when the document is read initially.private static final PdfName[]protected PdfConformanceprotected IPdfPageFactoryprotected PdfVersionDocument version.private final List<PdfDocument.DestinationMutationInfo> To be adjusted destinations.protected final StampingPropertiesprotected PdfReaderPdfReader associated with the document.(package private) Map<PdfIndirectReference, byte[]> Cache of already serialized objects from this document for smart mode.protected SerializeOptionsprotected intprotected PdfStructTreeRootprotected TagStructureContextprotected PdfDictionaryDocument trailed.protected PdfWriterPdfWriter associated with the document.private XMPMetaXMP Metadata which is used to prevent bytes deserialization for a few times on the same bytes.private byte[]XMP Metadata bytes for the document.(package private) final PdfXrefTableList of indirect objects used in the document. -
Constructor Summary
ConstructorsConstructorDescriptionPdfDocument(PdfReader reader) Open PDF document in reading mode.PdfDocument(PdfReader reader, DocumentProperties properties) Open PDF document in reading mode.PdfDocument(PdfReader reader, PdfWriter writer) Opens PDF document in the stamping mode.PdfDocument(PdfReader reader, PdfWriter writer, StampingProperties properties) Open PDF document in stamping mode.PdfDocument(PdfWriter writer) Open PDF document in writing mode.PdfDocument(PdfWriter writer, DocumentProperties properties) Open PDF document in writing mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAssociatedFile(String description, PdfFileSpec fs) Adds file associated with PDF document as a whole and identifies the relationship between them.voidaddEventHandler(String type, AbstractPdfDocumentEventHandler handler) Adds new event handler.voidaddFileAttachment(String key, PdfFileSpec fs) Adds file attachment at document level.Adds aPdfFontinstance to this document so that this font is flushed automatically on document close.voidaddNamedDestination(PdfString key, PdfObject value) This methods adds new name in the Dests NameTree.voidaddNamedDestination(String key, PdfObject value) This methods adds new name in the Dests NameTree.Creates and adds new page to the end of document.addNewPage(int index) Creates and inserts new page to the document.addNewPage(int index, PageSize pageSize) Creates and inserts new page to the document.addNewPage(PageSize pageSize) Creates and adds new page with the specified page size.voidaddOutputIntent(PdfOutputIntent outputIntent) AddsPdfOutputIntentthat shall specify the colour characteristics of output devices on which the document might be rendered.Inserts page to the document.Adds page to the end of document.protected voidcheckAndAddPage(int index, PdfPage page) Checks page before adding and add.protected voidcheckAndAddPage(PdfPage page) Checks page before adding.protected voidchecks whether a method is invoked at the closed documentvoidcheckIsoConformance(IValidationContext validationContext) private voidcloneOutlines(Set<PdfOutline> outlinesToCopy, PdfOutline newParent, PdfOutline oldParent, Map<PdfPage, PdfPage> page2page, PdfDocument toDocument) This method copies create new outlines in the Document to copy.voidclose()Close PDF document.private voidcopyOutlines(Set<PdfOutline> outlines, PdfDocument toDocument, Map<PdfPage, PdfPage> page2page) This method copies all given outlinescopyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument) Copies a range of pages from current document totoDocumentappending copied pages to the end.copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage) Copies a range of pages from current document totoDocument.copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocument.copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocumentappending copied pages to the end.copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument) Copies a range of pages from current document totoDocumentappending copied pages to the end.copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage) Copies a range of pages from current document totoDocument.copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocument.copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocumentappending copied pages to the end.Creates next available indirect reference.voidDispatches an event.(package private) booleanprivate voidprivate voidensureTreeRootAddedToNames(PdfObject treeRoot, PdfName treeType) FindPdfFontfrom loaded fonts with corresponding fontProgram and encoding or CMAP.voidflushCopiedObjects(PdfDocument sourceDoc) Flush all copied objects and remove them from copied cache.protected voidFlushes all newly added or loaded fonts.protected voidflushObject(PdfObject pdfObject, boolean canBeInObjStm) Flush an object.private voidgetAllOutlinesToCopy(PdfOutline outline, Set<PdfOutline> outlinesToCopy) This method gets all outlines to be copied including parent outlinesReturns files associated with PDF document.Gets PDF catalog.Get thePdfConformanceGets default font for the document: Helvetica, WinAnsi.Gets default page size.Gets the container containing all available dependencies.protected Collection<PdfFont> List all newly added or loaded fontslongObtains numeric document id.Obtains document id as aSequenceId.Gets document information dictionary.Gets the encrypted payload of this document, or returnsnullif this document isn't an unencrypted wrapper document.Returns the object containing the registered products.Get the first page of the document.getFont(PdfDictionary dictionary) Create a new instance ofPdfFontor load already created one.Gets the last page of the document.Gets current memory limits handlerGets modified document idintGets next parent index of tagged document.intGets number of pages of the document.intGet number of indirect objects in the document.Gets original document idgetOutlines(boolean updateOutlines) This method returns a complete outline tree of the whole document.getPage(int pageNum) Gets the page by page number.getPage(PdfDictionary pageDictionary) Gets thePdfPageinstance byPdfDictionary.protected IPdfPageFactoryReturns the factory for creating page instances.String[]This method retrieves the page labels from a document as an array of String objects.intgetPageNumber(PdfDictionary pageDictionary) Gets page number byPdfDictionary.intgetPageNumber(PdfPage page) Gets page number by page.getPdfObject(int objNum) Gets PdfObject by object number.Gets PDF version.GetsPdfReaderassociated with the document.Gets a persistent XMP metadata serialization options.GetsPdfStructTreeRootof tagged document.Gets documentTagStructureContext.Gets document trailer.GetsPdfWriterassociated with the document.Gets XMP Metadata.getXmpMetadata(boolean createNew) Gets XMP Metadata or create a new one.byte[]Gets XMP Metadata.byte[]getXmpMetadataBytes(boolean createNew) Gets XMP Metadata or create a new one.(package private) PdfXrefTablegetXref()Gets list of indirect references.(package private) booleanbooleanChecks if provided event handler assigned for this document.booleanIndicates if the document has any outlinesvoidThis method initializes an outline tree of the document and sets outline mode to true.protected voidInitializeTagStructureContext.booleanReturnstrueif the document is opened in append mode, andfalseotherwise.booleanisClosed()Gets close status of the document.booleanChecks, whetherclose()method will close associated PdfReader.booleanChecks, whetherclose()method will close associated PdfWriter.booleanChecks if the document closing has been started or not.(package private) booleanisDocumentFont(PdfIndirectReference indRef) booleanChecks, whetherclose()will flush unused objects, e.g.booleanisTagged()Gets tagged status of the document.Gets static copy of cross reference table.voidmarkStreamAsEmbeddedFile(PdfStream stream) MarksPdfStreamobject as embedded file stream.voidmovePage(int pageNumber, int insertBefore) Moves page to new place in same document with all it tag structurebooleanMoves page to new place in same document with all it tag structureprotected voidopen(PdfVersion newPdfVersion) Initializes document.private static voidoverrideFullCompressionInWriterProperties(WriterProperties properties, boolean readerHasXrefStream) private voidprocessReadingError(String errorMessage) private voidbooleanregisterProduct(ProductData productData) Registers a product for debugging purposes.voidRemoves all event handlers for this document.voidRemoves event handler.voidremovePage(int pageNum) Removes page from the document by page number.booleanremovePage(PdfPage page) Removes the first occurrence of the specified page from this document, if it is present.private voidRemoves all widgets associated with a given page from AcroForm structure.private voidresolveDestinations(PdfDocument toDocument, Map<PdfPage, PdfPage> page2page) voidsetCloseReader(boolean closeReader) Sets, whetherclose()method shall close associated PdfReader.voidsetCloseWriter(boolean closeWriter) Sets, whetherclose()method shall close associated PdfWriter.voidsetDefaultPageSize(PageSize pageSize) Sets default page size.voidSets an encrypted payload, making this document an unencrypted wrapper document.voidsetFlushUnusedObjects(boolean flushUnusedObjects) Sets, whetherclose()shall flush unused objects, e.g.voidsetSerializeOptions(SerializeOptions serializeOptions) Sets a persistent XMP metadata serialization options.Specifies that document shall contain tag structure.voidsetUserProperties(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.protected voidsetXmpMetadata(byte[] xmpMetadata) Sets the XMP Metadata.voidsetXmpMetadata(XMPMeta xmpMeta) Sets the XMP Metadata.voidsetXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) Sets the XMP Metadata.protected voidstoreDestinationToReaddress(PdfDestination destination, Consumer<PdfDestination> onPageAvailable, Consumer<PdfDestination> onPageNotAvailable) Save destinations in a temporary storage for further copying.private voidtryFlushTagStructure(boolean isAppendMode) protected voidInitializes the new instance of document's structure tree rootPdfStructTreeRoot.protected XMPMetaUpdate XMP metadata values fromPdfDocumentInfo.private voidprivate voidupdateValueInMarkInfoDict(PdfName key, PdfObject value) protected voidUpdates XMP metadata.private boolean
-
Field Details
-
PDF_NAMES_TO_REMOVE_FROM_ORIGINAL_TRAILER
-
LOGGER
private static final org.slf4j.Logger LOGGER -
properties
-
xref
List of indirect objects used in the document. -
documentFonts
-
documentHandlers
-
documentId
-
pendingDestinationMutations
To be adjusted destinations. Key - originating page on the source document Value - a hashmap of Parent pdf objects and destinations to be updated -
writer
PdfWriter associated with the document. Not null if document opened either in writing or stamping mode. -
reader
PdfReader associated with the document. Not null if document is opened either in reading or stamping mode. -
catalog
Document catalog. -
trailer
Document trailed. -
pdfVersion
Document version. -
pdfConformance
-
fingerPrint
-
serializeOptions
-
structTreeRoot
-
structParentIndex
protected int structParentIndex -
closeReader
protected boolean closeReader -
closeWriter
protected boolean closeWriter -
isClosing
protected boolean isClosing -
closed
protected boolean closed -
flushUnusedObjects
protected boolean flushUnusedObjectsflag determines whether to write unused objects to result document -
tagStructureContext
-
documentInfoHelper
-
defaultFontStrategy
-
pdfPageFactory
-
serializedObjectsCache
Map<PdfIndirectReference, byte[]> serializedObjectsCacheCache of already serialized objects from this document for smart mode. -
memoryLimitsAwareHandler
MemoryLimitsAwareHandler memoryLimitsAwareHandlerHandler which will be used for decompression of pdf streams. -
defaultPageSize
Default page size. New page by default will be created with this size. -
originalDocumentId
The original (first) id when the document is read initially. -
modifiedDocumentId
The original modified (second) id when the document is read initially. -
encryptedEmbeddedStreamsHandler
-
info
Document info. -
xmpMetadataBytes
private byte[] xmpMetadataBytesXMP Metadata bytes for the document. -
xmpMetadata
XMP Metadata which is used to prevent bytes deserialization for a few times on the same bytes. -
diContainer
-
-
Constructor Details
-
PdfDocument
Open PDF document in reading mode.- Parameters:
reader- PDF reader.
-
PdfDocument
Open PDF document in reading mode.- Parameters:
reader- PDF reader.properties- document properties
-
PdfDocument
Open PDF document in writing mode. Document has no pages when initialized.- Parameters:
writer- PDF writer
-
PdfDocument
Open PDF document in writing mode. Document has no pages when initialized.- Parameters:
writer- PDF writerproperties- document properties
-
PdfDocument
-
PdfDocument
Open PDF document in stamping mode.- Parameters:
reader- PDF reader.writer- PDF writer.properties- properties of the stamping process
-
-
Method Details
-
isClosing
public boolean isClosing()Checks if the document closing has been started or not.- Returns:
trueif closing process has been started, otherwisefalse
-
setXmpMetadata
Sets the XMP Metadata.The XMP Metadata values are synchronized with information dictionary.
- Parameters:
xmpMeta- the xmpMetadata to setserializeOptions- serialization options- Throws:
XMPException- on serialization errors
-
setXmpMetadata
Sets the XMP Metadata.The XMP Metadata values are synchronized with information dictionary.
serializeOptionswill be used for serialization, they can be changed bysetSerializeOptions(SerializeOptions).- Parameters:
xmpMeta- the xmpMetadata to set- Throws:
XMPException- on serialization errors
-
setXmpMetadata
protected void setXmpMetadata(byte[] xmpMetadata) Sets the XMP Metadata.The XMP Metadata values are synchronized with information dictionary.
- Parameters:
xmpMetadata- the xmpMetadata bytes to set
-
getXmpMetadata
Gets XMP Metadata.XMP Metadata is lazy initialized. It will be initialized during the first call of this method.
To update XMP Metadata of the document, use
setXmpMetadata(XMPMeta)method.- Returns:
- existed XMP Metadata
- Throws:
XMPException- on serialization errors
-
getXmpMetadata
Gets XMP Metadata or create a new one.XMP Metadata is lazy initialized. It will be initialized during the first call of this method.
To update XMP Metadata of the document, use
setXmpMetadata(XMPMeta)method.- Parameters:
createNew- if true, create a new empty XMP Metadata if it did not present- Returns:
- existed or newly created XMP Metadata
- Throws:
XMPException- on serialization errors
-
getXmpMetadataBytes
public byte[] getXmpMetadataBytes()Gets XMP Metadata.XMP Metadata is lazy initialized. It will be initialized during the first call of this method.
To update XMP Metadata of the document, use
setXmpMetadata(XMPMeta)method.- Returns:
- existed XMP Metadata bytes
-
getXmpMetadataBytes
public byte[] getXmpMetadataBytes(boolean createNew) Gets XMP Metadata or create a new one.XMP Metadata is lazy initialized. It will be initialized during the first call of this method.
To update XMP Metadata of the document, use
setXmpMetadata(XMPMeta)method.- Parameters:
createNew- if true, create a new empty XMP Metadata if it did not present- Returns:
- existed or newly created XMP Metadata byte array
-
getPdfObject
-
getNumberOfPdfObjects
public int getNumberOfPdfObjects()Get number of indirect objects in the document.- Returns:
- number of indirect objects.
-
getPage
Gets the page by page number.- Parameters:
pageNum- page number.- Returns:
- page by page number.
- Throws:
PdfException- in case the page tree is broken
-
getPage
Gets thePdfPageinstance byPdfDictionary.- Parameters:
pageDictionary-PdfDictionarythat present page.- Returns:
- page by
PdfDictionary.
-
getFirstPage
Get the first page of the document.- Returns:
- first page of the document.
-
getLastPage
-
getMemoryLimitsAwareHandler
Gets current memory limits handler- Returns:
MemoryLimitsAwareHandlerinstance
-
markStreamAsEmbeddedFile
MarksPdfStreamobject as embedded file stream. Note that this method is for internal usage. To add an embedded file to the PDF document please use specialized API for file attachments. (e.g.addFileAttachment(String, PdfFileSpec),PdfPage.addAnnotation(PdfAnnotation))- Parameters:
stream- to be marked as embedded file stream
-
addNewPage
-
addNewPage
-
addNewPage
Creates and inserts new page to the document.- Parameters:
index- position to addPage page to- Returns:
- inserted page
- Throws:
PdfException- in casepageis flushed
-
addNewPage
Creates and inserts new page to the document.- Parameters:
index- position to addPage page topageSize- page size of the new page- Returns:
- inserted page
- Throws:
PdfException- in casepageis flushed
-
addPage
Adds page to the end of document.- Parameters:
page- page to add.- Returns:
- added page.
- Throws:
PdfException- in casepageis flushed
-
addPage
Inserts page to the document.- Parameters:
index- position to addPage page topage- page to addPage- Returns:
- inserted page
- Throws:
PdfException- in casepageis flushed
-
getNumberOfPages
public int getNumberOfPages()Gets number of pages of the document.- Returns:
- number of pages.
-
getPageNumber
Gets page number by page.- Parameters:
page- the page.- Returns:
- page number.
-
getPageNumber
Gets page number byPdfDictionary.- Parameters:
pageDictionary-PdfDictionarythat present page.- Returns:
- page number by
PdfDictionary.
-
movePage
Moves page to new place in same document with all it tag structure- Parameters:
page- page to be moved in document if presentinsertBefore- indicates before which page new one will be inserted to- Returns:
- true if this document contained the specified page
-
movePage
public void movePage(int pageNumber, int insertBefore) Moves page to new place in same document with all it tag structure- Parameters:
pageNumber- number of Page that will be movedinsertBefore- indicates before which page new one will be inserted to
-
removePage
Removes the first occurrence of the specified page from this document, if it is present. Returns true if this document contained the specified element (or equivalently, if this document changed as a result of the call).- Parameters:
page- page to be removed from this document, if present- Returns:
- true if this document contained the specified page
-
removePage
public void removePage(int pageNum) Removes page from the document by page number.- Parameters:
pageNum- the one-based index of the PdfPage to be removed
-
getDiContainer
Gets the container containing all available dependencies.- Returns:
- the container containing all available dependencies.
-
getDocumentInfo
Gets document information dictionary.infois lazy initialized. It will be initialized during the first call of this method.The information dictionary values are synchronized with document XMP Metadata.
- Returns:
- document information dictionary.
-
getOriginalDocumentId
Gets original document idIn order to set originalDocumentId
WriterProperties.setInitialDocumentId(PdfString)should be used- Returns:
- original document id
-
getModifiedDocumentId
Gets modified document idIn order to set modifiedDocumentId
WriterProperties.setModifiedDocumentId(PdfString)should be used- Returns:
- modified document id
-
getDefaultPageSize
Gets default page size. New pages by default are created with this size.- Returns:
- default page size
-
setDefaultPageSize
Sets default page size. New pages by default will be created with this size.- Parameters:
pageSize- page size to be set as default
-
addEventHandler
Adds new event handler.- Parameters:
type- a type of event to be handledhandler- event handler
-
dispatchEvent
Dispatches an event.- Parameters:
event- theAbstractPdfDocumentEventto be dispatched
-
hasEventHandler
Checks if provided event handler assigned for this document.- Parameters:
handler- theAbstractPdfDocumentEventHandlerto check- Returns:
trueif event handler is assigned for this document,falseotherwise
-
removeEventHandler
Removes event handler.- Parameters:
handler-AbstractPdfDocumentEventHandlerevent handler to remove for this document
-
removeAllHandlers
public void removeAllHandlers()Removes all event handlers for this document. -
getWriter
GetsPdfWriterassociated with the document.- Returns:
- PdfWriter associated with the document.
-
getReader
GetsPdfReaderassociated with the document.- Returns:
- PdfReader associated with the document.
-
isAppendMode
public boolean isAppendMode()Returnstrueif the document is opened in append mode, andfalseotherwise.- Returns:
trueif the document is opened in append mode, andfalseotherwise.
-
createNextIndirectReference
Creates next available indirect reference.- Returns:
- created indirect reference.
-
getPdfVersion
-
getCatalog
-
close
public void close()Close PDF document.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()Gets close status of the document.- Returns:
- true, if the document has already been closed, otherwise false.
-
isTagged
public boolean isTagged()Gets tagged status of the document.- Returns:
- true, if the document has tag structure, otherwise false.
-
setTagged
Specifies that document shall contain tag structure. See ISO 32000-1, section 14.8 "Tagged PDF"- Returns:
- this
PdfDocumentinstance
-
getStructTreeRoot
GetsPdfStructTreeRootof tagged document.- Returns:
PdfStructTreeRootin case document is tagged, otherwise it returns null.- See Also:
-
getNextStructParentIndex
public int getNextStructParentIndex()Gets next parent index of tagged document.- Returns:
- -1 if document is not tagged, or >= 0 if tagged.
- See Also:
-
getTagStructureContext
Gets documentTagStructureContext. The document must be tagged, otherwise an exception will be thrown.- Returns:
- document
TagStructureContext.
-
copyPagesTo
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage) Copies a range of pages from current document totoDocument. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pageFrom- start of the range of pages to be copied.pageTo- end of the range of pages to be copied.toDocument- a document to copy pages to.insertBeforePage- a position where to insert copied pages.- Returns:
- list of copied pages
-
getConformance
-
copyPagesTo
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocument. This range is inclusive, bothpageandpageToare included in list of copied pages. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pageFrom- 1-based start of the range of pages to be copied.pageTo- 1-based end (inclusive) of the range of pages to be copied. This page is included in list of copied pages.toDocument- a document to copy pages to.insertBeforePage- a position where to insert copied pages.copier- a copier which bears a special copy logic. May be null. It is recommended to use the same instance ofIPdfPageExtraCopierfor the same output document.- Returns:
- list of new copied pages
-
copyPagesTo
Copies a range of pages from current document totoDocumentappending copied pages to the end. This range is inclusive, bothpageandpageToare included in list of copied pages. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pageFrom- 1-based start of the range of pages to be copied.pageTo- 1-based end (inclusive) of the range of pages to be copied. This page is included in list of copied pages.toDocument- a document to copy pages to.- Returns:
- list of new copied pages
-
copyPagesTo
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocumentappending copied pages to the end. This range is inclusive, bothpageandpageToare included in list of copied pages. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pageFrom- 1-based start of the range of pages to be copied.pageTo- 1-based end (inclusive) of the range of pages to be copied. This page is included in list of copied pages.toDocument- a document to copy pages to.copier- a copier which bears a special copy logic. May be null. It is recommended to use the same instance ofIPdfPageExtraCopierfor the same output document.- Returns:
- list of new copied pages.
-
copyPagesTo
public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage) Copies a range of pages from current document totoDocument. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pagesToCopy- list of pages to be copied.toDocument- a document to copy pages to.insertBeforePage- a position where to insert copied pages.- Returns:
- list of new copied pages
-
copyPagesTo
public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocument. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pagesToCopy- list of pages to be copied.toDocument- a document to copy pages to.insertBeforePage- a position where to insert copied pages.copier- a copier which bears a special copy logic. May be null. It is recommended to use the same instance ofIPdfPageExtraCopierfor the same output document.- Returns:
- list of new copied pages
-
copyPagesTo
Copies a range of pages from current document totoDocumentappending copied pages to the end. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pagesToCopy- list of pages to be copied.toDocument- a document to copy pages to.- Returns:
- list of copied pages
-
copyPagesTo
public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, IPdfPageExtraCopier copier) Copies a range of pages from current document totoDocumentappending copied pages to the end. Use this method if you want to copy pages across tagged documents. This will keep resultant PDF structure consistent.If outlines destination names are the same in different documents, all such outlines will lead to a single location in the resultant document. In this case iText will log a warning. This can be avoided by renaming destinations names in the source document.
- Parameters:
pagesToCopy- list of pages to be copied.toDocument- a document to copy pages to.copier- a copier which bears a special copy logic. May be null. It is recommended to use the same instance ofIPdfPageExtraCopierfor the same output document.- Returns:
- list of copied pages
-
flushCopiedObjects
Flush all copied objects and remove them from copied cache.Note, if you will copy objects from the same document, duplicated objects will be created. That's why usually this method is meant to be used when all copying from source document is finished. For other cases one can also consider other flushing mechanisms, e.g. pages-based flushing.
- Parameters:
sourceDoc- source document
-
isCloseReader
-
setCloseReader
-
isCloseWriter
-
setCloseWriter
-
isFlushUnusedObjects
-
setFlushUnusedObjects
-
getOutlines
This method returns a complete outline tree of the whole document.- Parameters:
updateOutlines- if the flag istrue, the method reads the whole document and creates outline tree. If the flag isfalse, the method gets cached outline tree (if it was cached via calling getOutlines method before).- Returns:
- fully initialize
PdfOutlineobject.
-
initializeOutlines
public void initializeOutlines()This method initializes an outline tree of the document and sets outline mode to true. -
addNamedDestination
This methods adds new name in the Dests NameTree. It throws an exception, if the name already exists.- Parameters:
key- Name of the destination.value- An object destination refers to. Must be an array or a dictionary with key /D and array. See ISO 32000-1 12.3.2.3 for more info.
-
addNamedDestination
This methods adds new name in the Dests NameTree. It throws an exception, if the name already exists.- Parameters:
key- Name of the destination.value- An object destination refers to. Must be an array or a dictionary with key /D and array. See ISO 32000-1 12.3.2.3 for more info.
-
listIndirectReferences
Gets static copy of cross reference table.- Returns:
- a static copy of cross reference table
-
getTrailer
-
addOutputIntent
AddsPdfOutputIntentthat shall specify the colour characteristics of output devices on which the document might be rendered.- Parameters:
outputIntent-PdfOutputIntentto add.- See Also:
-
checkIsoConformance
-
addFileAttachment
Adds file attachment at document level.- Parameters:
key- name of the destination.fs-PdfFileSpecobject.
-
addAssociatedFile
Adds file associated with PDF document as a whole and identifies the relationship between them.Associated files may be used in Pdf/A-3 and Pdf 2.0 documents. The method is very similar to
addFileAttachment(String, PdfFileSpec). However, besides adding file description to Names tree, it adds file to array value of the AF key in the document catalog.For associated files their associated file specification dictionaries shall include the AFRelationship key
- Parameters:
description- the file descriptionfs- file specification dictionary of associated file- See Also:
-
getAssociatedFiles
Returns files associated with PDF document.- Returns:
- associated files array.
-
getEncryptedPayloadDocument
Gets the encrypted payload of this document, or returnsnullif this document isn't an unencrypted wrapper document.- Returns:
- encrypted payload of this document.
-
setEncryptedPayload
Sets an encrypted payload, making this document an unencrypted wrapper document. The file spec shall include the AFRelationship key with a value of EncryptedPayload, and shall include an encrypted payload dictionary.- Parameters:
fs- encrypted payload file spec.PdfEncryptedPayloadFileSpecFactorycan produce one.
-
getPageLabels
-
hasOutlines
public boolean hasOutlines()Indicates if the document has any outlines- Returns:
true, if there are outlines andfalseotherwise.
-
setUserProperties
public void setUserProperties(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.- Parameters:
userProperties- the user properties flag
-
getFont
Create a new instance ofPdfFontor load already created one.- Parameters:
dictionary-PdfDictionarythat presentsPdfFont.- Returns:
- instance of
PdfFontNote, PdfFont which created with
PdfFontFactory.createFont(PdfDictionary)won't be cached until it will be added toPdfCanvasorPdfResources.
-
getDefaultFont
-
addFont
-
registerProduct
Registers a product for debugging purposes.- Parameters:
productData- product to be registered.- Returns:
- true if the product hadn't been registered before.
-
getFingerPrint
Returns the object containing the registered products.- Returns:
- fingerprint object
-
findFont
-
getDocumentId
public long getDocumentId()Obtains numeric document id.- Returns:
- document id
-
getDocumentIdWrapper
-
getSerializeOptions
Gets a persistent XMP metadata serialization options.- Returns:
- serialize options
-
setSerializeOptions
Sets a persistent XMP metadata serialization options.- Parameters:
serializeOptions- serialize options
-
initTagStructureContext
protected void initTagStructureContext()InitializeTagStructureContext. -
flushObject
Flush an object.- Parameters:
pdfObject- object to flush.canBeInObjStm- indicates whether object can be placed into object stream.- Throws:
IOException- on error.
-
open
Initializes document.- Parameters:
newPdfVersion- new pdf version of the resultant file if stamper is used and the version needs to be changed, ornullotherwise
-
updateXmpMetadata
protected void updateXmpMetadata()Updates XMP metadata. Shall be overridden. -
updateDefaultXmpMetadata
Update XMP metadata values fromPdfDocumentInfo.- Returns:
- the XMPMetadata
- Throws:
XMPException- if the file is not well-formed XML or if parsing fails.
-
getDocumentFonts
List all newly added or loaded fonts- Returns:
- List of
PdfFont.
-
flushFonts
protected void flushFonts()Flushes all newly added or loaded fonts. -
checkAndAddPage
-
checkAndAddPage
-
checkClosingStatus
protected void checkClosingStatus()checks whether a method is invoked at the closed document -
getPageFactory
Returns the factory for creating page instances.- Returns:
- implementation of
IPdfPageFactoryfor current document
-
tryInitTagStructure
Initializes the new instance of document's structure tree rootPdfStructTreeRoot. See ISO 32000-1, section 14.7.2 Structure Hierarchy.- Parameters:
str- dictionary to create structure tree root
-
getXref
-
isDocumentFont
-
doesStreamBelongToEmbeddedFile
-
hasAcroForm
boolean hasAcroForm() -
enableByteArrayWritingMode
private void enableByteArrayWritingMode() -
tryFlushTagStructure
private void tryFlushTagStructure(boolean isAppendMode) -
updateValueInMarkInfoDict
-
removeUnusedWidgetsFromFields
Removes all widgets associated with a given page from AcroForm structure. Widgets can be either pure or merged.- Parameters:
page- to remove from.
-
resolveDestinations
-
copyOutlines
private void copyOutlines(Set<PdfOutline> outlines, PdfDocument toDocument, Map<PdfPage, PdfPage> page2page) This method copies all given outlines- Parameters:
outlines- outlines to be copiedtoDocument- document where outlines should be copied
-
getAllOutlinesToCopy
This method gets all outlines to be copied including parent outlines- Parameters:
outline- current outlineoutlinesToCopy- a Set of outlines to be copied
-
cloneOutlines
private void cloneOutlines(Set<PdfOutline> outlinesToCopy, PdfOutline newParent, PdfOutline oldParent, Map<PdfPage, PdfPage> page2page, PdfDocument toDocument) This method copies create new outlines in the Document to copy.- Parameters:
outlinesToCopy- - Set of outlines to be copiednewParent- - new parent outlineoldParent- - old parent outline
-
ensureTreeRootAddedToNames
-
writerHasEncryption
private boolean writerHasEncryption() -
updatePdfVersionFromCatalog
private void updatePdfVersionFromCatalog() -
readDocumentIds
private void readDocumentIds() -
processReadingError
-
overrideFullCompressionInWriterProperties
private static void overrideFullCompressionInWriterProperties(WriterProperties properties, boolean readerHasXrefStream)
-