public class PdfDocument extends Object implements IEventDispatcher, Closeable, Serializable
Modifier and Type | Field and Description |
---|---|
protected PdfCatalog |
catalog
Document catalog.
|
protected boolean |
closed |
protected boolean |
closeReader |
protected boolean |
closeWriter |
protected PdfPage |
currentPage
Currently active page.
|
protected PageSize |
defaultPageSize
Default page size.
|
protected Set<PdfFont> |
documentFonts |
protected EventDispatcher |
eventDispatcher |
protected boolean |
flushUnusedObjects
flag determines whether to write unused objects to result document
|
protected PdfDocumentInfo |
info
Document info.
|
protected boolean |
isClosing |
protected PdfVersion |
pdfVersion
Document version.
|
protected StampingProperties |
properties |
protected PdfReader |
reader
PdfReader associated with the document.
|
protected int |
structParentIndex |
protected PdfStructTreeRoot |
structTreeRoot |
protected TagStructureContext |
tagStructureContext |
protected PdfDictionary |
trailer
Document trailed.
|
protected boolean |
userProperties |
protected PdfWriter |
writer
PdfWriter associated with the document.
|
protected byte[] |
xmpMetadata
XMP Metadata for the document.
|
Constructor and Description |
---|
PdfDocument(PdfReader reader)
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addEventHandler(String type, IEventHandler handler)
Adds new event handler.
|
void |
addFileAttachment(String description, byte[] fileStore, String fileDisplay, PdfName mimeType, PdfDictionary fileParameter, PdfName afRelationshipValue) |
void |
addFileAttachment(String description, PdfFileSpec fs) |
void |
addFileAttachment(String description, String file, String fileDisplay, PdfName mimeType, PdfName afRelationshipValue) |
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) |
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) |
protected void |
checkAndAddPage(PdfPage page) |
protected void |
checkClosingStatus()
checks whether a method is invoked at the closed document
|
protected void |
checkIsoConformance() |
void |
checkIsoConformance(Object obj, IsoKey key) |
void |
checkIsoConformance(Object obj, IsoKey key, PdfResources resources) |
void |
checkShowTextIsoConformance(Object gState, PdfResources resources) |
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(Event event)
Dispatches an event.
|
void |
dispatchEvent(Event event, boolean delayed)
Dispatches a delayed event.
|
protected void |
flushFonts() |
protected void |
flushObject(PdfObject pdfObject, boolean canBeInObjStm) |
PdfCatalog |
getCatalog()
Gets PDF catalog.
|
protected Counter |
getCounter() |
PageSize |
getDefaultPageSize()
Gets default page size.
|
protected Set<PdfFont> |
getDocumentFonts()
List all newly added or loaded fonts
|
PdfDocumentInfo |
getDocumentInfo()
Gets document information dictionary.
|
PdfPage |
getFirstPage()
Get the first page of the document.
|
PdfPage |
getLastPage()
Gets the last page of the document.
|
Integer |
getNextStructParentIndex() |
int |
getNumberOfPages()
Gets number of pages of the document.
|
int |
getNumberOfPdfObjects() |
PdfOutline |
getOutlines(boolean updateOutlines) |
PdfPage |
getPage(int pageNum)
Gets the page by page number.
|
PdfPage |
getPage(PdfDictionary pageDictionary)
Gets the PdfPage instance by PdfDictionary .
|
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) |
PdfVersion |
getPdfVersion()
Gets PDF version.
|
PdfReader |
getReader()
Gets PdfReader associated with the document.
|
PdfStructTreeRoot |
getStructTreeRoot() |
TagStructureContext |
getTagStructureContext()
Gets document TagStructureContext .
|
PdfDictionary |
getTrailer()
Gets document trailer.
|
PdfWriter |
getWriter()
Gets PdfWriter associated with the document.
|
byte[] |
getXmpMetadata()
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 |
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() |
boolean |
isAppendMode()
Returns true if the document is opened in append mode, and false otherwise.
|
boolean |
isClosed() |
boolean |
isCloseReader() |
boolean |
isCloseWriter() |
boolean |
isFlushUnusedObjects() |
boolean |
isTagged() |
List<PdfIndirectReference> |
listIndirectReferences() |
protected void |
markObjectAsMustBeFlushed(PdfObject pdfObject) |
protected void |
open(PdfVersion newPdfVersion)
Initializes document.
|
void |
removeAllHandlers()
Remove all event handlers.
|
void |
removeEventHandler(String type, IEventHandler handler)
Removes event handler.
|
PdfPage |
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) |
void |
setCloseWriter(boolean closeWriter) |
void |
setDefaultPageSize(PageSize pageSize)
Sets default page size.
|
void |
setFlushUnusedObjects(boolean flushUnusedObjects) |
void |
setTagged() |
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) |
void |
setXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) |
protected void |
storeLinkAnnotation(PdfPage page, PdfLinkAnnotation annotation) |
protected XMPMeta |
updateDefaultXmpMetadata() |
protected void |
updateXmpMetadata() |
protected PdfPage currentPage
protected PageSize defaultPageSize
protected EventDispatcher eventDispatcher
protected PdfWriter writer
protected PdfReader reader
protected byte[] xmpMetadata
protected PdfCatalog catalog
protected PdfDictionary trailer
protected PdfDocumentInfo info
protected PdfVersion pdfVersion
protected final StampingProperties properties
protected PdfStructTreeRoot structTreeRoot
protected int structParentIndex
protected boolean userProperties
protected boolean closeReader
protected boolean closeWriter
protected boolean isClosing
protected boolean closed
protected boolean flushUnusedObjects
protected TagStructureContext tagStructureContext
public PdfDocument(PdfReader reader)
reader
- PDF reader.
public PdfDocument(PdfWriter writer)
writer
- PDF writer
public 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 process
protected void setXmpMetadata(byte[] xmpMetadata)
xmpMetadata
- The xmpMetadata to set.
public void setXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) throws XMPException
XMPException
public void setXmpMetadata(XMPMeta xmpMeta) throws XMPException
XMPException
public byte[] getXmpMetadata()
public byte[] getXmpMetadata(boolean createNew)
createNew
- if true, create a new empty XMPMetadata if it did not present.
public PdfObject getPdfObject(int objNum)
public int getNumberOfPdfObjects()
public PdfPage getPage(int pageNum)
pageNum
- page number.
public PdfPage getPage(PdfDictionary pageDictionary)
PdfPage
instance by PdfDictionary
.
pageDictionary
- PdfDictionary
that present page.
PdfDictionary
.
public PdfPage getFirstPage()
public PdfPage getLastPage()
public PdfPage addNewPage()
public PdfPage addNewPage(PageSize pageSize)
pageSize
- page size of the new page
public PdfPage addNewPage(int index)
index
- position to addPage page to
PdfException
- in case page
is flushed
public PdfPage addNewPage(int index, PageSize pageSize)
index
- position to addPage page to
pageSize
- page size of the new page
PdfException
- in case page
is flushed
public PdfPage addPage(PdfPage page)
page
- page to add.
PdfException
- in case page
is flushed
public PdfPage addPage(int index, PdfPage page)
index
- position to addPage page to
page
- page to addPage
PdfException
- in case page
is flushed
public int getNumberOfPages()
public int getPageNumber(PdfPage page)
page
- the page.
public int getPageNumber(PdfDictionary pageDictionary)
PdfDictionary
.
pageDictionary
- PdfDictionary
that present page.
PdfDictionary
.
public boolean removePage(PdfPage page)
page
- page to be removed from this document, if present
public PdfPage removePage(int pageNum)
pageNum
- the one-based index of the PdfPage to be removed
public PdfDocumentInfo getDocumentInfo()
public PageSize getDefaultPageSize()
public void setDefaultPageSize(PageSize pageSize)
pageSize
- page size to be set as default.
public void addEventHandler(String type, IEventHandler handler)
IEventDispatcher
addEventHandler
in interface IEventDispatcher
type
- a type of event to be handled.
handler
- event handler.
public void dispatchEvent(Event event)
IEventDispatcher
dispatchEvent
in interface IEventDispatcher
public void dispatchEvent(Event event, boolean delayed)
IEventDispatcher
dispatchEvent
in interface IEventDispatcher
public boolean hasEventHandler(String type)
IEventDispatcher
hasEventHandler
in interface IEventDispatcher
public void removeEventHandler(String type, IEventHandler handler)
IEventDispatcher
removeEventHandler
in interface IEventDispatcher
public void removeAllHandlers()
IEventDispatcher
removeAllHandlers
in interface IEventDispatcher
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 Closeable
close
in interface AutoCloseable
public boolean isClosed()
public boolean isTagged()
public void setTagged()
public PdfStructTreeRoot getStructTreeRoot()
public Integer 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.
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.
PdfException
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, 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.
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.
copier
- a copier which bears a special copy logic. May be NULL
PdfException
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, 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.
pageFrom
-
pageTo
-
toDocument
-
PdfException
public List<PdfPage> copyPagesTo(int pageFrom, int pageTo, 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.
pageFrom
-
pageTo
-
toDocument
-
copier
- a copier which bears a special copy logic. May be NULL
PdfException
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.
pagesToCopy
- list of pages to be copied. TreeSet for the order of the pages to be natural.
toDocument
- a document to copy pages to.
insertBeforePage
- a position where to insert copied pages.
PdfException
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.
pagesToCopy
- list of pages to be copied. TreeSet for the order of the pages to be natural.
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
PdfException
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.
pagesToCopy
- list of pages to be copied. TreeSet for the order of the pages to be natural.
toDocument
- a document to copy pages to.
PdfException
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.
pagesToCopy
- list of pages to be copied. TreeSet for the order of the pages to be natural.
toDocument
- a document to copy pages to.
copier
- a copier which bears a special copy logic
PdfException
public boolean isCloseReader()
public void setCloseReader(boolean closeReader)
public boolean isCloseWriter()
public void setCloseWriter(boolean closeWriter)
public boolean isFlushUnusedObjects()
public void setFlushUnusedObjects(boolean flushUnusedObjects)
public PdfOutline getOutlines(boolean updateOutlines)
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 PdfSpec 12.3.2.3 for more info.
PdfException
public List<PdfIndirectReference> listIndirectReferences()
public PdfDictionary getTrailer()
public void addOutputIntent(PdfOutputIntent outputIntent)
public void checkIsoConformance(Object obj, IsoKey key, PdfResources resources)
public void checkShowTextIsoConformance(Object gState, PdfResources resources)
public void addFileAttachment(String description, byte[] fileStore, String fileDisplay, PdfName mimeType, PdfDictionary fileParameter, PdfName afRelationshipValue)
public void addFileAttachment(String description, String file, String fileDisplay, PdfName mimeType, PdfName afRelationshipValue) throws FileNotFoundException
FileNotFoundException
public void addFileAttachment(String description, PdfFileSpec fs)
public String[] getPageLabels()
String
list of page labels if they were found, or null
otherwise
public boolean hasOutlines()
true
, if there are outlines and false
otherwise.
public void setUserProperties(boolean userProperties)
userProperties
- the user properties flag
protected void initTagStructureContext()
protected void storeLinkAnnotation(PdfPage page, PdfLinkAnnotation annotation)
protected void checkIsoConformance()
protected void markObjectAsMustBeFlushed(PdfObject pdfObject)
protected void flushObject(PdfObject pdfObject, boolean canBeInObjStm) throws IOException
IOException
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
otherwise
PdfException
protected void updateXmpMetadata()
protected XMPMeta updateDefaultXmpMetadata() throws XMPException
XMPException
protected Set<PdfFont> getDocumentFonts()
PdfFonts
.
protected void flushFonts()
protected void checkAndAddPage(int index, PdfPage page)
protected void checkAndAddPage(PdfPage page)
protected void checkClosingStatus()
PdfException
protected Counter getCounter()
Copyright © 1998–2016 iText Group NV. All rights reserved.