Skip to main content

Object

Enum Object 

Source
pub enum Object {
    Null,
    Boolean(bool),
    Integer(i64),
    Real(f64),
    String(Vec<u8>),
    Name(String),
    Array(Vec<Object>),
    Dictionary(HashMap<String, Object>),
    Stream {
        dict: HashMap<String, Object>,
        data: Bytes,
    },
    Reference(ObjectRef),
}
Expand description

PDF object representation.

Variants§

§

Null

Null object

§

Boolean(bool)

Boolean value

§

Integer(i64)

Integer value

§

Real(f64)

Real (floating-point) value

§

String(Vec<u8>)

String (byte array)

§

Name(String)

Name (starting with /)

§

Array(Vec<Object>)

Array of objects

§

Dictionary(HashMap<String, Object>)

Dictionary (key-value pairs)

§

Stream

Stream (dictionary + data)

Fields

§dict: HashMap<String, Object>

Stream dictionary

§data: Bytes

Stream data

§

Reference(ObjectRef)

Indirect object reference

Implementations§

Source§

impl Object

Source

pub fn text_string(s: impl AsRef<str>) -> Self

Create a PDF text string object from a Rust string.

Accepts &str, String, or any type that implements AsRef<str>. Encodes using PDFDocEncoding for characters within U+0000–U+00FF, or UTF-16BE with BOM for strings that contain characters above U+00FF.

Source

pub fn type_name(&self) -> &'static str

Get the type name of this object (without data).

Returns a human-readable type name like “String”, “Array”, “Dictionary”, etc. without including the actual data content.

Source

pub fn as_integer(&self) -> Option<i64>

Try to cast to integer.

Source

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

Try to cast to name.

Source

pub fn as_dict(&self) -> Option<&HashMap<String, Object>>

Try to cast to dictionary. Works for both Dictionary and Stream objects.

Source

pub fn as_array(&self) -> Option<&Vec<Object>>

Try to cast to array.

Source

pub fn as_reference(&self) -> Option<ObjectRef>

Try to cast to reference.

Source

pub fn as_bool(&self) -> Option<bool>

Try to cast to boolean.

Source

pub fn as_real(&self) -> Option<f64>

Try to cast to real number.

Source

pub fn as_string(&self) -> Option<&[u8]>

Try to cast to string (bytes).

Source

pub fn is_null(&self) -> bool

Check if object is null.

Source

pub fn decode_stream_data(&self) -> Result<Vec<u8>>

Decode stream data using filters specified in the stream dictionary.

This is a convenience method that calls decode_stream_data_with_decryption with no encryption parameters.

§Returns

The decoded stream data, or an error if this is not a stream object or if decoding fails.

§Examples
use xberg_native_pdf::object::Object;

let decoded_data = stream_obj.decode_stream_data()?;
Source

pub fn decode_stream_data_with_decryption( &self, decryption_fn: Option<&dyn Fn(&[u8]) -> Result<Vec<u8>>>, obj_num: u32, gen_num: u32, ) -> Result<Vec<u8>>

Decode stream data with optional decryption.

PDF Spec: Section 7.6.2 - General Encryption Algorithm states that streams must be decrypted BEFORE applying filters (decompression).

§Arguments
  • decryption_fn - Optional decryption function (from EncryptionHandler)
  • obj_num - Object number (for encryption key derivation)
  • gen_num - Generation number (for encryption key derivation)
§Returns

The decoded stream data, or an error if decoding/decryption fails.

Trait Implementations§

Source§

impl Clone for Object

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

Source§

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

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

impl PartialEq for Object

Source§

fn eq(&self, other: &Self) -> 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 Object

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more