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 valueBoolean- true or falseInteger- Signed integersReal- Floating-point numbersString- Text or binary dataName- Atomic symbols like /TypeArray- Ordered collectionsDictionary- Key-value mapsStream- Dictionary + binary dataReference- Indirect object reference (num gen R)
§Example
use oxidize_pdf::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
impl PdfObject
Sourcepub fn parse<R: Read + Seek>(lexer: &mut Lexer<R>) -> ParseResult<Self>
pub fn parse<R: Read + Seek>(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::parser::lexer::Lexer;
use oxidize_pdf::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));Sourcepub fn parse_with_options<R: Read + Seek>(
lexer: &mut Lexer<R>,
options: &ParseOptions,
) -> ParseResult<Self>
pub fn parse_with_options<R: Read + Seek>( lexer: &mut Lexer<R>, options: &ParseOptions, ) -> ParseResult<Self>
Parse a PDF object with custom options
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Check if this object is null.
§Example
use oxidize_pdf::parser::objects::PdfObject;
assert!(PdfObject::Null.is_null());
assert!(!PdfObject::Integer(42).is_null());Sourcepub fn as_bool(&self) -> Option<bool>
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::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);Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Get as integer
Sourcepub fn as_real(&self) -> Option<f64>
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::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));Sourcepub fn as_dict(&self) -> Option<&PdfDictionary>
pub fn as_dict(&self) -> Option<&PdfDictionary>
Get as dictionary
Sourcepub fn as_reference(&self) -> Option<(u32, u16)>
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::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§
impl StructuralPartialEq for PdfObject
Auto Trait Implementations§
impl Freeze for PdfObject
impl RefUnwindSafe for PdfObject
impl Send for PdfObject
impl Sync for PdfObject
impl Unpin for PdfObject
impl UnwindSafe for PdfObject
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more