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
impl ViewerPrefs
Sourcepub fn read<R: Resolve>(catalog: &Dict, r: &R) -> ViewerPrefs
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());Sourcepub fn is_direction_r2l<R: Resolve>(&self, r: &R) -> bool
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));Sourcepub fn print_scaling<R: Resolve>(&self, r: &R) -> bool
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));Sourcepub fn num_copies<R: Resolve>(&self, r: &R) -> i64
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);Sourcepub fn print_page_range<R: Resolve>(&self, r: &R) -> Option<Array>
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());Sourcepub fn duplex<R: Resolve>(&self, r: &R) -> Vec<u8> ⓘ
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");Sourcepub fn generic_name(&self, key: &Name) -> Option<Vec<u8>>
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
impl Clone for ViewerPrefs
Source§impl Debug for ViewerPrefs
impl Debug for ViewerPrefs
Source§impl Default for ViewerPrefs
impl Default for ViewerPrefs
Source§impl PartialEq for ViewerPrefs
impl PartialEq for ViewerPrefs
impl StructuralPartialEq for ViewerPrefs
Auto Trait Implementations§
impl Freeze for ViewerPrefs
impl RefUnwindSafe for ViewerPrefs
impl Send for ViewerPrefs
impl Sync for ViewerPrefs
impl Unpin for ViewerPrefs
impl UnsafeUnpin for ViewerPrefs
impl UnwindSafe for ViewerPrefs
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