Struct PdfiumPage

Source
pub struct PdfiumPage { /* private fields */ }
Expand description

§Rust interface to FPDF_PAGE

Implementations§

Source§

impl PdfiumPage

Source

pub fn boundaries(&self) -> PdfiumPageBoundaries<'_>

Source

pub fn render_at_height( &self, height: i32, format: PdfiumBitmapFormat, render_flags: PdfiumRenderFlags, ) -> PdfiumResult<PdfiumBitmap>

Renders this PdfiumPage into a new PdfiumBitmap scaled to a specific height.

This is a convenience method that automatically calculates the appropriate width to maintain the page’s aspect ratio when scaling to the specified height. The page is rendered on a white background.

§Arguments
  • height - The desired height of the rendered bitmap in pixels
  • format - The pixel format for the target bitmap
  • render_flags - Flags controlling the rendering behavior
§Returns

Returns a PdfiumBitmap containing the rendered page scaled to the specified height, or a PdfiumError if rendering fails.

§Examples
use pdfium::*;

fn render_page_thumbnail(page: &PdfiumPage) -> PdfiumResult<PdfiumBitmap> {
    page.render_at_height(
        300, // 300px height thumbnail
        PdfiumBitmapFormat::Bgra,
        PdfiumRenderFlags::empty(),
    )
}
Source

pub fn render_at_width( &self, width: i32, format: PdfiumBitmapFormat, render_flags: PdfiumRenderFlags, ) -> PdfiumResult<PdfiumBitmap>

Renders this PdfiumPage into a new PdfiumBitmap scaled to a specific width.

This is a convenience method that automatically calculates the appropriate height to maintain the page’s aspect ratio when scaling to the specified width. The page is rendered on a white background.

§Arguments
  • width - The desired width of the rendered bitmap in pixels
  • format - The pixel format for the target bitmap
  • render_flags - Flags controlling the rendering behavior
§Returns

Returns a PdfiumBitmap containing the rendered page scaled to the specified width, or a PdfiumError if rendering fails.

§Examples
use pdfium::*;

fn render_page_for_display(page: &PdfiumPage) -> PdfiumResult<PdfiumBitmap> {
    page.render_at_width(
        1920, // Full HD width
        PdfiumBitmapFormat::Bgra,
        PdfiumRenderFlags::empty(),
    )
}
Source

pub fn render_with_matrix( &self, width: i32, height: i32, format: PdfiumBitmapFormat, background: Option<PdfiumColor>, matrix: &PdfiumMatrix, render_flags: PdfiumRenderFlags, clipping: Option<PdfiumRect>, ) -> PdfiumResult<PdfiumBitmap>

§Renders this PdfiumPage into a new PdfiumBitmap using a transformation matrix.

This function provides fine-grained control over the rendering process by allowing you to directly specify a transformation matrix, background color, render flags, and clipping rectangle. The transformation matrix can be used to apply scaling, rotation or translation transformations during rendering.

§Arguments
  • width - The width of the target bitmap in pixels
  • height - The height of the target bitmap in pixels
  • format - The pixel format for the target bitmap
  • background - Optional background color to fill the bitmap before rendering
  • matrix - The transformation matrix to apply during rendering
  • render_flags - Flags controlling the rendering behavior (0 for most use cases)
  • clipping - Optional clipping rectangle to restrict rendering to a specific area
§Returns

Returns a PdfiumBitmap containing the rendered page, or a PdfiumError if rendering fails.

§Examples
use pdfium::*;

fn page_to_bitmap(
    document: &PdfiumDocument,
    index: i32,
    height: i32,
) -> PdfiumResult<PdfiumBitmap> {
    let page = document.page(index)?;
    let bounds = page.boundaries().default()?;
    let scale = height as f32 / bounds.height();
    let width = (bounds.width() * scale) as i32;
    let matrix = PdfiumMatrix::new_scale(scale);
    page.render_with_matrix(
        width,
        height,
        PdfiumBitmapFormat::Bgra,
        Some(PdfiumColor::WHITE),
        &matrix,
        PdfiumRenderFlags::empty(),
        None,
    )
}
Source

pub fn render_into_bitmap_with_matrix( &self, bitmap: &mut PdfiumBitmap, matrix: &PdfiumMatrix, render_flags: PdfiumRenderFlags, clipping: Option<PdfiumRect>, )

§Renders this PdfiumPage into the given PdfiumBitmap using a transformation matrix.

This function provides fine-grained control over the rendering process by allowing you to directly specify a transformation matrix, render flags, and clipping rectangle. The transformation matrix can be used to apply scaling, rotation or translation transformations during rendering.

§Arguments
  • bitmap - The target bitmap to render into
  • matrix - The transformation matrix to apply during rendering
  • render_flags - Flags controlling the rendering behavior (0 for most use cases)
  • clipping - Optional clipping rectangle to restrict rendering to a specific area. If None, defaults to the full bitmap dimensions.
§Returns

Returns Ok(()) if rendering succeeds, or a PdfiumError if rendering fails.

Trait Implementations§

Source§

impl Drop for PdfiumPage

Source§

fn drop(&mut self)

§Closes this PdfiumPage, releasing held memory.
Source§

impl From<&PdfiumPage> for FPDF_PAGE

Source§

fn from(value: &PdfiumPage) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.