Page
Overview
Page is a class in Aspose.PDF FOSS for Java.
Represents a single PDF page (ISO 32000-1:2008, §7.7.3.3).
This class provides 67 methods for working with Page objects in Java programs.
Available methods include: Page, accept, add, addStamp, addSyntheticTextFragments, appendToContentStream, applyHeaderFooterOverlay, calculateContentBBox, clearContentsCache, ensureResources, flattenAnnotations, flushContentsIfDirty, and 51 additional methods.
All public members are accessible to any Java application after installing the Aspose.PDF FOSS for Java package.
Properties: annotations, artBox, artifacts, background, blank, bleedBox, and 22 more.
Properties
| Name | Type | Access | Description |
|---|---|---|---|
owningDocument | Document | Read | Returns the document that owns this page, or null if not attached. |
mediaBox | Rectangle | Read | Returns the media box for this page (ISO 32000, §7.7.3.3, Table 30). |
cropBox | Rectangle | Read | Returns the crop box for this page. |
artBox | Rectangle | Read | Returns the art box. |
bleedBox | Rectangle | Read | Returns the bleed box. |
trimBox | Rectangle | Read | Returns the trim box. |
rect | Rectangle | Read | Returns the effective rectangle for this page (same as getCropBox). |
rotate | int | Read | Returns the page rotation in degrees (0, 90, 180, or 270). |
rotationMatrix | Matrix | Read | Returns the page rotation matrix. |
resources | Resources | Read | Returns the page resources. |
rawContents | PdfBase | Read | Returns the raw page content stream PDF object, or null if absent. |
contents | OperatorCollection | Read | Returns the parsed content stream operators (like Aspose’s page.Contents). |
contentsDirty | boolean | Read | @return whether this page’s cached content operators have unsaved edits. |
syntheticTextFragments | List<TextFragment> | Read | Returns synthetic in-memory text fragments associated with this page. |
annotations | AnnotationCollection | Read | Returns the typed annotation collection for this page. |
pdfDictionary | PdfDictionary | Read | Returns the underlying PDF dictionary for this page. |
background | Color | Read | Returns the page background colour as set by {@link #setBackground(Color)}, |
| or {@code null} if no explicit background has been applied. | |||
number | int | Read | Returns the 1-based page number (set by PageCollection). |
layers | java.util.List<Layer> | Read | Returns the list of layers (Optional Content Groups) on this page. |
colorType | ColorType | Read | Classifies the dominant colour content of this page — |
| {@link ColorType#Rgb} if the content has any chromatic colour, | |||
| {@link ColorType#Grayscale} if it uses only gray midtones, | |||
| {@link ColorType#BlackAndWhite} if every observed colour is solid | |||
| black or solid white, or {@link ColorType#Undefined} for an empty / | |||
| unreadable content stream. | |||
artifacts | ArtifactCollection | Read | Returns the collection of artifacts found on this page. |
paragraphs | Paragraphs | Read | Returns the paragraph collection for this page. |
pageInfo | PageInfo | Read | Returns the page info (dimensions and margins) for this page. |
header | HeaderFooter | Read | Returns the header for this page, or null if none. |
footer | HeaderFooter | Read | Returns the footer for this page, or null if none. |
tocInfo | TocInfo | Read | Returns the TOC info for this page, or null. |
stampInfoRecords | PdfArray | Read | Returns stamp metadata records stored on this page. |
blank | boolean | Read | Returns {@code true} if the page has no visible content (empty or absent content stream). |
Methods
| Signature | Description |
|---|---|
Page(pageDict: PdfDictionary, parser: PDFParser) | Creates a Page wrapper around the given page dictionary. |
getOwningDocument() → Document | Returns the document that owns this page, or null if not attached. |
getMediaBox() → Rectangle | Returns the media box for this page (ISO 32000, §7.7.3.3, Table 30). |
getCropBox() → Rectangle | Returns the crop box for this page. |
getArtBox() → Rectangle | Returns the art box. |
getBleedBox() → Rectangle | Returns the bleed box. |
getTrimBox() → Rectangle | Returns the trim box. |
getRect() → Rectangle | Returns the effective rectangle for this page (same as getCropBox). |
calculateContentBBox() → Rectangle | Returns the minimal bounding box of inked content on this page in user |
| space, scanning the content stream for path operators ({@code re}, | |
| {@code m}, {@code l}, {@code c}), text-positioning operators | |
| ({@code Tm}, {@code Td}, {@code T*}) and XObject invocations ({@code Do}). | |
getPageRect(considerRotation: boolean) → Rectangle | Returns the page rectangle, optionally considering rotation. |
getRotate() → int | Returns the page rotation in degrees (0, 90, 180, or 270). |
getRotationMatrix() → Matrix | Returns the page rotation matrix. |
getResources() → Resources | Returns the page resources. |
getRawContents() → PdfBase | Returns the raw page content stream PDF object, or null if absent. |
getContents() → OperatorCollection | Returns the parsed content stream operators (like Aspose’s page.Contents). |
markContentsDirty() | Marks the cached operator collection as dirty, so that the next |
| {@link #flushContentsIfDirty()} (invoked by {@code Document.save}) will | |
| serialise the current cache back into {@code /Contents}. | |
isContentsDirty() → boolean | @return whether this page’s cached content operators have unsaved edits. |
flushPageInfoIfNeeded() | Propagates the page-level {@link PageInfo} dimensions back to the |
| page’s {@code /MediaBox} if the user has changed them through | |
| {@link #getPageInfo()}{@code .setWidth(…)} / {@code setHeight(…)} / | |
| {@code setIsLandscape(…)}. | |
flushContentsIfDirty() | |
clearContentsCache() | Clears the cached operator collection, forcing the next |
| {@link #getContents()} call to re-parse from {@code /Contents}. | |
addSyntheticTextFragments(fragments: List<TextFragment>) | Registers synthetic in-memory text fragments associated with this page. |
getSyntheticTextFragments() → List<TextFragment> | Returns synthetic in-memory text fragments associated with this page. |
getAnnotations() → AnnotationCollection | Returns the typed annotation collection for this page. |
getPdfDictionary() → PdfDictionary | Returns the underlying PDF dictionary for this page. |
getBackground() → Color | Returns the page background colour as set by {@link #setBackground(Color)}, |
| or {@code null} if no explicit background has been applied. | |
setBackground(color: Color) | Sets a solid background colour for this page. |
getNumber() → int | Returns the 1-based page number (set by PageCollection). |
setNumber(number: int) | Sets the 1-based page number. |
setMediaBox(rect: Rectangle) | Sets the media box for this page (ISO 32000, §7.7.3.3, Table 30). |
setCropBox(rect: Rectangle) | Sets the crop box for this page (ISO 32000, §14.11.2). |
setArtBox(rect: Rectangle) | Sets the art box for this page. |
setBleedBox(rect: Rectangle) | Sets the bleed box for this page. |
setTrimBox(rect: Rectangle) | Sets the trim box for this page. |
setRotation(degrees: int) | Sets the page rotation in degrees. |
setRotate(rotation: Rotation) | Sets the page rotation using the {@link Rotation} enum. |
accept(absorber: TextAbsorber) | Accepts a text absorber to extract text from this page. |
accept(absorber: ImagePlacementAbsorber) | Accepts an image placement absorber to find images on this page. |
getLayers() → java.util.List<Layer> | Returns the list of layers (Optional Content Groups) on this page. |
setLayers(layers: java.util.List<Layer>) | Sets the layers for this page. |
getColorType() → ColorType | Classifies the dominant colour content of this page — |
| {@link ColorType#Rgb} if the content has any chromatic colour, | |
| {@link ColorType#Grayscale} if it uses only gray midtones, | |
| {@link ColorType#BlackAndWhite} if every observed colour is solid | |
| black or solid white, or {@link ColorType#Undefined} for an empty / | |
| unreadable content stream. | |
getArtifacts() → ArtifactCollection | Returns the collection of artifacts found on this page. |
add(artifact: Artifact) | |
setPageSize(width: double, height: double) | Convenience method to set the page size by setting the media box. |
getParagraphs() → Paragraphs | Returns the paragraph collection for this page. |
setParagraphs(paragraphs: Paragraphs) | Sets the paragraph collection for this page. |
getPageInfo() → PageInfo | Returns the page info (dimensions and margins) for this page. |
setPageInfo(pageInfo: PageInfo) | Sets the page info. |
getHeader() → HeaderFooter | Returns the header for this page, or null if none. |
setHeader(header: HeaderFooter) | Sets the header for this page. |
getFooter() → HeaderFooter | Returns the footer for this page, or null if none. |
setFooter(footer: HeaderFooter) | Sets the footer for this page. |
applyHeaderFooterOverlay(pageNumber: int, totalPages: int) | Renders this page’s header and/or footer (set via {@link #setHeader}/ |
| {@link #setFooter}) as a Form XObject overlay appended to the page’s | |
| existing content stream. | |
getTocInfo() → TocInfo | Returns the TOC info for this page, or null. |
setTocInfo(tocInfo: TocInfo) | Sets the TOC info, making this page a table-of-contents page. |
flattenAnnotations() | Flattens all annotations on this page by baking their normal appearance |
| streams into the page content stream, then removing the /Annots entry | |
| (ISO 32000-1:2008, §12.5.5). | |
addStamp(stamp: Stamp) | Adds a stamp to this page by delegating to the stamp’s {@link Stamp#put(Page)} method. |
addStamp(stamp: TextStamp) | Adds a text stamp to this page by generating content stream operators. |
addStamp(stamp: ImageStamp) | Adds an image stamp to this page by generating content stream operators. |
addStamp(stamp: PdfPageStamp) | Adds a page stamp to this page by overlaying the source page content. |
getStampInfoRecords() → PdfArray | Returns stamp metadata records stored on this page. |
removeStampById(stampId: int) → boolean | |
prependToContentStream(data: byte[]) | Prepends raw content stream data before this page’s existing /Contents. |
appendToContentStream(data: byte[]) | Appends raw content stream data to this page’s /Contents. |
ensureResources() → Resources | Ensures this page has a /Resources dictionary, creating one if absent. |
setContents(operators: OperatorCollection) | Replaces the page content stream with the given operator collection. |
isBlank() → boolean | Returns {@code true} if the page has no visible content (empty or absent content stream). |
replaceText(searchText: String, replaceText: String) → int | Replaces all occurrences of {@code searchText} with {@code replaceText} |
| in this page’s content stream. |