Struct pdfium_render::page::PdfPage

source ·
pub struct PdfPage<'a> { /* private fields */ }
Expand description

A single page in a PdfDocument.

In addition to its own intrinsic properties, a PdfPage serves as the entry point to all object collections related to a single page in a document. These collections include:

Implementations§

source§

impl<'a> PdfPage<'a>

source

pub fn document(&self) -> &'a PdfDocument<'a>

Returns the PdfDocument containing this PdfPage.

source

pub fn bindings(&self) -> &'a dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings used by the PdfDocument containing this PdfPage.

source

pub fn label(&self) -> Option<&str>

Returns the label assigned to this PdfPage, if any.

source

pub fn width(&self) -> PdfPoints

Returns the width of this PdfPage in device-independent points. One point is 1/72 inches, roughly 0.358 mm.

source

pub fn height(&self) -> PdfPoints

Returns the height of this PdfPage in device-independent points. One point is 1/72 inches, roughly 0.358 mm.

source

pub fn page_size(&self) -> PdfRect

Returns the width and height of this PdfPage expressed as a PdfRect.

source

pub fn orientation(&self) -> PdfPageOrientation

Returns PdfPageOrientation::Landscape if the width of this PdfPage is greater than its height; otherwise returns PdfPageOrientation::Portrait.

source

pub fn is_portrait(&self) -> bool

Returns true if this PdfPage has orientation PdfPageOrientation::Portrait.

source

pub fn is_landscape(&self) -> bool

Returns true if this PdfPage has orientation PdfPageOrientation::Landscape.

source

pub fn rotation(&self) -> Result<PdfBitmapRotation, PdfiumError>

Returns any intrinsic rotation encoded into this document indicating a rotation should be applied to this PdfPage during rendering.

source

pub fn set_rotation(&mut self, rotation: PdfBitmapRotation)

Sets the intrinsic rotation that should be applied to this PdfPage during rendering.

source

pub fn has_transparency(&self) -> bool

Returns true if any object on the page contains transparency.

source

pub fn paper_size(&self) -> PdfPagePaperSize

Returns the paper size of this PdfPage.

source

pub fn has_embedded_thumbnail(&self) -> bool

Returns true if this PdfPage contains an embedded thumbnail.

Embedded thumbnails can be generated as a courtesy by PDF generators to save PDF consumers the burden of having to render their own thumbnails on the fly. If a thumbnail for this page was not embedded at the time the document was created, one can easily be rendered using the standard rendering functions:

    let thumbnail_desired_pixel_size = 128;

    let thumbnail = page.render_with_config(
        &PdfRenderConfig::thumbnail(thumbnail_desired_pixel_size)
    )?; // Renders a 128 x 128 thumbnail of the page
source

pub fn embedded_thumbnail(&self) -> Result<PdfBitmap<'_>, PdfiumError>

Returns the embedded thumbnail for this PdfPage, if any.

Embedded thumbnails can be generated as a courtesy by PDF generators to save PDF consumers the burden of having to render their own thumbnails on the fly. If a thumbnail for this page was not embedded at the time the document was created, one can easily be rendered using the standard rendering functions:

    let thumbnail_desired_pixel_size = 128;

    let thumbnail = page.render_with_config(
        &PdfRenderConfig::thumbnail(thumbnail_desired_pixel_size)
    )?; // Renders a 128 x 128 thumbnail of the page
source

pub fn text(&self) -> Result<PdfPageText<'_>, PdfiumError>

Returns the collection of text boxes contained within this PdfPage.

source

pub fn annotations(&self) -> &PdfPageAnnotations<'a>

Returns an immutable collection of the annotations that have been added to this PdfPage.

source

pub fn annotations_mut(&mut self) -> &mut PdfPageAnnotations<'a>

Returns a mutable collection of the annotations that have been added to this PdfPage.

source

pub fn boundaries(&self) -> &PdfPageBoundaries<'a>

Returns an immutable collection of the bounding boxes defining the extents of this PdfPage.

source

pub fn boundaries_mut(&mut self) -> &mut PdfPageBoundaries<'a>

Returns a mutable collection of the bounding boxes defining the extents of this PdfPage.

source

pub fn objects(&self) -> &PdfPageObjects<'a>

Returns an immutable collection of all the page objects on this PdfPage.

source

pub fn objects_mut(&mut self) -> &mut PdfPageObjects<'a>

Returns a mutable collection of all the page objects on this PdfPage.

source

pub fn fonts(&self) -> Vec<PdfFont<'_>>

Returns a list of all the distinct PdfFont instances used by the page text objects on this PdfPage, if any.

source

pub fn render(
    &self,
    width: u16,
    height: u16,
    rotation: Option<PdfBitmapRotation>
) -> Result<PdfBitmap<'_>, PdfiumError>

Renders this PdfPage into a PdfBitmap with the given pixel dimensions and page rotation.

It is the responsibility of the caller to ensure the given pixel width and height correctly maintain the page’s aspect ratio.

See also PdfPage::render_with_config(), which calculates the correct pixel dimensions, rotation settings, and rendering options to apply from a PdfRenderConfig object.

Each call to PdfPage::render() creates a new PdfBitmap object and allocates memory for it. To avoid repeated allocations, create a single PdfBitmap object using PdfBitmap::empty() and reuse it across multiple calls to PdfPage::render_into_bitmap().

source

pub fn render_with_config(
    &self,
    config: &PdfRenderConfig
) -> Result<PdfBitmap<'_>, PdfiumError>

Renders this PdfPage into a new PdfBitmap using pixel dimensions, page rotation settings, and rendering options configured in the given PdfRenderConfig.

Each call to PdfPage::render_with_config() creates a new PdfBitmap object and allocates memory for it. To avoid repeated allocations, create a single PdfBitmap object using PdfBitmap::empty() and reuse it across multiple calls to PdfPage::render_into_bitmap_with_config().

source

pub fn render_into_bitmap(
    &self,
    bitmap: &mut PdfBitmap<'_>,
    width: u16,
    height: u16,
    rotation: Option<PdfBitmapRotation>
) -> Result<(), PdfiumError>

Renders this PdfPage into the given PdfBitmap using the given the given pixel dimensions and page rotation.

It is the responsibility of the caller to ensure the given pixel width and height correctly maintain the page’s aspect ratio. The size of the buffer backing the given bitmap must be sufficiently large to hold the rendered image or an error will be returned.

See also PdfPage::render_into_bitmap_with_config(), which calculates the correct pixel dimensions, rotation settings, and rendering options to apply from a PdfRenderConfig object.

source

pub fn render_into_bitmap_with_config(
    &self,
    bitmap: &mut PdfBitmap<'_>,
    config: &PdfRenderConfig
) -> Result<(), PdfiumError>

Renders this PdfPage into the given PdfBitmap using pixel dimensions, page rotation settings, and rendering options configured in the given PdfRenderConfig.

The size of the buffer backing the given bitmap must be sufficiently large to hold the rendered image or an error will be returned.

source

pub fn flatten(&mut self) -> Result<(), PdfiumError>

Flattens all annotations and form fields on this PdfPage into the page contents.

source

pub fn content_regeneration_strategy(
    &self
) -> PdfPageContentRegenerationStrategy

Returns the strategy used by pdfium-render to regenerate the content of a PdfPage.

Updates to a PdfPage are not committed to the underlying PdfDocument until the page’s content is regenerated. If a page is reloaded or closed without regenerating the page’s content, any changes not applied are lost.

By default, pdfium-render will trigger content regeneration on any change to a PdfPage; this removes the possibility of data loss, and ensures changes can be read back from other data structures as soon as they are made. However, if many changes are made to a page at once, then regenerating the content after every change is inefficient; it is faster to stage all changes first, then regenerate the page’s content just once. In this case, changing the content regeneration strategy for a PdfPage can improve performance, but you must be careful not to forget to commit your changes before closing or reloading the page.

source

pub fn set_content_regeneration_strategy(
    &mut self,
    strategy: PdfPageContentRegenerationStrategy
)

Sets the strategy used by pdfium-render to regenerate the content of a PdfPage.

Updates to a PdfPage are not committed to the underlying PdfDocument until the page’s content is regenerated. If a page is reloaded or closed without regenerating the page’s content, any changes not applied are lost.

By default, pdfium-render will trigger content regeneration on any change to a PdfPage; this removes the possibility of data loss, and ensures changes can be read back from other data structures as soon as they are made. However, if many changes are made to a page at once, then regenerating the content after every change is inefficient; it is faster to stage all changes first, then regenerate the page’s content just once. In this case, changing the content regeneration strategy for a PdfPage can improve performance, but you must be careful not to forget to commit your changes before closing or reloading the page.

source

pub fn regenerate_content(&mut self) -> Result<(), PdfiumError>

Commits any staged but unsaved changes to this PdfPage to the underlying PdfDocument.

Updates to a PdfPage are not committed to the underlying PdfDocument until the page’s content is regenerated. If a page is reloaded or closed without regenerating the page’s content, any changes not applied are lost.

By default, pdfium-render will trigger content regeneration on any change to a PdfPage; this removes the possibility of data loss, and ensures changes can be read back from other data structures as soon as they are made. However, if many changes are made to a page at once, then regenerating the content after every change is inefficient; it is faster to stage all changes first, then regenerate the page’s content just once. In this case, changing the content regeneration strategy for a PdfPage can improve performance, but you must be careful not to forget to commit your changes before closing or reloading the page.

Trait Implementations§

source§

impl<'a> Drop for PdfPage<'a>

source§

fn drop(&mut self)

Closes this PdfPage, releasing held memory.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PdfPage<'a>

§

impl<'a> !Send for PdfPage<'a>

§

impl<'a> !Sync for PdfPage<'a>

§

impl<'a> Unpin for PdfPage<'a>

§

impl<'a> !UnwindSafe for PdfPage<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.