Skip to main content

PageGeometry

Struct PageGeometry 

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

Page coordinate normalization configuration.

Combines MediaBox, optional CropBox, and page rotation to provide a unified transform from PDF native space to top-left origin user-visible space.

§Coordinate Transform Pipeline

  1. Offset from MediaBox origin
  2. Apply rotation (0°/90°/180°/270° clockwise)
  3. Offset by CropBox position (in rotated space)
  4. Y-flip (bottom-left → top-left origin)

§Example

use pdfplumber_core::geometry::BBox;
use pdfplumber_parse::page_geometry::PageGeometry;

// US Letter page, no crop, no rotation
let media_box = BBox::new(0.0, 0.0, 612.0, 792.0);
let geo = PageGeometry::new(media_box, None, 0);

assert_eq!(geo.width(), 612.0);
assert_eq!(geo.height(), 792.0);

// Point near top in PDF space (y=720) → near top in display (y=72)
let (x, y) = geo.normalize_point(72.0, 720.0);
assert!((x - 72.0).abs() < 0.01);
assert!((y - 72.0).abs() < 0.01);

Implementations§

Source§

impl PageGeometry

Source

pub fn new(media_box: BBox, crop_box: Option<BBox>, rotation: i32) -> Self

Create a new PageGeometry from page metadata.

§Arguments
  • media_box - Page MediaBox as raw PDF coordinates in a BBox. The BBox fields map to PDF array values: x0 = left, top = y-min (PDF bottom), x1 = right, bottom = y-max (PDF top).
  • crop_box - Optional CropBox (same coordinate convention as MediaBox). If None, MediaBox is used as the visible viewport.
  • rotation - Page /Rotate value. Normalized to 0, 90, 180, or 270.
Source

pub fn width(&self) -> f64

Visible page width after rotation and cropping.

Source

pub fn height(&self) -> f64

Visible page height after rotation and cropping.

Source

pub fn rotation(&self) -> i32

Page rotation in degrees (normalized to 0, 90, 180, or 270).

Source

pub fn normalize_point(&self, x: f64, y: f64) -> (f64, f64)

Transform a point from PDF native space to top-left origin display space.

Applies: MediaBox offset → rotation → CropBox offset → y-flip.

Source

pub fn normalize_bbox( &self, min_x: f64, min_y: f64, max_x: f64, max_y: f64, ) -> BBox

Transform a bounding box from PDF native space to top-left origin display space.

Takes min/max corners in native PDF coordinates and returns a BBox in display space with top-left origin. Corners are re-normalized after transformation since rotation may swap min/max.

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> Same for T

Source§

type Output = T

Should always be Self
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.