public class PdfDocument extends Object implements Closeable
| Modifier and Type | Field and Description |
|---|---|
protected PdfCatalog |
catalog
Document catalog.
|
protected boolean |
closed |
protected boolean |
closeReader |
protected boolean |
closeWriter |
protected DefaultFontStrategy |
defaultFontStrategy |
protected DocumentInfoHelper |
documentInfoHelper |
protected FingerPrint |
fingerPrint |
protected boolean |
flushUnusedObjects
flag determines whether to write unused objects to result document
|
protected boolean |
isClosing |
protected PdfConformance |
pdfConformance |
protected IPdfPageFactory |
pdfPageFactory |
protected PdfVersion |
pdfVersion
Document version.
|
protected StampingProperties |
properties |
protected PdfReader |
reader
PdfReader associated with the document.
|
protected SerializeOptions |
serializeOptions |
protected int |
structParentIndex |
protected PdfStructTreeRoot |
structTreeRoot |
protected TagStructureContext |
tagStructureContext |
protected PdfDictionary |
trailer
Document trailed.
|
protected PdfWriter |
writer
PdfWriter associated with the document.
|
| Constructor and Description |
|---|
PdfDocument(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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAssociatedFile(String description,
PdfFileSpec fs)
Adds file associated with PDF document as a whole and identifies the relationship between them.
|
void |
addEventHandler(String type,
AbstractPdfDocumentEventHandler handler)
Adds new event handler.
|
void |
addFileAttachment(String key,
PdfFileSpec fs)
Adds file attachment at document level.
|
PdfFont |
addFont(PdfFont font)
Adds a
PdfFont instance to this document so that this font is flushed automatically
on document close. |
void |
addNamedDestination(PdfString key,
PdfObject value)
This methods adds new name in the Dests NameTree.
|
void |
addNamedDestination(String key,
PdfObject value)
This methods adds new name in the Dests NameTree.
|
PdfPage |
addNewPage()
Creates and adds new page to the end of document.
|
PdfPage |
addNewPage(int index)
Creates and inserts new page to the document.
|
PdfPage |
addNewPage(int index,
PageSize pageSize)
Creates and inserts new page to the document.
|
PdfPage |
addNewPage(PageSize pageSize)
Creates and adds new page with the specified page size.
|
void |
addOutputIntent(PdfOutputIntent outputIntent)
Adds
PdfOutputIntent that shall specify the colour characteristics of output devices
on which the document might be rendered. |
PdfPage |
addPage(int index,
PdfPage page)
Inserts page to the document.
|
PdfPage |
addPage(PdfPage page)
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 |
checkClosingStatus()
checks whether a method is invoked at the closed document
|
void |
checkIsoConformance(IValidationContext validationContext) |
void |
close()
Close PDF document.
|
List<PdfPage> |
copyPagesTo(int pageFrom,
int pageTo,
PdfDocument toDocument)
Copies a range of pages from current document to
toDocument appending copied pages to the end. |
List<PdfPage> |
copyPagesTo(int pageFrom,
int pageTo,
PdfDocument toDocument,
int insertBeforePage)
Copies a range of pages from current document to
toDocument. |
List<PdfPage> |
copyPagesTo(int pageFrom,
int pageTo,
PdfDocument toDocument,
int insertBeforePage,
IPdfPageExtraCopier copier)
Copies a range of pages from current document to
toDocument. |
List<PdfPage> |
copyPagesTo(int pageFrom,
int pageTo,
PdfDocument toDocument,
IPdfPageExtraCopier copier)
Copies a range of pages from current document to
toDocument appending copied pages to the end. |
List<PdfPage> |
copyPagesTo(List<Integer> pagesToCopy,
PdfDocument toDocument)
Copies a range of pages from current document to
toDocument appending copied pages to the end. |
List<PdfPage> |
copyPagesTo(List<Integer> pagesToCopy,
PdfDocument toDocument,
int insertBeforePage)
Copies a range of pages from current document to
toDocument. |
List<PdfPage> |
copyPagesTo(List<Integer> pagesToCopy,
PdfDocument toDocument,
int insertBeforePage,
IPdfPageExtraCopier copier)
Copies a range of pages from current document to
toDocument. |
List<PdfPage> |
copyPagesTo(List<Integer> pagesToCopy,
PdfDocument toDocument,
IPdfPageExtraCopier copier)
Copies a range of pages from current document to
toDocument appending copied pages to the end. |
PdfIndirectReference |
createNextIndirectReference()
Creates next available indirect reference.
|
void |
dispatchEvent(AbstractPdfDocumentEvent event)
Dispatches an event.
|
PdfFont |
findFont(String fontProgram,
String encoding)
Find
PdfFont 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 |
flushFonts()
Flushes all newly added or loaded fonts.
|
protected void |
flushObject(PdfObject pdfObject,
boolean canBeInObjStm)
Flush an object.
|
PdfArray |
getAssociatedFiles()
Returns files associated with PDF document.
|
PdfCatalog |
getCatalog()
Gets PDF catalog.
|
PdfConformance |
getConformance()
Get the
PdfConformance |
PdfFont |
getDefaultFont()
Gets default font for the document: Helvetica, WinAnsi.
|
PageSize |
getDefaultPageSize()
Gets default page size.
|
com.itextpdf.commons.utils.DIContainer |
getDiContainer()
Gets the container containing all available dependencies.
|
protected Collection<PdfFont> |
getDocumentFonts()
List all newly added or loaded fonts
|
long |
getDocumentId()
Obtains numeric document id.
|
com.itextpdf.commons.actions.sequence.SequenceId |
getDocumentIdWrapper()
Obtains document id as a
SequenceId. |
PdfDocumentInfo |
getDocumentInfo()
Gets document information dictionary.
|
PdfEncryptedPayloadDocument |
getEncryptedPayloadDocument()
Gets the encrypted payload of this document,
or returns
null if this document isn't an unencrypted wrapper document. |
FingerPrint |
getFingerPrint()
Returns the object containing the registered products.
|
PdfPage |
getFirstPage()
Get the first page of the document.
|
PdfFont |
getFont(PdfDictionary dictionary)
Create a new instance of
PdfFont or load already created one. |
PdfPage |
getLastPage()
Gets the last page of the document.
|
MemoryLimitsAwareHandler |
getMemoryLimitsAwareHandler()
Gets current memory limits handler
|
PdfString |
getModifiedDocumentId()
Gets modified document id
|
int |
getNextStructParentIndex()
Gets next parent index of tagged document.
|
int |
getNumberOfPages()
Gets number of pages of the document.
|
int |
getNumberOfPdfObjects()
Get number of indirect objects in the document.
|
PdfString |
getOriginalDocumentId()
Gets original document id
|
PdfOutline |
getOutlines(boolean updateOutlines)
This method returns a complete outline tree of the whole document.
|
PdfPage |
getPage(int pageNum)
Gets the page by page number.
|
PdfPage |
getPage(PdfDictionary pageDictionary)
Gets the
PdfPage instance by PdfDictionary. |
protected IPdfPageFactory |
getPageFactory()
Returns the factory for creating page instances.
|
String[] |
getPageLabels()
This method retrieves the page labels from a document as an array of String objects.
|
int |
getPageNumber(PdfDictionary pageDictionary)
Gets page number by
PdfDictionary. |
int |
getPageNumber(PdfPage page)
Gets page number by page.
|
PdfObject |
getPdfObject(int objNum)
Gets PdfObject by object number.
|
PdfVersion |
getPdfVersion()
Gets PDF version.
|
PdfReader |
getReader()
Gets
PdfReader associated with the document. |
SerializeOptions |
getSerializeOptions()
Gets a persistent XMP metadata serialization options.
|
PdfStructTreeRoot |
getStructTreeRoot()
Gets
PdfStructTreeRoot of tagged document. |
TagStructureContext |
getTagStructureContext()
Gets document
TagStructureContext. |
PdfDictionary |
getTrailer()
Gets document trailer.
|
PdfWriter |
getWriter()
Gets
PdfWriter associated with the document. |
XMPMeta |
getXmpMetadata()
Gets XMP Metadata.
|
XMPMeta |
getXmpMetadata(boolean createNew)
Gets XMP Metadata or create a new one.
|
byte[] |
getXmpMetadataBytes()
Gets XMP Metadata.
|
byte[] |
getXmpMetadataBytes(boolean createNew)
Gets XMP Metadata or create a new one.
|
boolean |
hasEventHandler(AbstractPdfDocumentEventHandler handler)
Checks if provided event handler assigned for this document.
|
boolean |
hasOutlines()
Indicates if the document has any outlines
|
void |
initializeOutlines()
This method initializes an outline tree of the document and sets outline mode to true.
|
protected void |
initTagStructureContext()
Initialize
TagStructureContext. |
boolean |
isAppendMode()
Returns
true if the document is opened in append mode, and false otherwise. |
boolean |
isClosed()
Gets close status of the document.
|
boolean |
isCloseReader()
Checks, whether
close() method will close associated PdfReader. |
boolean |
isCloseWriter()
Checks, whether
close() method will close associated PdfWriter. |
boolean |
isClosing()
Checks if the document closing has been started or not.
|
boolean |
isFlushUnusedObjects()
Checks, whether
close() will flush unused objects,
e.g. |
boolean |
isTagged()
Gets tagged status of the document.
|
List<PdfIndirectReference> |
listIndirectReferences()
Gets static copy of cross reference table.
|
void |
markStreamAsEmbeddedFile(PdfStream stream)
Marks
PdfStream object as embedded file stream. |
void |
movePage(int pageNumber,
int insertBefore)
Moves page to new place in same document with all it tag structure
|
boolean |
movePage(PdfPage page,
int insertBefore)
Moves page to new place in same document with all it tag structure
|
protected void |
open(PdfVersion newPdfVersion)
Initializes document.
|
boolean |
registerProduct(com.itextpdf.commons.actions.data.ProductData productData)
Registers a product for debugging purposes.
|
void |
removeAllHandlers()
Removes all event handlers for this document.
|
void |
removeEventHandler(AbstractPdfDocumentEventHandler 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, whether
close() method shall close associated PdfReader. |
void |
setCloseWriter(boolean closeWriter)
Sets, whether
close() method shall close associated PdfWriter. |
void |
setDefaultPageSize(PageSize pageSize)
Sets default page size.
|
void |
setEncryptedPayload(PdfFileSpec fs)
Sets an encrypted payload, making this document an unencrypted wrapper document.
|
void |
setFlushUnusedObjects(boolean flushUnusedObjects)
Sets, whether
close() shall flush unused objects,
e.g. |
void |
setSerializeOptions(SerializeOptions serializeOptions)
Sets a persistent XMP metadata serialization options.
|
PdfDocument |
setTagged()
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)
Sets 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 |
tryInitTagStructure(PdfDictionary str)
Initializes the new instance of document's structure tree root
PdfStructTreeRoot. |
protected XMPMeta |
updateDefaultXmpMetadata()
Update XMP metadata values from
PdfDocumentInfo. |
protected void |
updateXmpMetadata()
Updates XMP metadata.
|
protected final StampingProperties properties
protected PdfWriter writer
protected PdfReader reader
protected PdfCatalog catalog
protected PdfDictionary trailer
protected PdfVersion pdfVersion
protected PdfConformance pdfConformance
protected FingerPrint fingerPrint
protected SerializeOptions serializeOptions
protected PdfStructTreeRoot structTreeRoot
protected int structParentIndex
protected boolean closeReader
protected boolean closeWriter
protected boolean isClosing
protected boolean closed
protected boolean flushUnusedObjects
protected TagStructureContext tagStructureContext
protected DocumentInfoHelper documentInfoHelper
protected DefaultFontStrategy defaultFontStrategy
protected IPdfPageFactory pdfPageFactory
public PdfDocument(PdfReader reader)
reader - PDF reader.public PdfDocument(PdfReader reader, DocumentProperties properties)
reader - PDF reader.properties - document propertiespublic PdfDocument(PdfWriter writer)
writer - PDF writerpublic PdfDocument(PdfWriter writer, DocumentProperties properties)
writer - PDF writerproperties - document propertiespublic PdfDocument(PdfReader reader, PdfWriter writer)
reader - PDF reader.writer - PDF writer.public PdfDocument(PdfReader reader, PdfWriter writer, StampingProperties properties)
reader - PDF reader.writer - PDF writer.properties - properties of the stamping processpublic boolean isClosing()
true if closing process has been started, otherwise falsepublic void setXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) throws XMPException
The XMP Metadata values are synchronized with information dictionary.
xmpMeta - the xmpMetadata to setserializeOptions - serialization optionsXMPException - on serialization errorspublic void setXmpMetadata(XMPMeta xmpMeta) throws XMPException
The XMP Metadata values are synchronized with information dictionary.
serializeOptions will be used for serialization, they
can be changed by setSerializeOptions(SerializeOptions).
xmpMeta - the xmpMetadata to setXMPException - on serialization errorsprotected void setXmpMetadata(byte[] xmpMetadata)
The XMP Metadata values are synchronized with information dictionary.
xmpMetadata - the xmpMetadata bytes to setpublic XMPMeta getXmpMetadata() throws XMPException
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.
XMPException - on serialization errorspublic XMPMeta getXmpMetadata(boolean createNew) throws XMPException
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.
createNew - if true, create a new empty XMP Metadata if it did not presentXMPException - on serialization errorspublic byte[] getXmpMetadataBytes()
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.
public byte[] getXmpMetadataBytes(boolean createNew)
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.
createNew - if true, create a new empty XMP Metadata if it did not presentpublic PdfObject getPdfObject(int objNum)
objNum - object number.PdfObject or null, if object not found.public int getNumberOfPdfObjects()
public PdfPage getPage(int pageNum)
pageNum - page number.PdfException - in case the page tree is brokenpublic PdfPage getPage(PdfDictionary pageDictionary)
PdfPage instance by PdfDictionary.pageDictionary - PdfDictionary that present page.PdfDictionary.public PdfPage getFirstPage()
public PdfPage getLastPage()
public MemoryLimitsAwareHandler getMemoryLimitsAwareHandler()
MemoryLimitsAwareHandler instancepublic void markStreamAsEmbeddedFile(PdfStream stream)
PdfStream 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))stream - to be marked as embedded file streampublic PdfPage addNewPage()
public PdfPage addNewPage(PageSize pageSize)
pageSize - page size of the new pagepublic PdfPage addNewPage(int index)
index - position to addPage page toPdfException - in case page is flushedpublic PdfPage addNewPage(int index, PageSize pageSize)
index - position to addPage page topageSize - page size of the new pagePdfException - in case page is flushedpublic PdfPage addPage(PdfPage page)
page - page to add.PdfException - in case page is flushedpublic PdfPage addPage(int index, PdfPage page)
index - position to addPage page topage - page to addPagePdfException - in case page is flushedpublic int getNumberOfPages()
public int getPageNumber(PdfPage page)
page - the page.public int getPageNumber(PdfDictionary pageDictionary)
PdfDictionary.pageDictionary - PdfDictionary that present page.PdfDictionary.public boolean movePage(PdfPage page, int insertBefore)
page - page to be moved in document if presentinsertBefore - indicates before which page new one will be inserted topublic void movePage(int pageNumber,
int insertBefore)
pageNumber - number of Page that will be movedinsertBefore - indicates before which page new one will be inserted topublic boolean removePage(PdfPage page)
page - page to be removed from this document, if presentpublic void removePage(int pageNum)
pageNum - the one-based index of the PdfPage to be removedpublic com.itextpdf.commons.utils.DIContainer getDiContainer()
public PdfDocumentInfo getDocumentInfo()
info is lazy initialized. It will be initialized during the first call of this method.
The information dictionary values are synchronized with document XMP Metadata.
public PdfString getOriginalDocumentId()
In order to set originalDocumentId WriterProperties.setInitialDocumentId(com.itextpdf.kernel.pdf.PdfString) should be used
public PdfString getModifiedDocumentId()
In order to set modifiedDocumentId WriterProperties.setModifiedDocumentId(com.itextpdf.kernel.pdf.PdfString) should be used
public PageSize getDefaultPageSize()
public void setDefaultPageSize(PageSize pageSize)
pageSize - page size to be set as defaultpublic void addEventHandler(String type, AbstractPdfDocumentEventHandler handler)
type - a type of event to be handledhandler - event handlerpublic void dispatchEvent(AbstractPdfDocumentEvent event)
event - the AbstractPdfDocumentEvent to be dispatchedpublic boolean hasEventHandler(AbstractPdfDocumentEventHandler handler)
handler - the AbstractPdfDocumentEventHandler to checktrue if event handler is assigned for this document, false otherwisepublic void removeEventHandler(AbstractPdfDocumentEventHandler handler)
handler - AbstractPdfDocumentEventHandler event handler to remove for this documentpublic void removeAllHandlers()
public PdfWriter getWriter()
PdfWriter associated with the document.public PdfReader getReader()
PdfReader associated with the document.public boolean isAppendMode()
true if the document is opened in append mode, and false otherwise.true if the document is opened in append mode, and false otherwise.public PdfIndirectReference createNextIndirectReference()
public PdfVersion getPdfVersion()
public PdfCatalog getCatalog()
public void close()
close in interface Closeableclose in interface AutoCloseablepublic boolean isClosed()
public boolean isTagged()
public PdfDocument setTagged()
PdfDocument instancepublic PdfStructTreeRoot getStructTreeRoot()
PdfStructTreeRoot of tagged document.PdfStructTreeRoot in case document is tagged, otherwise it returns null.isTagged(),
getNextStructParentIndex()public int getNextStructParentIndex()
isTagged(),
getNextStructParentIndex()public TagStructureContext getTagStructureContext()
TagStructureContext.
The document must be tagged, otherwise an exception will be thrown.TagStructureContext.public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage)
toDocument.
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.
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.public PdfConformance getConformance()
PdfConformancepublic List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier)
toDocument. This range is inclusive, both page
and pageTo 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.
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 of IPdfPageExtraCopier
for the same output document.public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument)
toDocument appending copied pages to the end. This range
is inclusive, both page and pageTo 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.
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.public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, PdfDocument toDocument, IPdfPageExtraCopier copier)
toDocument appending copied pages to the end. This range
is inclusive, both page and pageTo 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.
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 of IPdfPageExtraCopier
for the same output document.public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage)
toDocument.
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.
pagesToCopy - list of pages to be copied.toDocument - a document to copy pages to.insertBeforePage - a position where to insert copied pages.public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, int insertBeforePage, IPdfPageExtraCopier copier)
toDocument.
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.
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 of IPdfPageExtraCopier
for the same output document.public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument)
toDocument 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.
pagesToCopy - list of pages to be copied.toDocument - a document to copy pages to.public List<PdfPage> copyPagesTo(List<Integer> pagesToCopy, PdfDocument toDocument, IPdfPageExtraCopier copier)
toDocument 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.
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 of IPdfPageExtraCopier
for the same output document.public void flushCopiedObjects(PdfDocument sourceDoc)
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.
sourceDoc - source documentpublic boolean isCloseReader()
close() method will close associated PdfReader.close() method is going to close associated PdfReader, otherwise false.public void setCloseReader(boolean closeReader)
close() method shall close associated PdfReader.closeReader - true, close() method shall close associated PdfReader, otherwise false.public boolean isCloseWriter()
close() method will close associated PdfWriter.close() method is going to close associated PdfWriter, otherwise false.public void setCloseWriter(boolean closeWriter)
close() method shall close associated PdfWriter.closeWriter - true, close() method shall close associated PdfWriter, otherwise false.public boolean isFlushUnusedObjects()
close() will flush unused objects,
e.g. unreachable from PDF Catalog. By default - false.close() shall not flush unused objects, otherwise true.public void setFlushUnusedObjects(boolean flushUnusedObjects)
close() shall flush unused objects,
e.g. unreachable from PDF Catalog.flushUnusedObjects - false, if close() shall not flush unused objects, otherwise true.public PdfOutline getOutlines(boolean updateOutlines)
updateOutlines - if the flag is true, the method reads the whole document and creates outline tree.
If the flag is false, the method gets cached outline tree
(if it was cached via calling getOutlines method before).PdfOutline object.public void initializeOutlines()
public void addNamedDestination(String key, PdfObject value)
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.public void addNamedDestination(PdfString key, PdfObject value)
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.public List<PdfIndirectReference> listIndirectReferences()
public PdfDictionary getTrailer()
public void addOutputIntent(PdfOutputIntent outputIntent)
PdfOutputIntent that shall specify the colour characteristics of output devices
on which the document might be rendered.outputIntent - PdfOutputIntent to add.PdfOutputIntentpublic void checkIsoConformance(IValidationContext validationContext)
public void addFileAttachment(String key, PdfFileSpec fs)
key - name of the destination.fs - PdfFileSpec object.public void addAssociatedFile(String description, PdfFileSpec fs)
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
description - the file descriptionfs - file specification dictionary of associated fileaddFileAttachment(String, PdfFileSpec)public PdfArray getAssociatedFiles()
public PdfEncryptedPayloadDocument getEncryptedPayloadDocument()
null if this document isn't an unencrypted wrapper document.public void setEncryptedPayload(PdfFileSpec fs)
fs - encrypted payload file spec. PdfEncryptedPayloadFileSpecFactory can produce one.public String[] getPageLabels()
String list of page labels if they were found, or null otherwisepublic boolean hasOutlines()
true, if there are outlines and false otherwise.public void setUserProperties(boolean userProperties)
userProperties - the user properties flagpublic PdfFont getFont(PdfDictionary dictionary)
PdfFont or load already created one.dictionary - PdfDictionary that presents PdfFont.PdfFont
Note, PdfFont which created with PdfFontFactory.createFont(PdfDictionary) won't be cached
until it will be added to PdfCanvas or PdfResources.
public PdfFont getDefaultFont()
PdfFont or null on error.public PdfFont addFont(PdfFont font)
PdfFont 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 yetfont - a PdfFont instance to addpublic boolean registerProduct(com.itextpdf.commons.actions.data.ProductData productData)
productData - product to be registered.public FingerPrint getFingerPrint()
public PdfFont findFont(String fontProgram, String encoding)
PdfFont from loaded fonts with corresponding fontProgram and encoding or CMAP.fontProgram - a font name or path to a font programencoding - an encoding or CMAPpublic long getDocumentId()
public com.itextpdf.commons.actions.sequence.SequenceId getDocumentIdWrapper()
SequenceId.public SerializeOptions getSerializeOptions()
public void setSerializeOptions(SerializeOptions serializeOptions)
serializeOptions - serialize optionsprotected void initTagStructureContext()
TagStructureContext.protected void storeDestinationToReaddress(PdfDestination destination, Consumer<PdfDestination> onPageAvailable, Consumer<PdfDestination> onPageNotAvailable)
destination - the PdfDestination to be updated itself.onPageAvailable - a destination consumer that will handle the copying when the
destination still resolves, it gets the new destination as inputonPageNotAvailable - a destination consumer that will handle the copying when the
destination is not available, it gets the original destination
as inputprotected void flushObject(PdfObject pdfObject, boolean canBeInObjStm) throws IOException
pdfObject - object to flush.canBeInObjStm - indicates whether object can be placed into object stream.IOException - on error.protected void open(PdfVersion newPdfVersion)
newPdfVersion - new pdf version of the resultant file if stamper is used and the version needs to be
changed,
or null otherwiseprotected void updateXmpMetadata()
protected XMPMeta updateDefaultXmpMetadata() throws XMPException
PdfDocumentInfo.XMPException - if the file is not well-formed XML or if parsing fails.protected Collection<PdfFont> getDocumentFonts()
PdfFont.protected void flushFonts()
protected void checkAndAddPage(int index,
PdfPage page)
index - one-base index of the page.page - PdfPage to add.protected void checkAndAddPage(PdfPage page)
page - PdfPage to add.protected void checkClosingStatus()
protected IPdfPageFactory getPageFactory()
IPdfPageFactory for current documentprotected void tryInitTagStructure(PdfDictionary str)
PdfStructTreeRoot.
See ISO 32000-1, section 14.7.2 Structure Hierarchy.str - dictionary to create structure tree rootCopyright © 1998–2025 Apryse Group NV. All rights reserved.