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
- Offset from MediaBox origin
- Apply rotation (0°/90°/180°/270° clockwise)
- Offset by CropBox position (in rotated space)
- 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
impl PageGeometry
Sourcepub fn new(media_box: BBox, crop_box: Option<BBox>, rotation: i32) -> Self
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 aBBox. 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). IfNone, MediaBox is used as the visible viewport.rotation- Page/Rotatevalue. Normalized to 0, 90, 180, or 270.
Sourcepub fn normalize_point(&self, x: f64, y: f64) -> (f64, f64)
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.
Sourcepub fn normalize_bbox(
&self,
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) -> BBox
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§
impl Freeze for PageGeometry
impl RefUnwindSafe for PageGeometry
impl Send for PageGeometry
impl Sync for PageGeometry
impl Unpin for PageGeometry
impl UnsafeUnpin for PageGeometry
impl UnwindSafe for PageGeometry
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
Mutably borrows from an owned value. Read more