pub struct PdfiumPage { /* private fields */ }Expand description
§Rust interface to FPDF_PAGE
Implementations§
Source§impl PdfiumPage
impl PdfiumPage
pub fn boundaries(&self) -> PdfiumPageBoundaries<'_>
Sourcepub fn render_at_height(
&self,
height: i32,
format: PdfiumBitmapFormat,
render_flags: PdfiumRenderFlags,
) -> PdfiumResult<PdfiumBitmap>
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 pixelsformat- The pixel format for the target bitmaprender_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(),
)
}Sourcepub fn render_at_width(
&self,
width: i32,
format: PdfiumBitmapFormat,
render_flags: PdfiumRenderFlags,
) -> PdfiumResult<PdfiumBitmap>
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 pixelsformat- The pixel format for the target bitmaprender_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(),
)
}Sourcepub fn render_with_matrix(
&self,
width: i32,
height: i32,
format: PdfiumBitmapFormat,
background: Option<PdfiumColor>,
matrix: &PdfiumMatrix,
render_flags: PdfiumRenderFlags,
clipping: Option<PdfiumRect>,
) -> PdfiumResult<PdfiumBitmap>
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 pixelsheight- The height of the target bitmap in pixelsformat- The pixel format for the target bitmapbackground- Optional background color to fill the bitmap before renderingmatrix- The transformation matrix to apply during renderingrender_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,
)
}Sourcepub fn render_into_bitmap_with_matrix(
&self,
bitmap: &mut PdfiumBitmap,
matrix: &PdfiumMatrix,
render_flags: PdfiumRenderFlags,
clipping: Option<PdfiumRect>,
)
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 intomatrix- The transformation matrix to apply during renderingrender_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
impl Drop for PdfiumPage
Source§fn drop(&mut self)
fn drop(&mut self)
§Closes this PdfiumPage, releasing held memory.
Source§impl From<&PdfiumPage> for FPDF_PAGE
impl From<&PdfiumPage> for FPDF_PAGE
Source§fn from(value: &PdfiumPage) -> Self
fn from(value: &PdfiumPage) -> Self
Auto Trait Implementations§
impl Freeze for PdfiumPage
impl RefUnwindSafe for PdfiumPage
impl !Send for PdfiumPage
impl !Sync for PdfiumPage
impl Unpin for PdfiumPage
impl UnwindSafe for PdfiumPage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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