Skip to main content

AsyncDocument

Struct AsyncDocument 

Source
pub struct AsyncDocument { /* private fields */ }
Expand description

A PDF document over an async random-access backend. The whole file is never read: opening fetches only the tail, the xref chain and the page tree; objects are fetched span-by-span on demand.

Cloning is cheap (a shared handle); every method takes &self, so one instance can serve many tasks concurrently.

Implementations§

Source§

impl AsyncDocument

Source

pub async fn open(path: impl AsRef<Path>) -> Result<AsyncDocument>

Opens a file through a FileBackend wrapped in a CachedBackend with default capacity.

Files encrypted with the Standard security handler under the empty user password are decrypted transparently, exactly as the synchronous document decrypts them; a file that requires a real password is rejected with pdfboss_core::Error::Encrypted.

Source

pub async fn open_with_password( path: impl AsRef<Path>, password: &str, ) -> Result<AsyncDocument>

AsyncDocument::open with the password that opens the file, accepted as either the user or the owner password — the async twin of pdfboss_core::Document::open_with_password.

Source

pub async fn from_bytes(bytes: impl Into<Bytes>) -> Result<AsyncDocument>

Opens an in-memory document through an uncached MemBackend.

Decrypts empty-password Standard-handler files transparently, like AsyncDocument::open; a required password is rejected with pdfboss_core::Error::Encrypted.

Source

pub async fn from_bytes_with_password( bytes: impl Into<Bytes>, password: &str, ) -> Result<AsyncDocument>

AsyncDocument::from_bytes with the password that opens the file, accepted as either the user or the owner password.

Source

pub async fn with_backend(backend: impl Backend) -> Result<AsyncDocument>

Opens a document over any backend, as-is (no cache is added).

Decrypts empty-password Standard-handler files transparently, like AsyncDocument::open; a required password is rejected with pdfboss_core::Error::Encrypted.

Source

pub async fn with_backend_with_password( backend: impl Backend, password: &str, ) -> Result<AsyncDocument>

AsyncDocument::with_backend with the password that opens the file, accepted as either the user or the owner password.

Source

pub fn version(&self) -> (u8, u8)

The PDF version from the header, e.g. (1, 7).

Source§

impl AsyncDocument

Source

pub async fn get_object(&self, r: ObjRef) -> Result<Object>

Fetches an indirect object by reference (xref lookup, object-stream indirection, cached). A generation mismatch between the request and the file is tolerated (lenient), mirroring the sync document.

Source

pub async fn resolve(&self, o: &Object) -> Result<Object>

Chases reference chains with a depth guard (beyond that: CircularReference); a reference to a missing or unreadable object resolves to Null (lenient), mirroring the sync document.

Source

pub async fn decode_stream(&self, s: &Stream) -> Result<Vec<u8>>

Decodes a stream’s data through its filter chain, resolving indirect filter parameters against this document.

Source

pub async fn read_span(&self, span: Span) -> Result<Vec<u8>>

Raw file bytes for span (for hex views), clamped to the file length.

Source

pub fn file_len(&self) -> u64

Total length of the underlying file in bytes.

Source

pub async fn metadata(&self) -> Result<Metadata>

Document metadata from the trailer /Info dictionary (lenient: absent or malformed entries are simply None), mirroring the sync document.

Source

pub async fn oc_state(&self) -> Option<OcState>

The document’s optional-content visibility under its default configuration, or None when the catalog declares no /OCProperties — the async twin of the sync document’s oc_state. A rendering caller passes it on through pdfboss_render::RenderOptions::oc.

Source

pub fn page_count(&self) -> usize

Number of pages: the flattened page tree’s length. The tree is flattened once at open, so this is synchronous and authoritative — mirroring the sync document once its tree has been flattened.

Source

pub fn page(&self, index: usize) -> Result<Page>

The page at 0-based index, as the same Page type the synchronous document hands out — built by Page::from_tree_attrs, the one implementation of page defaulting, over attributes this document resolved while flattening the tree at open. Synchronous because everything it needs is already resolved.

With a Page in hand, every shared algorithm runs over this document directly: extract_text_with(doc.clone(), &page), render_page_reporting_with(doc.clone(), &page, ..), and page_content_with(&doc, &page) — the document is an Arc handle, so the clone is two atomic increments.

Source

pub fn elements(&self, opts: ElementOpts) -> ElementStream

Lazy element stream mirroring the sync iterator’s ordering and salvage semantics. Physical elements come in file order (header, objects by offset, xref/trailer sections, startxref, eof); logical elements follow in document order (pages ascending, and within a page: fonts, images, annotations, then content ops if enabled). Nothing is fetched, parsed or decoded before it is yielded.

The returned stream owns a cheap Arc clone of this document rather than borrowing it, so it is 'static and outlives self.

Trait Implementations§

Source§

impl AsyncObjectSource for AsyncDocument

What lets every shared algorithm run over an asynchronous document: page_content_with, extract_text_with, render_page_reporting_with all take any AsyncObjectSource, and this is the genuinely asynchronous one. AsyncDocument is an Arc handle, so cloning one to hand to an entry point by value is two atomic increments.

The trait speaks core’s Result, so this crate’s transport failures cross the boundary as pdfboss_core::Error::Transport (parse-layer errors unwrap back to their original variant — see the From impl in crate::error). Leniency inside the shared algorithms keys off the parse variants, which survive the crossing unchanged.

Source§

fn get(&self, r: ObjRef) -> BoxFuture<'_, Result<Object>>

Fetches an indirect object by reference.
Source§

fn stream_data<'a>(&'a self, s: &'a Stream) -> BoxFuture<'a, Result<Vec<u8>>>

Decodes a stream’s data through its filter chain, resolving indirect filter parameters against this source.
Source§

fn resolve<'a>(&'a self, o: &'a Object) -> BoxFuture<'a, Result<Object>>

Chases reference chains, depth-capped at MAX_RESOLVE_DEPTH. Read more
Source§

impl Clone for AsyncDocument

Source§

fn clone(&self) -> AsyncDocument

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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 = !

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.