Enum PdfObject

Source
pub enum PdfObject {
    Null,
    Boolean(bool),
    Integer(i64),
    Real(f64),
    String(PdfString),
    Name(PdfName),
    Array(PdfArray),
    Dictionary(PdfDictionary),
    Stream(PdfStream),
    Reference(u32, u16),
}
Expand description

PDF Object types - The fundamental data types in PDF.

All data in a PDF file is represented using these basic types. Objects can be direct (embedded) or indirect (referenced).

§Object Types

  • Null - Undefined/absent value
  • Boolean - true or false
  • Integer - Signed integers
  • Real - Floating-point numbers
  • String - Text or binary data
  • Name - Atomic symbols like /Type
  • Array - Ordered collections
  • Dictionary - Key-value maps
  • Stream - Dictionary + binary data
  • Reference - Indirect object reference (num gen R)

§Example

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

// Different object types
let null = PdfObject::Null;
let bool_val = PdfObject::Boolean(true);
let int_val = PdfObject::Integer(42);
let real_val = PdfObject::Real(3.14159);
let name = PdfObject::Name(PdfName::new("Type".to_string()));
let reference = PdfObject::Reference(10, 0); // 10 0 R

// Type checking
assert!(int_val.as_integer().is_some());
assert_eq!(int_val.as_integer(), Some(42));

Variants§

§

Null

Null object - represents undefined or absent values

§

Boolean(bool)

Boolean value - true or false

§

Integer(i64)

Integer number

§

Real(f64)

Real (floating-point) number

§

String(PdfString)

String data (literal or hexadecimal)

§

Name(PdfName)

Name object - unique identifier

§

Array(PdfArray)

Array - ordered collection of objects

§

Dictionary(PdfDictionary)

Dictionary - unordered key-value pairs

§

Stream(PdfStream)

Stream - dictionary with binary data

§

Reference(u32, u16)

Indirect object reference (object_number, generation_number)

Implementations§

Source§

impl PdfObject

Source

pub fn parse<R: Read>(lexer: &mut Lexer<R>) -> ParseResult<Self>

Parse a PDF object from a lexer.

Reads tokens from the lexer and constructs the appropriate PDF object. Handles all PDF object types including indirect references.

§Arguments
  • lexer - Token source for parsing
§Returns

The parsed PDF object.

§Errors

Returns an error if:

  • Invalid syntax is encountered
  • Unexpected end of input
  • Malformed object structure
§Example
use oxidize_pdf_core::parser::lexer::Lexer;
use oxidize_pdf_core::parser::objects::PdfObject;
use std::io::Cursor;

let input = b"42";
let mut lexer = Lexer::new(Cursor::new(input));
let obj = PdfObject::parse(&mut lexer)?;
assert_eq!(obj, PdfObject::Integer(42));
Source

pub fn is_null(&self) -> bool

Check if this object is null.

§Example
use oxidize_pdf_core::parser::objects::PdfObject;

assert!(PdfObject::Null.is_null());
assert!(!PdfObject::Integer(42).is_null());
Source

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

Get the value as a boolean if this is a Boolean object.

§Returns

Some(bool) if this is a Boolean object, None otherwise.

§Example
use oxidize_pdf_core::parser::objects::PdfObject;

let obj = PdfObject::Boolean(true);
assert_eq!(obj.as_bool(), Some(true));

let obj = PdfObject::Integer(1);
assert_eq!(obj.as_bool(), None);
Source

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

Get as integer

Source

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

Get the value as a real number.

Returns the value for both Real and Integer objects, converting integers to floating-point.

§Returns

Some(f64) if this is a numeric object, None otherwise.

§Example
use oxidize_pdf_core::parser::objects::PdfObject;

let real_obj = PdfObject::Real(3.14);
assert_eq!(real_obj.as_real(), Some(3.14));

let int_obj = PdfObject::Integer(42);
assert_eq!(int_obj.as_real(), Some(42.0));
Source

pub fn as_string(&self) -> Option<&PdfString>

Get as string

Source

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

Get as name

Source

pub fn as_array(&self) -> Option<&PdfArray>

Get as array

Source

pub fn as_dict(&self) -> Option<&PdfDictionary>

Get as dictionary

Source

pub fn as_stream(&self) -> Option<&PdfStream>

Get as stream

Source

pub fn as_reference(&self) -> Option<(u32, u16)>

Get the object reference if this is a Reference object.

§Returns

Some((object_number, generation_number)) if this is a Reference, None otherwise.

§Example
use oxidize_pdf_core::parser::objects::PdfObject;

let obj = PdfObject::Reference(10, 0);
assert_eq!(obj.as_reference(), Some((10, 0)));

// Use for resolving references
if let Some((obj_num, gen_num)) = obj.as_reference() {
    println!("Reference to {} {} R", obj_num, gen_num);
}

Trait Implementations§

Source§

impl Clone for PdfObject

Source§

fn clone(&self) -> PdfObject

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 PdfObject

Source§

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

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

impl PartialEq for PdfObject

Source§

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

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.