1use crate::PdfData;
4use crate::document::page::{Page, Pages};
5use crate::object::Object;
6use crate::xref::{XRef, fallback, root_xref};
7
8pub struct Pdf {
10 xref: XRef,
11}
12
13impl Pdf {
14 pub fn new(data: PdfData) -> Option<Self> {
18 let xref = root_xref(data.clone()).or_else(|| fallback(data))?;
19
20 Some(Self { xref })
21 }
22
23 pub fn len(&self) -> usize {
25 self.xref.len()
26 }
27
28 pub fn objects(&self) -> impl IntoIterator<Item = Object> {
30 self.xref.objects()
31 }
32
33 pub fn pages(&self) -> Option<Vec<Page>> {
35 self.xref
36 .get(self.xref.trailer_data().pages_ref)
37 .and_then(|p| Pages::new(p, &self.xref).map(|p| p.pages))
38 }
39}