Class PdfDocument
- All Implemented Interfaces:
-
IEventDispatcher
,Closeable
,AutoCloseable
- Direct Known Subclasses:
-
PdfADocument
-
Field Summary
Modifier and TypeFieldDescriptionprotected PdfCatalog
Document catalog.protected boolean
protected boolean
protected boolean
protected EventDispatcher
protected FingerPrint
protected boolean
flag determines whether to write unused objects to result documentprotected PdfDocumentInfo
Document info.protected boolean
protected PdfVersion
Document version.protected final StampingProperties
protected PdfReader
PdfReader associated with the document.protected SerializeOptions
protected int
protected PdfStructTreeRoot
protected TagStructureContext
protected PdfDictionary
Document trailed.protected PdfWriter
PdfWriter associated with the document.protected byte[]
XMP Metadata for the document. -
Constructor Summary
ConstructorDescriptionPdfDocument
(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 TypeMethodDescriptionvoid
addAssociatedFile
(String description, PdfFileSpec fs) Adds file associated with PDF document as a whole and identifies the relationship between them.protected void
addCustomMetadataExtensions
(XMPMeta xmpMeta) Adds custom XMP metadata extension.void
addEventHandler
(String type, IEventHandler handler) Adds new event handler.void
addFileAttachment
(String key, PdfFileSpec fs) Adds file attachment at document level.Adds aPdfFont
instance to this document so that this font is flushed automatically on document close.void
addNamedDestination
(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.void
addOutputIntent
(PdfOutputIntent outputIntent) AddsPdfOutputIntent
that 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 void
checkAndAddPage
(int index, PdfPage page) Checks page before adding and add.protected void
checkAndAddPage
(PdfPage page) Checks page before adding.protected void
checks whether a method is invoked at the closed documentprotected void
Checks whether PDF document conforms a specific standard.void
checkIsoConformance
(Object obj, IsoKey key) Checks whether PDF document conforms a specific standard.void
checkIsoConformance
(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream) Checks whether PDF document conforms a specific standard.void
checkShowTextIsoConformance
(CanvasGraphicsState gState, PdfResources resources) Checks whether PDF document conforms a specific standard.void
close()
Close PDF document.copyPagesTo
(int pageFrom, int pageTo, PdfDocument toDocument) Copies a range of pages from current document totoDocument
appending 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 totoDocument
appending copied pages to the end.copyPagesTo
(List<Integer> pagesToCopy, PdfDocument toDocument) Copies a range of pages from current document totoDocument
appending 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 totoDocument
appending copied pages to the end.Creates next available indirect reference.void
dispatchEvent
(Event event) Dispatches an event.void
dispatchEvent
(Event event, boolean delayed) Dispatches a delayed event.FindPdfFont
from loaded fonts with corresponding fontProgram and encoding or CMAP.void
flushCopiedObjects
(PdfDocument sourceDoc) Flush all copied objects and remove them from copied cache.protected void
Flushes all newly added or loaded fonts.protected void
flushObject
(PdfObject pdfObject, boolean canBeInObjStm) Flush an object.Returns files associated with PDF document.Gets PDF catalog.Gets default font for the document: Helvetica, WinAnsi.Gets default page size.protected Collection<PdfFont>
List all newly added or loaded fontslong
Obtains numeric document id.Obtains document id as aSequenceId
.Gets document information dictionary.Gets the encrypted payload of this document, or returnsnull
if 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 ofPdfFont
or load already created one.Gets the last page of the document.Gets modified document idint
Gets next parent index of tagged document.int
Gets number of pages of the document.int
Get 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 thePdfPage
instance byPdfDictionary
.protected IPdfPageFactory
Returns the factory for creating page instances.String[]
This method retrieves the page labels from a document as an array of String objects.int
getPageNumber
(PdfDictionary pageDictionary) Gets page number byPdfDictionary
.int
getPageNumber
(PdfPage page) Gets page number by page.getPdfObject
(int objNum) Gets PdfObject by object number.Gets PDF version.GetsPdfReader
associated with the document.Gets a persistent XMP metadata serialization options.GetsPdfStructTreeRoot
of tagged document.Gets documentTagStructureContext
.Gets document trailer.GetsPdfWriter
associated with the document.byte[]
Gets XMPMetadata.byte[]
getXmpMetadata
(boolean createNew) Gets XMPMetadata or create a new one.boolean
hasEventHandler
(String type) Checks if event dispatcher as an event handler assigned for a certain event type.boolean
Indicates if the document has any outlinesvoid
This method initializes an outline tree of the document and sets outline mode to true.protected void
InitializeTagStructureContext
.boolean
Returnstrue
if the document is opened in append mode, andfalse
otherwise.boolean
isClosed()
Gets close status of the document.boolean
Checks, whetherclose()
method will close associated PdfReader.boolean
Checks, whetherclose()
method will close associated PdfWriter.boolean
Checks, whetherclose()
will flush unused objects, e.g.boolean
isTagged()
Gets tagged status of the document.Gets static copy of cross reference table.protected void
markObjectAsMustBeFlushed
(PdfObject pdfObject) Mark an object withPdfObject.MUST_BE_FLUSHED
.void
markStreamAsEmbeddedFile
(PdfStream stream) MarksPdfStream
object as embedded file stream.void
movePage
(int pageNumber, int insertBefore) Moves page to new place in same document with all it tag structureboolean
Moves page to new place in same document with all it tag structureprotected void
open
(PdfVersion newPdfVersion) Initializes document.boolean
registerProduct
(ProductData productData) Registers a product for debugging purposes.void
Remove all event handlers.void
removeEventHandler
(String type, IEventHandler handler) Removes event handler.void
removePage
(int pageNum) Removes page from the document by page number.boolean
removePage
(PdfPage page) Removes the first occurrence of the specified page from this document, if it is present.void
setCloseReader
(boolean closeReader) Sets, whetherclose()
method shall close associated PdfReader.void
setCloseWriter
(boolean closeWriter) Sets, whetherclose()
method shall close associated PdfWriter.void
setDefaultPageSize
(PageSize pageSize) Sets default page size.void
Sets an encrypted payload, making this document an unencrypted wrapper document.void
setFlushUnusedObjects
(boolean flushUnusedObjects) Sets, whetherclose()
shall flush unused objects, e.g.void
setSerializeOptions
(SerializeOptions serializeOptions) Sets a persistent XMP metadata serialization options.Specifies that document shall contain tag structure.void
setUserProperties
(boolean userProperties) Sets the flag indicating the presence of structure elements that contain user properties attributes.protected void
setXmpMetadata
(byte[] xmpMetadata) Use this method to set the XMP Metadata.void
setXmpMetadata
(XMPMeta xmpMeta) Sets the XMP Metadata.void
setXmpMetadata
(XMPMeta xmpMeta, SerializeOptions serializeOptions) Sets the XMP Metadata.protected void
storeDestinationToReaddress
(PdfDestination destination, Consumer<PdfDestination> onPageAvailable, Consumer<PdfDestination> onPageNotAvailable) Save destinations in a temporary storage for further copying.protected void
storeLinkAnnotation
(PdfPage page, PdfLinkAnnotation annotation) Deprecated.will be removed in next major version, it is being replaced with storeDestinationToReaddressprotected void
Initializes the new instance of document's structure tree rootPdfStructTreeRoot
.protected XMPMeta
Update XMP metadata values fromPdfDocumentInfo
.protected void
Updates XMP metadata.
-
Field Details
-
properties
-
eventDispatcher
-
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. -
xmpMetadata
protected byte[] xmpMetadataXMP Metadata for the document. -
catalog
Document catalog. -
trailer
Document trailed. -
info
Document info. -
pdfVersion
Document version. -
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
-
-
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 writer -
properties
- document properties
-
PdfDocument
Opens PDF document in the stamping mode.
- Parameters:
-
reader
- PDF reader. -
writer
- PDF writer.
-
PdfDocument
Open PDF document in stamping mode.- Parameters:
-
reader
- PDF reader. -
writer
- PDF writer. -
properties
- properties of the stamping process
-
-
Method Details
-
setXmpMetadata
Sets the XMP Metadata.- Parameters:
-
xmpMeta
- the xmpMetadata to set -
serializeOptions
- serialization options - Throws:
-
XMPException
- on serialization errors
-
setXmpMetadata
protected void setXmpMetadata(byte[] xmpMetadata) Use this method to set the XMP Metadata.- Parameters:
-
xmpMetadata
- The xmpMetadata to set.
-
setXmpMetadata
Sets the XMP Metadata.- Parameters:
-
xmpMeta
- the xmpMetadata to set - Throws:
-
XMPException
- on serialization errors
-
getXmpMetadata
public byte[] getXmpMetadata()Gets XMPMetadata.- Returns:
- the XMPMetadata
-
getXmpMetadata
public byte[] getXmpMetadata(boolean createNew) Gets XMPMetadata or create a new one.- Parameters:
-
createNew
- if true, create a new empty XMPMetadata if it did not present. - Returns:
- existed or newly created XMPMetadata byte array.
-
getPdfObject
Gets PdfObject by object number.- Parameters:
-
objNum
- object number. - Returns:
-
PdfObject
ornull
, if object not found.
-
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 thePdfPage
instance byPdfDictionary
.- Parameters:
-
pageDictionary
-PdfDictionary
that present page. - Returns:
-
page by
PdfDictionary
.
-
getFirstPage
Get the first page of the document.- Returns:
- first page of the document.
-
getLastPage
Gets the last page of the document.- Returns:
- last page.
-
markStreamAsEmbeddedFile
MarksPdfStream
object 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
Creates and adds new page to the end of document.- Returns:
- added page
-
addNewPage
Creates and adds new page with the specified page size.- Parameters:
-
pageSize
- page size of the new page - Returns:
- added page
-
addNewPage
Creates and inserts new page to the document.- Parameters:
-
index
- position to addPage page to - Returns:
- inserted page
- Throws:
-
PdfException
- in casepage
is flushed
-
addNewPage
Creates and inserts new page to the document.- Parameters:
-
index
- position to addPage page to -
pageSize
- page size of the new page - Returns:
- inserted page
- Throws:
-
PdfException
- in casepage
is flushed
-
addPage
Adds page to the end of document.- Parameters:
-
page
- page to add. - Returns:
- added page.
- Throws:
-
PdfException
- in casepage
is flushed
-
addPage
Inserts page to the document.- Parameters:
-
index
- position to addPage page to -
page
- page to addPage - Returns:
- inserted page
- Throws:
-
PdfException
- in casepage
is 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
-PdfDictionary
that 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 present -
insertBefore
- 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 moved -
insertBefore
- 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
-
getDocumentInfo
Gets document information dictionary.info
is lazy initialized. It will be initialized during the first call of this method.- Returns:
- document information dictionary.
-
getOriginalDocumentId
Gets original document idIn order to set originalDocumentId
WriterProperties.setInitialDocumentId(com.itextpdf.kernel.pdf.PdfString)
should be used- Returns:
- original dccument id
-
getModifiedDocumentId
Gets modified document idIn order to set modifiedDocumentId
WriterProperties.setModifiedDocumentId(com.itextpdf.kernel.pdf.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.- Specified by:
-
addEventHandler
in interfaceIEventDispatcher
- Parameters:
-
type
- a type of event to be handled -
handler
- event handler
-
dispatchEvent
Dispatches an event.- Specified by:
-
dispatchEvent
in interfaceIEventDispatcher
- Parameters:
-
event
- theEvent
to be dispatched
-
dispatchEvent
Dispatches a delayed event. Sometimes event cannot be handled immediately because event handler has not been set yet. In this case event is placed into event ques of dispatcher and is waiting until handler is assigned.- Specified by:
-
dispatchEvent
in interfaceIEventDispatcher
- Parameters:
-
event
- theEvent
to be dispatched -
delayed
- flag whetherEvent
delayed or not
-
hasEventHandler
Checks if event dispatcher as an event handler assigned for a certain event type.- Specified by:
-
hasEventHandler
in interfaceIEventDispatcher
- Parameters:
-
type
- a type of theEvent
- Returns:
- true if event dispatcher as an event handler assigned for a certain event type
-
removeEventHandler
Removes event handler.- Specified by:
-
removeEventHandler
in interfaceIEventDispatcher
- Parameters:
-
type
- a type of theEvent
-
handler
- event handlerIEventHandler
-
removeAllHandlers
public void removeAllHandlers()Remove all event handlers.- Specified by:
-
removeAllHandlers
in interfaceIEventDispatcher
-
getWriter
GetsPdfWriter
associated with the document.- Returns:
- PdfWriter associated with the document.
-
getReader
GetsPdfReader
associated with the document.- Returns:
- PdfReader associated with the document.
-
isAppendMode
public boolean isAppendMode()Returnstrue
if the document is opened in append mode, andfalse
otherwise.- Returns:
-
true
if the document is opened in append mode, andfalse
otherwise.
-
createNextIndirectReference
Creates next available indirect reference.- Returns:
- created indirect reference.
-
getPdfVersion
Gets PDF version.- Returns:
- PDF version.
-
getCatalog
Gets PDF catalog.- Returns:
- PDF catalog.
-
close
public void close()Close PDF document.- Specified by:
-
close
in interfaceAutoCloseable
- Specified by:
-
close
in 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
PdfDocument
instance
-
getStructTreeRoot
GetsPdfStructTreeRoot
of tagged document.- Returns:
-
PdfStructTreeRoot
in 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
-
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, bothpage
andpageTo
are 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 ofIPdfPageExtraCopier
for the same output document. - Returns:
- list of new copied pages
-
copyPagesTo
Copies a range of pages from current document totoDocument
appending copied pages to the end. This range is inclusive, bothpage
andpageTo
are 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 totoDocument
appending copied pages to the end. This range is inclusive, bothpage
andpageTo
are 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 ofIPdfPageExtraCopier
for 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 ofIPdfPageExtraCopier
for the same output document. - Returns:
- list of new copied pages
-
copyPagesTo
Copies a range of pages from current document totoDocument
appending 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 totoDocument
appending 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 ofIPdfPageExtraCopier
for 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
public boolean isCloseReader()Checks, whetherclose()
method will close associated PdfReader.- Returns:
-
true,
close()
method is going to close associated PdfReader, otherwise false.
-
setCloseReader
public void setCloseReader(boolean closeReader) Sets, whetherclose()
method shall close associated PdfReader.- Parameters:
-
closeReader
- true,close()
method shall close associated PdfReader, otherwise false.
-
isCloseWriter
public boolean isCloseWriter()Checks, whetherclose()
method will close associated PdfWriter.- Returns:
-
true,
close()
method is going to close associated PdfWriter, otherwise false.
-
setCloseWriter
public void setCloseWriter(boolean closeWriter) Sets, whetherclose()
method shall close associated PdfWriter.- Parameters:
-
closeWriter
- true,close()
method shall close associated PdfWriter, otherwise false.
-
isFlushUnusedObjects
public boolean isFlushUnusedObjects()Checks, whetherclose()
will flush unused objects, e.g. unreachable from PDF Catalog. By default - false.- Returns:
-
false, if
close()
shall not flush unused objects, otherwise true.
-
setFlushUnusedObjects
public void setFlushUnusedObjects(boolean flushUnusedObjects) Sets, whetherclose()
shall flush unused objects, e.g. unreachable from PDF Catalog.- Parameters:
-
flushUnusedObjects
- false, ifclose()
shall not flush unused objects, otherwise true.
-
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
PdfOutline
object.
-
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.
-
listIndirectReferences
Gets static copy of cross reference table.- Returns:
- a static copy of cross reference table
-
getTrailer
Gets document trailer.- Returns:
- document trailer.
-
addOutputIntent
AddsPdfOutputIntent
that shall specify the colour characteristics of output devices on which the document might be rendered.- Parameters:
-
outputIntent
-PdfOutputIntent
to add. - See Also:
-
checkIsoConformance
Checks whether PDF document conforms a specific standard. Shall be override.- Parameters:
-
obj
- An object to conform. -
key
- type of object to conform.
-
checkIsoConformance
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream) Checks whether PDF document conforms a specific standard. Shall be override.- Parameters:
-
obj
- an object to conform. -
key
- type of object to conform. -
resources
-PdfResources
associated with an object to check. -
contentStream
- current content stream
-
checkShowTextIsoConformance
Checks whether PDF document conforms a specific standard. Shall be override.- Parameters:
-
gState
- aCanvasGraphicsState
object to conform. -
resources
-PdfResources
associated with an object to check.
-
addFileAttachment
Adds file attachment at document level.- Parameters:
-
key
- name of the destination. -
fs
-PdfFileSpec
object.
-
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 description -
fs
- 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 returnsnull
if 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.PdfEncryptedPayloadFileSpecFactory
can produce one.
-
getPageLabels
This method retrieves the page labels from a document as an array of String objects.- Returns:
-
String
list of page labels if they were found, ornull
otherwise
-
hasOutlines
public boolean hasOutlines()Indicates if the document has any outlines- Returns:
-
true
, if there are outlines andfalse
otherwise.
-
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 ofPdfFont
or load already created one.- Parameters:
-
dictionary
-PdfDictionary
that presentsPdfFont
. - Returns:
-
instance of
PdfFont
Note, PdfFont which created with
PdfFontFactory.createFont(PdfDictionary)
won't be cached until it will be added toPdfCanvas
orPdfResources
.
-
getDefaultFont
Gets default font for the document: Helvetica, WinAnsi. One instance per document.- Returns:
-
instance of
PdfFont
ornull
on error.
-
addFont
Adds aPdfFont
instance to this document so that this font is flushed automatically on document close. As a side effect, the underlying font dictionary is made indirect if it wasn't the case yet- Parameters:
-
font
- aPdfFont
instance to add - Returns:
- the same PdfFont instance.
-
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
FindPdfFont
from loaded fonts with corresponding fontProgram and encoding or CMAP.- Parameters:
-
fontProgram
- a font name or path to a font program -
encoding
- an encoding or CMAP - Returns:
- the font instance, or null if font wasn't found
-
getDocumentId
public long getDocumentId()Obtains numeric document id.- Returns:
- document id
-
getDocumentIdWrapper
Obtains document id as aSequenceId
.- Returns:
- document id
-
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
. -
storeLinkAnnotation
Deprecated.will be removed in next major version, it is being replaced with storeDestinationToReaddressSave the link annotation in a temporary storage for further copying. Save destinations in a temporary storage for further copying.- Parameters:
-
page
- just copiedPdfPage
link annotation belongs to. -
annotation
-PdfLinkAnnotation
itself.
-
checkIsoConformance
protected void checkIsoConformance()Checks whether PDF document conforms a specific standard. Shall be override. -
markObjectAsMustBeFlushed
Mark an object withPdfObject.MUST_BE_FLUSHED
.- Parameters:
-
pdfObject
- an object to mark.
-
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, ornull
otherwise
-
addCustomMetadataExtensions
Adds custom XMP metadata extension. Useful for PDF/UA, ZUGFeRD, etc.- Parameters:
-
xmpMeta
-XMPMeta
to add custom metadata to.
-
updateXmpMetadata
protected void updateXmpMetadata()Updates XMP metadata. Shall be override. -
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
Checks page before adding and add.- Parameters:
-
index
- one-base index of the page. -
page
-PdfPage
to add.
-
checkAndAddPage
Checks page before adding.- Parameters:
-
page
-PdfPage
to add.
-
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
IPdfPageFactory
for 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
-