Page

Overview

Page is a class in Aspose.PDF FOSS for Python.

A page of a PDF document.

This class provides 10 methods for working with Page objects in Python programs. Available methods include: __init__, accept, add_image, add_text, draw_line, draw_rectangle, redact_text, render, replace_text, save_as_image. All public members are accessible to any Python application after installing the Aspose.PDF FOSS for Python package. Properties: annotations, content, crop_box, index, media_box, rect, and 1 more.

Properties

NameTypeAccessDescription
indexintRead/WriteThe zero-based index of the page.
recttuple[float, float, float, float]ReadGet the page rectangle (MediaBox).
annotationsAnnotationCollectionReadGet the collection of annotations on the page.
media_boxtuple[float, float, float, float]ReadAlias for rect.
rotationintRead/WriteThe page rotation in degrees, clockwise (one of 0, 90, 180, 270).
crop_boxtuple[float, float, float, float]Read/WriteThe page CropBox (x0, y0, x1, y1); falls back to the MediaBox when unset.
contentbytesReadGet the page content stream.

Methods

SignatureDescription
__init__(document: Document, index: int)Calls init(document, index) on this Page instance.
add_text(text: str, x: float, y: float, font_size: float, font_name: str | None, font: FontDescriptor | bytes | bytearray | str | Path | None, color: Sequence[float], tag: str | None, actual_text: str | None, layout: TextLayoutOptions | None)PageAppend positioned text to this page.
add_image(image: bytes | bytearray | str | Path, x: float, y: float, width: float | None, height: float | None, pixel_width: int | None, pixel_height: int | None, color_space: str, bits_per_component: int, name: str | None, tag: str | None, alt: str | None, actual_text: str | None)strPlace an image on this page and return its resource name.
draw_rectangle(x: float, y: float, width: float, height: float, stroke_color: Sequence[float] | None, fill_color: Sequence[float] | None, line_width: float, tag: str | None, alt: str | None, actual_text: str | None)PageAppend a stroked and/or filled rectangle to this page.
draw_line(x1: float, y1: float, x2: float, y2: float, stroke_color: Sequence[float], line_width: float, tag: str | None, alt: str | None, actual_text: str | None)PageAppend a stroked line segment to this page.
accept(visitor: Any)Dispatch this page to an object implementing visit(page).
render(dpi: float, scale: float, background: tuple[int, int, int], antialias: bool | int)RasterizedPageRender this page to an RGB raster image.
save_as_image(path: str | Path, dpi: float, scale: float, background: tuple[int, int, int], antialias: bool | int)PathRender this page and save it as .png or .tif/.tiff.
replace_text(search: str, replacement: str, case_sensitive: bool, max_count: int)intReplace existing text in simple text-showing operands on this page.
redact_text(search: str, case_sensitive: bool, max_count: int, overlay: bool, overlay_color: Sequence[float])intRemove existing text from simple text-showing operands on this page.

See Also