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)
Reference(ObjectRef)
Indirect object reference
Implementations§
Source§impl Object
impl Object
Sourcepub fn text_string(s: impl AsRef<str>) -> Self
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.
Sourcepub fn type_name(&self) -> &'static str
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.
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Try to cast to integer.
Sourcepub fn as_dict(&self) -> Option<&HashMap<String, Object>>
pub fn as_dict(&self) -> Option<&HashMap<String, Object>>
Try to cast to dictionary. Works for both Dictionary and Stream objects.
Sourcepub fn as_reference(&self) -> Option<ObjectRef>
pub fn as_reference(&self) -> Option<ObjectRef>
Try to cast to reference.
Sourcepub fn decode_stream_data(&self) -> Result<Vec<u8>>
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()?;Sourcepub 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>>
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.