Struct 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 bindings(&self) -> &'a dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings used by 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<PdfPageRenderRotation, 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: PdfPageRenderRotation)

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.

Returns an immutable collection of the links on this PdfPage.

Returns a mutable collection of the links on 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 pixels_to_points( &self, x: Pixels, y: Pixels, config: &PdfRenderConfig, ) -> Result<(PdfPoints, PdfPoints), PdfiumError>

Converts from a bitmap coordinate system, measured in Pixels and with constraints and dimensions determined by the given PdfRenderConfig object, to the equivalent position on this page, measured in PdfPoints.

Source

pub fn points_to_pixels( &self, x: PdfPoints, y: PdfPoints, config: &PdfRenderConfig, ) -> Result<(Pixels, Pixels), PdfiumError>

Converts from the page coordinate system, measured in PdfPoints, to the equivalent position in a bitmap coordinate system measured in Pixels and with constraints and dimensions defined by the given PdfRenderConfig object.

Source

pub fn render( &self, width: Pixels, height: Pixels, rotation: Option<PdfPageRenderRotation>, ) -> 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: Pixels, height: Pixels, rotation: Option<PdfPageRenderRotation>, ) -> Result<(), PdfiumError>

Renders this PdfPage into the given PdfBitmap using 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 transform_with_clip( &mut self, a: PdfMatrixValue, b: PdfMatrixValue, c: PdfMatrixValue, d: PdfMatrixValue, e: PdfMatrixValue, f: PdfMatrixValue, clip: PdfRect, ) -> Result<(), PdfiumError>

Applies the given transformation, expressed as six values representing the six configurable elements of a nine-element 3x3 PDF transformation matrix, to the objects on this PdfPage, restricting the effects of the transformation to the given clipping rectangle.

To move, scale, rotate, or skew the objects on this PdfPage, consider using one or more of the following functions. Internally they all use PdfPage::transform(), but are probably easier to use (and certainly clearer in their intent) in most situations.

The order in which transformations are applied is significant. For example, the result of rotating then translating an object may be vastly different from translating then rotating the same object.

An overview of PDF transformation matrices can be found in the PDF Reference Manual version 1.7 on page 204; a detailed description can be found in section 4.2.3 on page 207.

Source

pub fn apply_matrix_with_clip( &mut self, matrix: PdfMatrix, clip: PdfRect, ) -> Result<(), PdfiumError>

Applies the given transformation, expressed as a PdfMatrix, to this PdfPage, restricting the effects of the transformation matrix to the given clipping rectangle.

Source

pub fn transform( &mut self, a: PdfMatrixValue, b: PdfMatrixValue, c: PdfMatrixValue, d: PdfMatrixValue, e: PdfMatrixValue, f: PdfMatrixValue, ) -> Result<(), PdfiumError>

Applies the given transformation, expressed as six values representing the six configurable elements of a nine-element 3x3 PDF transformation matrix, to each object on this PdfPage.

To move, scale, rotate, or skew each object on this PdfPage, consider using one or more of the following functions. Internally they all use Self::transform(), but are probably easier to use (and certainly clearer in their intent) in most situations.

The order in which transformations are applied is significant. For example, the result of rotating then translating an object may be vastly different from translating then rotating the same object.

An overview of PDF transformation matrices can be found in the PDF Reference Manual version 1.7 on page 204; a detailed description can be found in section 4.2.3 on page 207.

Source

pub fn apply_matrix(&mut self, matrix: PdfMatrix) -> Result<(), PdfiumError>

Applies the given transformation, expressed as a PdfMatrix, to each object on this PdfPage.

Source

pub fn translate( &mut self, delta_x: PdfPoints, delta_y: PdfPoints, ) -> Result<(), PdfiumError>

Moves the origin of each object on this PdfPage by the given horizontal and vertical delta distances.

Source

pub fn scale( &mut self, horizontal_scale_factor: PdfMatrixValue, vertical_scale_factor: PdfMatrixValue, ) -> Result<(), PdfiumError>

Changes the size of each object on this PdfPage, scaling it by the given horizontal and vertical scale factors.

Source

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

Flips each object on this PdfPage horizontally around its origin by applying a horizontal scale factor of -1.

Source

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

Flips each object on this PdfPage vertically around its origin by applying a vertical scale factor of -1.

Source

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

Reflects each object on this PdfPage by flipping it both horizontally and vertically around its origin.

Source

pub fn rotate_counter_clockwise_degrees( &mut self, degrees: PdfMatrixValue, ) -> Result<(), PdfiumError>

Rotates each object on this PdfPage counter-clockwise by the given number of degrees.

Source

pub fn rotate_clockwise_degrees( &mut self, degrees: PdfMatrixValue, ) -> Result<(), PdfiumError>

Rotates each object on this PdfPage clockwise by the given number of degrees.

Source

pub fn rotate_counter_clockwise_radians( &mut self, radians: PdfMatrixValue, ) -> Result<(), PdfiumError>

Rotates each object on this PdfPage counter-clockwise by the given number of radians.

Source

pub fn rotate_clockwise_radians( &mut self, radians: PdfMatrixValue, ) -> Result<(), PdfiumError>

Rotates each object on this PdfPage clockwise by the given number of radians.

Source

pub fn skew_degrees( &mut self, x_axis_skew: PdfMatrixValue, y_axis_skew: PdfMatrixValue, ) -> Result<(), PdfiumError>

Skews the axes of each object on this PdfPage by the given angles in degrees.

Source

pub fn skew_radians( &mut self, x_axis_skew: PdfMatrixValue, y_axis_skew: PdfMatrixValue, ) -> Result<(), PdfiumError>

Skews the axes of each object on this PdfPage by the given angles in radians.

Source

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

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

Source

pub fn delete(self) -> Result<(), PdfiumError>

Deletes this PdfPage from its containing PdfPages collection, consuming this PdfPage.

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, all uncommitted changes will be 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, all uncommitted changes will be 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, all uncommitted changes will be 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> Freeze for PdfPage<'a>

§

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 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, 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.