public class PdfPage extends PdfObjectWrapper<PdfDictionary>
Modifier | Constructor and Description |
---|---|
protected |
PdfPage(PdfDictionary pdfObject) |
protected |
PdfPage(PdfDocument pdfDocument) |
protected |
PdfPage(PdfDocument pdfDocument, PageSize pageSize) |
Modifier and Type | Method and Description |
---|---|
PdfPage |
addAnnotation(int index, PdfAnnotation annotation, boolean tagAnnotation)
Adds specified PdfAnnotation to specified index in annotations array with or without autotagging.
|
PdfPage |
addAnnotation(PdfAnnotation annotation)
Adds specified annotation to the end of annotations array and tagged it.
|
void |
addAssociatedFile(PdfFileSpec fs)
Adds file associated with PDF page and identifies the relationship between them.
|
void |
addAssociatedFile(String description, PdfFileSpec fs)
Adds file associated with PDF page and identifies the relationship between them.
|
PdfPage |
addOutputIntent(PdfOutputIntent outputIntent)
Adds PdfOutputIntent that shall specify the colour characteristics of output devices on which the page might be rendered.
|
boolean |
containsAnnotation(PdfAnnotation annotation)
Checks if page contains the specified annotation.
|
PdfFormXObject |
copyAsFormXObject(PdfDocument toDocument)
Copies page as FormXObject to the specified document.
|
PdfPage |
copyTo(PdfDocument toDocument)
Copies page to the specified document.
|
PdfPage |
copyTo(PdfDocument toDocument, IPdfPageExtraCopier copier)
Copies page to the specified document.
|
void |
flush()
Flushes page dictionary, its content streams, annotations and thumb image.
|
void |
flush(boolean flushResourcesContentStreams)
Flushes page dictionary, its content streams, annotations and thumb image.
|
List<PdfAnnotation> |
getAnnotations()
Gets array of annotation dictionaries that shall contain indirect references to all annotations associated with the page.
|
int |
getAnnotsSize()
Gets the number of PdfAnnotation associated with this page.
|
Rectangle |
getArtBox()
Gets the Rectangle object specified by page's ArtBox, that define the extent of the page’s meaningful content (including potential white space) as intended by the page’s creator.
|
PdfArray |
getAssociatedFiles(boolean create)
Returns files associated with PDF page.
|
Rectangle |
getBleedBox()
Gets the Rectangle object specified by page's BleedBox, that define the region to which the contents of the page shall be clipped when output in a production environment.
|
byte[] |
getContentBytes()
Get decoded bytes for the whole page content.
|
PdfStream |
getContentStream(int index)
Gets the content stream at specified 0-based index in the Contents object PdfArray .
|
int |
getContentStreamCount()
Gets the size of Contents object PdfArray .
|
Rectangle |
getCropBox()
Gets the Rectangle specified by page's CropBox, that defines the visible region of default user space.
|
PdfDocument |
getDocument()
Gets the PdfDocument that owns that page, or null if such document isn't exist.
|
PdfStream |
getFirstContentStream()
|
PdfStream |
getLastContentStream()
|
Rectangle |
getMediaBox()
Gets Rectangle object specified by page's Media Box, that defines the boundaries of the physical medium on which the page shall be displayed or printed
|
int |
getNextMcid()
Calculates and returns the next available for this page's content stream MCID reference.
|
List<PdfOutline> |
getOutlines(boolean updateOutlines)
This method gets outlines of a current page
|
Rectangle |
getPageSize()
Gets page size, defined by media box object.
|
Rectangle |
getPageSizeWithRotation()
Gets page size, considering page rotation.
|
PdfResources |
getResources()
Gets the PdfResources wrapper object for this page resources.
|
int |
getRotation()
Gets the number of degrees by which the page shall be rotated clockwise when displayed or printed.
|
byte[] |
getStreamBytes(int index)
Gets decoded bytes of a certain stream of a page content.
|
int |
getStructParentIndex()
Gets the key of the page’s entry in the structural parent tree.
|
PdfName |
getTabOrder()
Gets a name specifying the tab order that shall be used for annotations on the page.
|
PdfImageXObject |
getThumbnailImage()
Sets a stream object that shall define the page’s thumbnail image.
|
Rectangle |
getTrimBox()
Gets the Rectangle object specified by page's TrimBox object, that define the intended dimensions of the finished page after trimming.
|
PdfStream |
getXmpMetadata()
Gets the XMP Metadata object.
|
boolean |
isIgnorePageRotationForContent() |
boolean |
isPageRotationInverseMatrixWritten()
This flag is meaningful for the case, when page rotation is applied and ignorePageRotationForContent is set to true.
|
protected boolean |
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.
|
PdfStream |
newContentStreamAfter()
|
PdfStream |
newContentStreamBefore()
|
PdfPage |
put(PdfName key, PdfObject value)
Helper method that associate specified value with specified key in the underlined PdfDictionary .
|
PdfPage |
removeAnnotation(PdfAnnotation annotation)
Removes an annotation from the page.
|
PdfPage |
setAdditionalAction(PdfName key, PdfAction action)
Helper method to add an additional action to this page.
|
PdfPage |
setArtBox(Rectangle rectangle)
Sets the ArtBox object, that define the extent of the page’s meaningful content (including potential white space) as intended by the page’s creator.
|
PdfPage |
setBleedBox(Rectangle rectangle)
Sets the BleedBox object, that defines the region to which the contents of the page shall be clipped when output in a production environment.
|
PdfPage |
setCropBox(Rectangle rectangle)
Sets the CropBox object, that defines the visible region of default user space.
|
PdfPage |
setIgnorePageRotationForContent(boolean ignorePageRotationForContent)
If true - defines that in case the page has a rotation, then new content will be automatically rotated in the opposite direction.
|
PdfPage |
setMediaBox(Rectangle rectangle)
Sets the Media Box object, that defines the boundaries of the physical medium on which the page shall be displayed or printed.
|
PdfPage |
setPageLabel(PageLabelNumberingStyle numberingStyle, String labelPrefix)
This method adds or replaces a page label.
|
PdfPage |
setPageLabel(PageLabelNumberingStyle numberingStyle, String labelPrefix, int firstPage)
This method adds or replaces a page label.
|
void |
setPageRotationInverseMatrixWritten()
NOTE: For internal usage! Use this method only if you know what you are doing.
|
PdfPage |
setResources(PdfResources pdfResources)
Sets PdfResources object.
|
PdfPage |
setRotation(int degAngle)
Sets the page rotation.
|
PdfPage |
setTabOrder(PdfName tabOrder)
Sets a name specifying the tab order that shall be used for annotations on the page.
|
PdfPage |
setThumbnailImage(PdfImageXObject thumb)
Sets a stream object that shall define the page’s thumbnail image.
|
PdfPage |
setTrimBox(Rectangle rectangle)
Sets the TrimBox object, that define the intended dimensions of the finished page after trimming.
|
PdfPage |
setXmpMetadata(byte[] xmpMetadata)
Sets the XMP Metadata.
|
PdfPage |
setXmpMetadata(XMPMeta xmpMeta)
Serializes XMP Metadata to byte array and sets it.
|
PdfPage |
setXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions)
Serializes XMP Metadata to byte array and sets it.
|
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
protected PdfPage(PdfDictionary pdfObject)
protected PdfPage(PdfDocument pdfDocument, PageSize pageSize)
protected PdfPage(PdfDocument pdfDocument)
public Rectangle getPageSize()
Rectangle
that specify page size.
public Rectangle getPageSizeWithRotation()
Rectangle
that specify size of rotated page.
public int getRotation()
int
number of degrees. Default value: 0
public PdfPage setRotation(int degAngle)
degAngle
- the int
number of degrees by which the page shall be rotated clockwise when displayed or printed. Shall be a multiple of 90.
PdfPage
instance.
public PdfStream getContentStream(int index)
PdfArray
. The situation when Contents object is a PdfStream
is treated like a one element array.
index
- the int
index of returned PdfStream
.
PdfStream
object at specified index; will return null in case page dictionary doesn't adhere to the specification, meaning that the document is an invalid PDF.
IndexOutOfBoundsException
- if the index is out of range
public int getContentStreamCount()
PdfArray
. The situation when Contents object is a PdfStream
is treated like a one element array.
int
size of Contents object, or 1 if Contents object is a PdfStream
.
public PdfStream getFirstContentStream()
PdfStream
in Contents object, or null
if Contents is empty.
public PdfStream getLastContentStream()
PdfStream
in Contents object, or null
if Contents is empty.
public PdfStream newContentStreamBefore()
PdfStream
object and puts it at the beginning of Contents array (if Contents object is PdfStream
it will be replaced with one-element array).
PdfStream
object.
public PdfStream newContentStreamAfter()
PdfStream
object and puts it at the end of Contents array (if Contents object is PdfStream
it will be replaced with one-element array).
PdfStream
object.
public PdfResources getResources()
PdfResources
wrapper object for this page resources. If page doesn't have resource object, then it will be inherited from page's parents. If neither parents nor page has the resource object, then the new one is created and added to page dictionary.
flush()
, or you can add it manually with this line, if needed:
getPdfObject().put(PdfName.Resources, getResources().getPdfObject());
PdfResources
wrapper of the page.
public PdfPage setResources(PdfResources pdfResources)
PdfResources
object.
pdfResources
- PdfResources
to set.
PdfPage
instance.
public PdfPage setXmpMetadata(byte[] xmpMetadata) throws IOException
xmpMetadata
- the byte[]
of XMP Metadata to set.
PdfPage
instance.
IOException
- in case of writing error.
public PdfPage setXmpMetadata(XMPMeta xmpMeta, SerializeOptions serializeOptions) throws XMPException, IOException
xmpMeta
- the XMPMeta
object to set.
serializeOptions
- the SerializeOptions
used while serialization.
PdfPage
instance.
XMPException
- in case of XMP Metadata serialization error.
IOException
- in case of writing error.
public PdfPage setXmpMetadata(XMPMeta xmpMeta) throws XMPException, IOException
xmpMeta
- the XMPMeta
object to set.
PdfPage
instance.
XMPException
- in case of XMP Metadata serialization error.
IOException
- in case of writing error.
public PdfStream getXmpMetadata()
PdfStream
object, that represent XMP Metadata.
public PdfPage copyTo(PdfDocument toDocument)
toDocument
- a document to copy page to.
PdfPage
.
public PdfPage copyTo(PdfDocument toDocument, IPdfPageExtraCopier copier)
toDocument
- a document to copy page 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.
PdfPage
.
public PdfFormXObject copyAsFormXObject(PdfDocument toDocument) throws IOException
toDocument
- a document to copy to.
PdfFormXObject
object.
IOException
- if an I/O error occurs.
public PdfDocument getDocument()
PdfDocument
that owns that page, or null
if such document isn't exist.
PdfDocument
that owns that page, or null
if such document isn't exist.
public void flush()
If the page belongs to the document which is tagged, page flushing also triggers flushing of the tags, which are considered to belong to the page. The logic that defines if the given tag (structure element) belongs to the page is the following: if all the marked content references (dictionary or number references), that are the descendants of the given structure element, belong to the current page - the tag is considered to belong to the page. If tag has descendants from several pages - it is flushed, if all other pages except the current one are flushed.
flush
in class PdfObjectWrapper<PdfDictionary>
public void flush(boolean flushResourcesContentStreams)
flushResourcesContentStreams
is true, all content streams that are rendered on this page (like FormXObjects, annotation appearance streams, patterns) and also all images associated with this page will also be flushed.
For notes about tag structure flushing see PdfPage#flush() method
.
If PdfADocument
is used, flushing will be applied only if flushResourcesContentStreams
is true.
Be careful with handling document in which some of the pages are flushed. Keep in mind that flushed objects are finalized and are completely written to the output stream. This frees their memory but makes it impossible to modify or read data from them. Whenever there is an attempt to modify or to fetch flushed object inner contents an exception will be thrown. Flushing is only possible for objects in the writing and stamping modes, also its possible to flush modified objects in append mode.
flushResourcesContentStreams
- if true all content streams that are rendered on this page (like form xObjects, annotation appearance streams, patterns) and also all images associated with this page will be flushed.
public Rectangle getMediaBox()
Rectangle
object specified by page's Media Box, that defines the boundaries of the physical medium on which the page shall be displayed or printed
Rectangle
object specified by page Media Box, expressed in default user space units.
PdfException
- in case of any error while reading MediaBox object.
public PdfPage setMediaBox(Rectangle rectangle)
public Rectangle getCropBox()
Rectangle
specified by page's CropBox, that defines the visible region of default user space. When the page is displayed or printed, its contents shall be clipped (cropped) to this rectangle and then shall be imposed on the output medium in some implementation-defined manner.
Rectangle
object specified by pages's CropBox, expressed in default user space units. MediaBox by default.
public PdfPage setCropBox(Rectangle rectangle)
public PdfPage setBleedBox(Rectangle rectangle)
public Rectangle getBleedBox()
Rectangle
object specified by page's BleedBox, that define the region to which the contents of the page shall be clipped when output in a production environment.
Rectangle
object specified by page's BleedBox, expressed in default user space units. CropBox by default.
public PdfPage setArtBox(Rectangle rectangle)
public Rectangle getArtBox()
Rectangle
object specified by page's ArtBox, that define the extent of the page’s meaningful content (including potential white space) as intended by the page’s creator.
Rectangle
object specified by page's ArtBox, expressed in default user space units. CropBox by default.
public PdfPage setTrimBox(Rectangle rectangle)
public Rectangle getTrimBox()
Rectangle
object specified by page's TrimBox object, that define the intended dimensions of the finished page after trimming.
Rectangle
object specified by page's TrimBox, expressed in default user space units. CropBox by default.
public byte[] getContentBytes()
PdfException
- in case of any IOException
.
public byte[] getStreamBytes(int index)
index
- index of stream inside Content.
PdfException
- in case of any IOException
.
public int getNextMcid()
PdfException
- in case of not tagged document.
public int getStructParentIndex()
public PdfPage setAdditionalAction(PdfName key, PdfAction action)
public List<PdfAnnotation> getAnnotations()
List
<PdfAnnotation
> containing all page's annotations.
public boolean containsAnnotation(PdfAnnotation annotation)
annotation
- the PdfAnnotation
to check.
true
if page contains specified annotation and false
otherwise.
public PdfPage addAnnotation(PdfAnnotation annotation)
annotation
- the PdfAnnotation
to add.
PdfPage
instance.
public PdfPage addAnnotation(int index, PdfAnnotation annotation, boolean tagAnnotation)
PdfAnnotation
to specified index in annotations array with or without autotagging. May be used in chain.
index
- the index at which specified annotation will be added. If -1
then annotation will be added to the end of array.
annotation
- the PdfAnnotation
to add.
tagAnnotation
- if true
the added annotation will be autotagged.
PdfPage
instance.
public PdfPage removeAnnotation(PdfAnnotation annotation)
annotation
- an annotation to be removed.
PdfPage
instance.
public int getAnnotsSize()
PdfAnnotation
associated with this page.
int
number of PdfAnnotation
associated with this page.
public List<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).
public boolean isIgnorePageRotationForContent()
public PdfPage setIgnorePageRotationForContent(boolean ignorePageRotationForContent)
false
.
ignorePageRotationForContent
- - true to ignore rotation of the new content on the rotated page.
PdfPage
instance.
public PdfPage setPageLabel(PageLabelNumberingStyle numberingStyle, String labelPrefix)
numberingStyle
- The numbering style that shall be used for the numeric portion of each page label. May be NULL
labelPrefix
- The label prefix for page labels in this range. May be NULL
PdfPage
instance.
public PdfPage setPageLabel(PageLabelNumberingStyle numberingStyle, String labelPrefix, int firstPage)
numberingStyle
- The numbering style that shall be used for the numeric portion of each page label. May be NULL
labelPrefix
- The label prefix for page labels in this range. May be NULL
firstPage
- The value of the numeric portion for the first page label in the range. Must be greater or equal 1.
PdfPage
instance.
public PdfPage setTabOrder(PdfName tabOrder)
PdfName.R
(row order), PdfName.C
(column order), and PdfName.S
(structure order). Beginning with PDF 2.0, the possible values also include PdfName.A
(annotations array order) and PdfName.W
(widget order). See ISO 32000 12.5, "Annotations" for details.
public PdfName getTabOrder()
PdfName.R
(row order), PdfName.C
(column order), and PdfName.S
(structure order). Beginning with PDF 2.0, the possible values also include PdfName.A
(annotations array order) and PdfName.W
(widget order). See ISO 32000 12.5, "Annotations" for details.
PdfName
specifying the annotations tab order or null if tab order is not defined.
public PdfPage setThumbnailImage(PdfImageXObject thumb)
thumb
- the thumbnail image
PdfPage
object
public PdfImageXObject getThumbnailImage()
null
if it is not present
public PdfPage addOutputIntent(PdfOutputIntent outputIntent)
PdfOutputIntent
that shall specify the colour characteristics of output devices on which the page might be rendered.
outputIntent
- PdfOutputIntent
to add.
PdfPage
object
PdfOutputIntent
public PdfPage put(PdfName key, PdfObject value)
PdfDictionary
. May be used in chain.
public boolean isPageRotationInverseMatrixWritten()
setIgnorePageRotationForContent(boolean)
public void setPageRotationInverseMatrixWritten()
setIgnorePageRotationForContent(boolean)
public void addAssociatedFile(String description, PdfFileSpec fs)
Associated files may be used in Pdf/A-3 and Pdf 2.0 documents. The method adds file to array value of the AF key in the page dictionary. If description is provided, it also will add file description to catalog Names tree.
For associated files their associated file specification dictionaries shall include the AFRelationship key
description
- the file description
fs
- file specification dictionary of associated file
public void addAssociatedFile(PdfFileSpec fs)
Adds file associated with PDF page and identifies the relationship between them.
Associated files may be used in Pdf/A-3 and Pdf 2.0 documents. The method adds file to array value of the AF key in the page dictionary.
For associated files their associated file specification dictionaries shall include the AFRelationship key
fs
- file specification dictionary of associated file
public PdfArray getAssociatedFiles(boolean create)
create
- defines whether AF arrays will be created if it doesn't exist
protected boolean isWrappedObjectMustBeIndirect()
PdfObjectWrapper
isWrappedObjectMustBeIndirect
in class PdfObjectWrapper<PdfDictionary>
Copyright © 1998–2023 iText Group NV. All rights reserved.