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_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
impl PdfObject
Sourcepub fn parse<R: Read>(lexer: &mut Lexer<R>) -> ParseResult<Self>
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));Sourcepub fn is_null(&self) -> bool
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());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_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);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_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));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_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);
}