Skip to main content

ViewerPrefs

Struct ViewerPrefs 

Source
pub struct ViewerPrefs {
    pub dict: Option<Dict>,
}
Expand description

A document’s viewer preferences.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert!(prefs.is_direction_r2l(&NoResolve));
// A catalog with no `/ViewerPreferences` has no dictionary at all,
// which is not the same as an empty one.
assert!(ViewerPrefs::read(&Dict::default(), &NoResolve).dict.is_none());

Fields§

§dict: Option<Dict>

The /ViewerPreferences dictionary, absent when the catalog has none.

Implementations§

Source§

impl ViewerPrefs

Source

pub fn read<R: Resolve>(catalog: &Dict, r: &R) -> ViewerPrefs

Reads the catalog’s preferences.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert!(prefs.dict.is_some());
Source

pub fn is_direction_r2l<R: Resolve>(&self, r: &R) -> bool

Whether the reading order is right-to-left.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert!(prefs.is_direction_r2l(&NoResolve));
assert!(!ViewerPrefs::default().is_direction_r2l(&NoResolve));
Source

pub fn print_scaling<R: Resolve>(&self, r: &R) -> bool

Whether the print dialog offers page scaling. True with no dictionary.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

// True with no dictionary, and true unless the key says `None`.
assert!(prefs.print_scaling(&NoResolve));
assert!(ViewerPrefs::default().print_scaling(&NoResolve));
Source

pub fn num_copies<R: Resolve>(&self, r: &R) -> i64

The default number of copies.

One with no dictionary, zero with a dictionary that omits the key — the two paths genuinely differ.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert_eq!(prefs.num_copies(&NoResolve), 3);
// One with no dictionary; a dictionary omitting the key answers zero.
assert_eq!(ViewerPrefs::default().num_copies(&NoResolve), 1);
Source

pub fn print_page_range<R: Resolve>(&self, r: &R) -> Option<Array>

The default printed page range, as raw index pairs. Duplicates are kept.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert!(prefs.print_page_range(&NoResolve).is_none());
Source

pub fn duplex<R: Resolve>(&self, r: &R) -> Vec<u8> ⓘ

The duplex handling. None — the string — with no dictionary.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

// The *string* `None` is the default, not an absent value.
assert_eq!(prefs.duplex(&NoResolve), b"None");
Source

pub fn generic_name(&self, key: &Name) -> Option<Vec<u8>>

Any preference whose value is a name.

The type filter is the point: a Boolean /HideToolbar and an integer /NumCopies both answer nothing here even when present. Keys are case-sensitive.

use pdfrum_doc::ViewerPrefs;
use pdfrum_object::{Dict, Name, NoResolve, Object};

let catalog = Dict::from_pairs([(
    Name::from("ViewerPreferences"),
    Object::Dict(Dict::from_pairs([
        (Name::from("Direction"), Object::Name(Name::from("R2L"))),
        (Name::from("NumCopies"), Object::Int(3)),
    ])),
)]);
let prefs = ViewerPrefs::read(&catalog, &NoResolve);

assert_eq!(prefs.generic_name(&Name::from("Direction")), Some(b"R2L".to_vec()));
// Name-typed: the integer `/NumCopies` answers nothing here.
assert_eq!(prefs.generic_name(&Name::from("NumCopies")), None);

Trait Implementations§

Source§

impl Clone for ViewerPrefs

Source§

fn clone(&self) -> ViewerPrefs

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 Debug for ViewerPrefs

Source§

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

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

impl Default for ViewerPrefs

Source§

fn default() -> ViewerPrefs

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

impl PartialEq for ViewerPrefs

Source§

fn eq(&self, other: &ViewerPrefs) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ViewerPrefs

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> 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.