pub struct Page {
pub index: usize,
pub media_box: Rect,
pub crop_box: Rect,
pub bleed_box: Rect,
pub trim_box: Rect,
pub art_box: Rect,
pub rotate: i32,
pub resources: Dict,
/* private fields */
}Expand description
A single page with inherited attributes already applied.
Defaults: media_box falls back to US Letter (612x792) when absent or
invalid, crop_box falls back to (and is intersected with) media_box,
bleed_box, trim_box and art_box fall back to crop_box (and are
clipped to media_box) per ISO 32000 §14.11.2, and rotate is
normalized to one of {0, 90, 180, 270}. Every construction path
normalizes rotate — Document::page and Page::from_parts alike —
so the invariant holds however a Page was built. rotate is a public
field, so a caller may still overwrite it afterwards; Page::size
reads it modulo a full turn and so stays correct if they do.
All five boxes are in unrotated PDF user space: Page::size swaps
width and height under a quarter-turn /Rotate, the boxes never do.
Fields§
§index: usize0-based page index.
media_box: Rect§crop_box: Rect§bleed_box: Rect§trim_box: Rect§art_box: Rect§rotate: i32§resources: DictThe page’s (inherited) /Resources dictionary.
Implementations§
Source§impl Page
impl Page
Sourcepub const US_LETTER: Rect
pub const US_LETTER: Rect
The default media box for a page that declares none: US Letter (612 by 792 points). Public because the default is part of the observable contract — a caller comparing two APIs’ pages needs to know which rectangle “the file said nothing” maps to.
Sourcepub fn from_parts(
index: usize,
media_box: Rect,
crop_box: Rect,
rotate: i32,
resources: Dict,
dict: Dict,
obj_ref: Option<ObjRef>,
) -> Page
pub fn from_parts( index: usize, media_box: Rect, crop_box: Rect, rotate: i32, resources: Dict, dict: Dict, obj_ref: Option<ObjRef>, ) -> Page
Builds a page from already-resolved attributes.
Document::page resolves page-tree inheritance itself; this is for
a caller that has done that resolution some other way — notably the
asynchronous API, which flattens the page tree while reading it — and
needs the same Page type back.
rotate is normalized here to one of {0, 90, 180, 270} exactly as
Document::page normalizes it, so a caller may pass a raw /Rotate
straight through: a negative or over-a-full-turn multiple of 90 is
reduced, and a value that is not a multiple of 90 falls back to 0
(lenient). The caller does not have to pre-normalize, and the Page
invariant holds whichever constructor built it.
bleed_box, trim_box and art_box are set to crop_box — their
ISO 32000 §14.11.2 default. A caller that resolved real values
overwrites the public fields afterwards.
Sourcepub fn from_tree_attrs(
index: usize,
resources: Option<Dict>,
media_box: Option<Rect>,
crop_box: Option<Rect>,
bleed_box: Option<Rect>,
trim_box: Option<Rect>,
art_box: Option<Rect>,
rotate: Option<i32>,
dict: Dict,
obj_ref: Option<ObjRef>,
) -> Page
pub fn from_tree_attrs( index: usize, resources: Option<Dict>, media_box: Option<Rect>, crop_box: Option<Rect>, bleed_box: Option<Rect>, trim_box: Option<Rect>, art_box: Option<Rect>, rotate: Option<i32>, dict: Dict, obj_ref: Option<ObjRef>, ) -> Page
Builds a page from raw, possibly missing page-tree attributes,
applying the same defaults Document::page applies (ISO 32000
§7.7.3.3, §14.11.2): a missing or degenerate /MediaBox reads as
Page::US_LETTER, /CropBox clips to the media box and falls back
to it, /BleedBox, /TrimBox and /ArtBox clip to the media box
and fall back to the crop box, a missing /Rotate reads as 0 and is
normalized, and missing /Resources read as empty.
This is the one implementation of page defaulting. The synchronous
tree walk routes through it, and a caller that resolved inheritance
some other way — notably the asynchronous API, which flattens the
page tree while reading it — gets the identical Page back, so the
two APIs cannot disagree about what an attribute-less page looks
like.
Sourcepub fn object_ref(&self) -> Option<ObjRef>
pub fn object_ref(&self) -> Option<ObjRef>
The page’s indirect object reference, when the page came from an
indirect kid in the page tree (pages inlined directly into a /Kids
array have none).
Sourcepub fn content(&self, doc: &Document) -> Result<Vec<u8>>
pub fn content(&self, doc: &Document) -> Result<Vec<u8>>
The page’s decoded content: the /Contents stream, or all streams
of a /Contents array decoded and joined with b"\n". A missing
/Contents yields empty content (lenient).
This drives page_content_with to completion on the calling thread.
There is one implementation of the algorithm, so this and the
asynchronous API cannot drift apart in what they consider a page’s
content to be.
Sourcepub fn size(&self) -> (f32, f32)
pub fn size(&self) -> (f32, f32)
Crop-box width and height, swapped when /Rotate is a quarter turn.
Both constructors normalize rotate, but the field is public and so
can be overwritten with a raw /Rotate; the rotation is therefore read
modulo a full turn rather than compared against 90 and 270 exactly, so
that -90 and 450 swap the dimensions just as 270 and 90 do. For an
already-normalized value this is the same test as before: 0, 90, 180
and 270 are unchanged by rem_euclid(360).