Struct PdfDictionary

Source
pub struct PdfDictionary(pub HashMap<PdfName, PdfObject>);
Expand description

PDF Dictionary object - Key-value mapping with name keys.

Dictionaries are the primary way to represent complex data structures in PDF. Keys must be PdfName objects, values can be any PDF object type.

§Common Dictionary Types

  • Catalog: Document root (/Type /Catalog)
  • Page: Individual page (/Type /Page)
  • Font: Font definition (/Type /Font)
  • Stream: Binary data with metadata

§Example

use oxidize_pdf_core::parser::objects::{PdfDictionary, PdfObject, PdfName};

let mut page_dict = PdfDictionary::new();
page_dict.insert("Type".to_string(), 
    PdfObject::Name(PdfName::new("Page".to_string())));
page_dict.insert("Parent".to_string(), 
    PdfObject::Reference(2, 0)); // Reference to pages tree

// Access values
assert_eq!(page_dict.get_type(), Some("Page"));
assert!(page_dict.contains_key("Parent"));

Tuple Fields§

§0: HashMap<PdfName, PdfObject>

Implementations§

Source§

impl PdfDictionary

Source

pub fn new() -> Self

Create a new empty dictionary.

§Example
use oxidize_pdf_core::parser::objects::{PdfDictionary, PdfObject, PdfName};

let mut dict = PdfDictionary::new();
dict.insert("Type".to_string(), PdfObject::Name(PdfName::new("Font".to_string())));
Source

pub fn get(&self, key: &str) -> Option<&PdfObject>

Get a value by key name.

§Arguments
  • key - The key name (without leading slash)
§Returns

Reference to the value if the key exists, None otherwise.

§Example
use oxidize_pdf_core::parser::objects::{PdfDictionary, PdfObject};

let mut dict = PdfDictionary::new();
dict.insert("Length".to_string(), PdfObject::Integer(1000));

if let Some(length) = dict.get("Length").and_then(|o| o.as_integer()) {
    println!("Stream length: {}", length);
}
Source

pub fn insert(&mut self, key: String, value: PdfObject)

Insert a key-value pair

Source

pub fn contains_key(&self, key: &str) -> bool

Check if dictionary contains a key

Source

pub fn get_type(&self) -> Option<&str>

Get the dictionary type (value of /Type key).

Many PDF dictionaries have a /Type entry that identifies their purpose.

§Returns

The type name if present, None otherwise.

§Common Types
  • “Catalog” - Document catalog
  • “Page” - Page object
  • “Pages” - Page tree node
  • “Font” - Font dictionary
  • “XObject” - External object
§Example
use oxidize_pdf_core::parser::objects::{PdfDictionary, PdfObject, PdfName};

let mut dict = PdfDictionary::new();
dict.insert("Type".to_string(), PdfObject::Name(PdfName::new("Page".to_string())));
assert_eq!(dict.get_type(), Some("Page"));

Trait Implementations§

Source§

impl Clone for PdfDictionary

Source§

fn clone(&self) -> PdfDictionary

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PdfDictionary

Source§

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

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

impl Default for PdfDictionary

Source§

fn default() -> Self

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

impl PartialEq for PdfDictionary

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PdfDictionary

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.