pub struct RenderOptions {
pub dpi: f32,
pub background: bool,
pub draw_text: bool,
pub draw_paths: bool,
pub draw_images: bool,
}Expand description
Options for a render.
Fields§
§dpi: f32Output resolution. 72 dpi renders one pixel per point.
background: boolPaint an opaque white background first. A PDF page is defined as white paper; leaving it transparent makes text unreadable in any viewer that composites onto dark.
draw_text: boolDraw text. Turning it off is how a caller gets a figure’s artwork without its labels.
draw_paths: bool§draw_images: boolImplementations§
Source§impl RenderOptions
impl RenderOptions
Sourcepub fn at_dpi(dpi: f32) -> Self
pub fn at_dpi(dpi: f32) -> Self
Examples found in repository?
examples/render.rs (line 17)
3fn main() {
4 let mut args = std::env::args().skip(1);
5 let Some(path) = args.next() else {
6 eprintln!("usage: render <file.pdf> [page] [dpi] [out.png]");
7 std::process::exit(2);
8 };
9 let index: usize = args.next().and_then(|s| s.parse().ok()).unwrap_or(0);
10 let dpi: f32 = args.next().and_then(|s| s.parse().ok()).unwrap_or(150.0);
11 let out = args.next().unwrap_or_else(|| "page.png".into());
12
13 let doc = rustium_pdf::Document::open(&path).expect("open");
14 let page = doc.page(index).expect("page");
15 let started = std::time::Instant::now();
16 let image = page
17 .render(&doc, rustium_pdf::RenderOptions::at_dpi(dpi))
18 .expect("render");
19 let elapsed = started.elapsed();
20
21 std::fs::write(&out, image.to_png().expect("encode")).expect("write");
22 println!(
23 "{out}: {}x{} at {dpi}dpi in {:.0}ms ({} glyphs, {} paths, {} images)",
24 image.width,
25 image.height,
26 elapsed.as_secs_f32() * 1000.0,
27 page.glyphs.len(),
28 page.paths.len(),
29 page.images.len()
30 );
31}Trait Implementations§
Source§impl Clone for RenderOptions
impl Clone for RenderOptions
impl Copy for RenderOptions
Source§impl Debug for RenderOptions
impl Debug for RenderOptions
Auto Trait Implementations§
impl Forget for RenderOptions
impl Freeze for RenderOptions
impl Move for RenderOptions
impl RefUnwindSafe for RenderOptions
impl Send for RenderOptions
impl Sync for RenderOptions
impl Unpin for RenderOptions
impl UnsafeUnpin for RenderOptions
impl UnwindSafe for RenderOptions
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