Skip to main content

RenderOptions

Struct RenderOptions 

Source
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: f32

Output resolution. 72 dpi renders one pixel per point.

§background: bool

Paint 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: bool

Draw text. Turning it off is how a caller gets a figure’s artwork without its labels.

§draw_paths: bool§draw_images: bool

Implementations§

Source§

impl RenderOptions

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RenderOptions

Source§

impl Debug for RenderOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RenderOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.