pub struct Page<'a> { /* private fields */ }Expand description
A single page of a PDF document.
Implementations§
Source§impl<'a> Page<'a>
impl<'a> Page<'a>
Sourcepub fn width(&self) -> f64
pub fn width(&self) -> f64
Page width in points (1 point = 1/72 inch).
Examples found in repository?
examples/render_page.rs (line 20)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let args: Vec<String> = std::env::args().collect();
9 if args.len() < 2 {
10 eprintln!("Usage: render_page <pdf-file> [page] [dpi] [output.png]");
11 std::process::exit(1);
12 }
13
14 let doc = Document::open(&args[1])?;
15 let page_idx: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(0);
16 let dpi: f64 = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(150.0);
17 let output = args.get(4).map(|s| s.as_str()).unwrap_or("output.png");
18
19 let page = doc.page(page_idx)?;
20 println!("Page {}: {:.0}x{:.0} pt, rotation {}", page_idx + 1, page.width(), page.height(), page.rotation());
21
22 let png = page.render_png(dpi)?;
23 std::fs::write(output, &png)?;
24 println!("Rendered to {output} ({} bytes, {dpi} DPI)", png.len());
25
26 Ok(())
27}Sourcepub fn height(&self) -> f64
pub fn height(&self) -> f64
Page height in points.
Examples found in repository?
examples/render_page.rs (line 20)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let args: Vec<String> = std::env::args().collect();
9 if args.len() < 2 {
10 eprintln!("Usage: render_page <pdf-file> [page] [dpi] [output.png]");
11 std::process::exit(1);
12 }
13
14 let doc = Document::open(&args[1])?;
15 let page_idx: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(0);
16 let dpi: f64 = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(150.0);
17 let output = args.get(4).map(|s| s.as_str()).unwrap_or("output.png");
18
19 let page = doc.page(page_idx)?;
20 println!("Page {}: {:.0}x{:.0} pt, rotation {}", page_idx + 1, page.width(), page.height(), page.rotation());
21
22 let png = page.render_png(dpi)?;
23 std::fs::write(output, &png)?;
24 println!("Rendered to {output} ({} bytes, {dpi} DPI)", png.len());
25
26 Ok(())
27}Sourcepub fn rotation(&self) -> i64
pub fn rotation(&self) -> i64
Page rotation in degrees (0, 90, 180, 270).
Examples found in repository?
examples/render_page.rs (line 20)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let args: Vec<String> = std::env::args().collect();
9 if args.len() < 2 {
10 eprintln!("Usage: render_page <pdf-file> [page] [dpi] [output.png]");
11 std::process::exit(1);
12 }
13
14 let doc = Document::open(&args[1])?;
15 let page_idx: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(0);
16 let dpi: f64 = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(150.0);
17 let output = args.get(4).map(|s| s.as_str()).unwrap_or("output.png");
18
19 let page = doc.page(page_idx)?;
20 println!("Page {}: {:.0}x{:.0} pt, rotation {}", page_idx + 1, page.width(), page.height(), page.rotation());
21
22 let png = page.render_png(dpi)?;
23 std::fs::write(output, &png)?;
24 println!("Rendered to {output} ({} bytes, {dpi} DPI)", png.len());
25
26 Ok(())
27}Sourcepub fn text(&self) -> Result<String>
pub fn text(&self) -> Result<String>
Extract text from this page as a plain string.
Examples found in repository?
examples/basic_read.rs (line 30)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let args: Vec<String> = std::env::args().collect();
9 if args.len() < 2 {
10 eprintln!("Usage: basic_read <pdf-file>");
11 std::process::exit(1);
12 }
13
14 let doc = Document::open(&args[1])?;
15
16 println!("Version: {}", doc.version_string());
17 println!("Pages: {}", doc.page_count());
18 println!("Encrypted: {}", doc.is_encrypted());
19
20 if let Some(title) = doc.title() {
21 println!("Title: {title}");
22 }
23 if let Some(author) = doc.author() {
24 println!("Author: {author}");
25 }
26
27 // Extract text from first page
28 if let Ok(page) = doc.page(0) {
29 println!("\n--- Page 1 text ---");
30 match page.text() {
31 Ok(text) => println!("{}", &text[..text.len().min(500)]),
32 Err(e) => println!("(text extraction failed: {e})"),
33 }
34 }
35
36 Ok(())
37}Sourcepub fn text_structured(&self) -> Result<PageText>
pub fn text_structured(&self) -> Result<PageText>
Extract structured text (with positions, fonts, etc.).
Sourcepub fn render_png(&self, dpi: f64) -> Result<Vec<u8>>
pub fn render_png(&self, dpi: f64) -> Result<Vec<u8>>
Render to PNG at the given DPI.
Examples found in repository?
examples/render_page.rs (line 22)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8 let args: Vec<String> = std::env::args().collect();
9 if args.len() < 2 {
10 eprintln!("Usage: render_page <pdf-file> [page] [dpi] [output.png]");
11 std::process::exit(1);
12 }
13
14 let doc = Document::open(&args[1])?;
15 let page_idx: usize = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(0);
16 let dpi: f64 = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(150.0);
17 let output = args.get(4).map(|s| s.as_str()).unwrap_or("output.png");
18
19 let page = doc.page(page_idx)?;
20 println!("Page {}: {:.0}x{:.0} pt, rotation {}", page_idx + 1, page.width(), page.height(), page.rotation());
21
22 let png = page.render_png(dpi)?;
23 std::fs::write(output, &png)?;
24 println!("Rendered to {output} ({} bytes, {dpi} DPI)", png.len());
25
26 Ok(())
27}Sourcepub fn render_jpeg(&self, dpi: f64, quality: u8) -> Result<Vec<u8>>
pub fn render_jpeg(&self, dpi: f64, quality: u8) -> Result<Vec<u8>>
Render to JPEG at the given DPI and quality (0-100).
Sourcepub fn render_svg(&self) -> Result<String>
pub fn render_svg(&self) -> Result<String>
Render to SVG.
Sourcepub fn render_raw(&self, dpi: f64) -> Result<RenderedPixmap>
pub fn render_raw(&self, dpi: f64) -> Result<RenderedPixmap>
Render to raw RGBA pixel data.
Sourcepub fn render_to_file(&self, path: impl AsRef<Path>, dpi: f64) -> Result<()>
pub fn render_to_file(&self, path: impl AsRef<Path>, dpi: f64) -> Result<()>
Render to a file (PNG format).
Sourcepub fn search_case_insensitive(&self, query: &str) -> Result<Vec<SearchResult>>
pub fn search_case_insensitive(&self, query: &str) -> Result<Vec<SearchResult>>
Search for text on this page (case-insensitive).
Auto Trait Implementations§
impl<'a> Freeze for Page<'a>
impl<'a> RefUnwindSafe for Page<'a>
impl<'a> Send for Page<'a>
impl<'a> Sync for Page<'a>
impl<'a> Unpin for Page<'a>
impl<'a> UnsafeUnpin for Page<'a>
impl<'a> UnwindSafe for Page<'a>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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