Skip to main content

ObjectStore

Struct ObjectStore 

Source
pub struct ObjectStore<S: PdfSource = Arc<[u8]>> { /* private fields */ }
Expand description

The central PDF object store with thread-safe lazy parsing.

Generic over the source data type via PdfSource.

Implementations§

Source§

impl<S: PdfSource> ObjectStore<S>

Source

pub fn open(source: S, mode: ParsingMode) -> Result<Self, PdfError>

Open a PDF source, parsing the header, xref table, and trailer.

This constructs the ObjectStore with all object slots ready for lazy parsing on demand. For encrypted PDFs, use Self::open_with_password.

Source

pub fn open_with_password( source: S, mode: ParsingMode, password: Option<&str>, ) -> Result<Self, PdfError>

Open a PDF source, optionally providing a password for encrypted documents.

After parsing the header, xref, and trailer, if the trailer contains an /Encrypt entry, the encryption dictionary is resolved and a SecurityHandler is created. The password is verified against both user and owner password hashes.

Source

pub fn resolve(&self, id: ObjectId) -> Result<&Object, PdfError>

Resolve an indirect object by its ID. Returns a reference to the lazily-parsed object.

Source

pub fn deep_resolve<'a>( &'a self, obj: &'a Object, ) -> Result<&'a Object, PdfError>

Follow a reference chain to the concrete object.

Uses an iterative loop with circular reference detection via SmallVec. Never recurses on the call stack.

Source

pub fn dict_resolve<'a>( &'a self, dict: &'a HashMap<Name, Object>, key: &Name, ) -> Result<Option<&'a Object>, PdfError>

Resolve a dictionary value by key, following references.

Source

pub fn decode_stream(&self, stream: &Object) -> Result<Vec<u8>, PdfError>

Decode stream data on demand using the filter chain from the stream dictionary.

Resolves /Filter and /DecodeParms from the stream dictionary, then applies the codec pipeline via rpdfium_codec::apply_filter_chain.

Source

pub fn parsing_mode(&self) -> ParsingMode

Get the parsing mode.

Source

pub fn trailer(&self) -> &TrailerInfo

Get the trailer info.

Source

pub fn get_trailer(&self) -> &TrailerInfo

ADR-019 alias for trailer().

Corresponds to CPDF_Parser::GetTrailer() in PDFium.

Source

pub fn file_version(&self) -> PdfVersion

Get the PDF version from the header.

Corresponds to CPDF_Parser::GetFileVersion() in PDFium.

Source

pub fn get_file_version(&self) -> PdfVersion

ADR-019 alias for file_version().

Corresponds to CPDF_Parser::GetFileVersion() in PDFium.

Source

pub fn version(&self) -> PdfVersion

👎Deprecated since 0.0.0:

use file_version() or get_file_version()

Rust-idiomatic alias for file_version().

Source

pub fn xref(&self) -> &XrefTable

Get the cross-reference table.

Source

pub fn object_count(&self) -> usize

Get the number of object slots.

Source

pub fn contains(&self, id: ObjectId) -> bool

Check if an object ID exists in the store.

Source

pub fn object_ids(&self) -> impl Iterator<Item = &ObjectId>

Get all known object IDs.

Source

pub fn security_handler(&self) -> Option<&SecurityHandler>

Returns a reference to the security handler, if the document is encrypted.

Source

pub fn get_security_handler(&self) -> Option<&SecurityHandler>

ADR-019 alias for security_handler().

Corresponds to CPDF_Parser::GetSecurityHandler() in PDFium.

Source

pub fn permissions(&self) -> Option<Permissions>

Returns the document access permissions, if the document is encrypted.

Delegates to SecurityHandler::permissions(). Returns None for unencrypted documents (all permissions implicitly granted).

Corresponds to CPDF_Parser::GetPermissions() in PDFium.

Source

pub fn get_permissions(&self) -> Option<Permissions>

ADR-019 alias for permissions().

Corresponds to CPDF_Parser::GetPermissions() in PDFium.

Source

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

Returns the encoded password bytes used during authentication, if the document is encrypted.

Delegates to SecurityHandler::encoded_password(). Returns None for unencrypted documents.

Corresponds to CPDF_Parser::GetEncodedPassword() in PDFium.

Source

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

ADR-019 alias for encoded_password().

Corresponds to CPDF_Parser::GetEncodedPassword() in PDFium.

Source

pub fn xref_table_rebuilt(&self) -> bool

Returns true if the cross-reference table was rebuilt (Lenient mode recovery).

When true, the original xref table could not be parsed and the parser fell back to a linear scan for N G obj markers.

Corresponds to CPDF_Parser::IsXRefTableRebuilt() in PDFium.

Source

pub fn is_xref_table_rebuilt(&self) -> bool

ADR-019 alias for xref_table_rebuilt().

Corresponds to CPDF_Parser::IsXRefTableRebuilt() in PDFium.

Source

pub fn xref_rebuilt(&self) -> bool

👎Deprecated since 0.0.0:

use xref_table_rebuilt() or is_xref_table_rebuilt()

Abbreviated alias for xref_table_rebuilt().

Source

pub fn is_xref_stream(&self) -> bool

Returns true if the newest cross-reference section is an xref stream (PDF 1.5+ compressed xref), false if it is a traditional xref table.

Corresponds to CPDF_Parser::IsXRefStream() in PDFium.

Source

pub fn object_position_or_zero(&self, id: ObjectId) -> Option<u64>

Returns the byte offset of the given object in the source data, if the object is a direct (non-stream) object. Returns None for objects embedded in object streams (ObjStm).

Corresponds to CPDF_Parser::GetObjectPositionOrZero() in PDFium.

Source

pub fn get_object_position_or_zero(&self, id: ObjectId) -> Option<u64>

ADR-019 alias for object_position_or_zero().

Corresponds to CPDF_Parser::GetObjectPositionOrZero() in PDFium.

Source

pub fn object_offset(&self, id: ObjectId) -> Option<u64>

👎Deprecated since 0.0.0:

use object_position_or_zero() or get_object_position_or_zero()

Rust-idiomatic alias for object_position_or_zero().

Source

pub fn source_data(&self) -> &S

Returns a reference to the raw source data.

Source

pub fn last_obj_num(&self) -> u32

Returns the maximum object number in the store.

Corresponds to CPDF_Parser::GetLastObjNum() in PDFium.

Source

pub fn get_last_obj_num(&self) -> u32

ADR-019 alias for last_obj_num().

Corresponds to CPDF_Parser::GetLastObjNum() in PDFium.

Source

pub fn max_object_number(&self) -> u32

👎Deprecated since 0.0.0:

use last_obj_num() or get_last_obj_num()

Rust-idiomatic alias for last_obj_num().

Source

pub fn last_xref_offset(&self) -> u64

Returns the byte offset of the last startxref value.

This is needed for incremental saves to set the /Prev trailer key.

Corresponds to CPDF_Parser::GetLastXRefOffset() in PDFium.

Source

pub fn xref_start_offset(&self) -> u64

👎Deprecated since 0.0.0:

use last_xref_offset() or get_last_xref_offset()

Rust-idiomatic alias for last_xref_offset().

Source

pub fn is_valid_object_number(&self, number: u32) -> bool

Returns true if the given object number exists in the cross-reference table (i.e. is a valid, non-free indirect object).

Corresponds to CPDF_Parser::IsValidObjectNumber() in PDFium.

Source

pub fn get_last_xref_offset(&self) -> u64

ADR-019 alias for last_xref_offset().

Corresponds to CPDF_Parser::GetLastXRefOffset() in PDFium.

Source

pub fn is_object_free(&self, number: u32) -> bool

Returns true if the given object number is marked free or null (i.e. does not exist as an in-use object in the store).

Corresponds to CPDF_Parser::IsObjectFreeOrNull() in PDFium.

Source

pub fn is_object_free_or_null(&self, number: u32) -> bool

ADR-019 alias for is_object_free().

Corresponds to CPDF_Parser::IsObjectFreeOrNull() in PDFium.

Source

pub fn document_size(&self) -> usize

Returns the total size of the source document in bytes.

Corresponds to CPDF_Parser::GetDocumentSize() in PDFium.

Source

pub fn get_document_size(&self) -> usize

ADR-019 alias for document_size().

Corresponds to CPDF_Parser::GetDocumentSize() in PDFium.

Source

pub fn decode_stream_for_object( &self, stream: &Object, obj_id: ObjectId, ) -> Result<Vec<u8>, PdfError>

Decode stream data for a specific object, applying decryption if needed.

Like Self::decode_stream, but also decrypts the raw stream data before applying the filter chain when the document is encrypted.

Source

pub fn raw_stream_bytes_for_object( &self, stream: &Object, obj_id: ObjectId, ) -> Result<Vec<u8>, PdfError>

Return the raw (optionally decrypted) stream bytes without applying any filter chain. This is useful when the caller needs to handle a specific filter (like JPXDecode) specially to extract metadata.

Source

pub fn decrypt_string(&self, data: &[u8], obj_id: ObjectId) -> Vec<u8>

Decrypt a string value from an encrypted document.

If the document is not encrypted, returns the input bytes unchanged.

Auto Trait Implementations§

§

impl<S> Freeze for ObjectStore<S>
where S: Freeze,

§

impl<S = Arc<[u8]>> !RefUnwindSafe for ObjectStore<S>

§

impl<S> Send for ObjectStore<S>

§

impl<S> Sync for ObjectStore<S>

§

impl<S> Unpin for ObjectStore<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for ObjectStore<S>
where S: UnsafeUnpin,

§

impl<S = Arc<[u8]>> !UnwindSafe for ObjectStore<S>

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.
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