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
impl AsyncDocument
Sourcepub async fn open(path: impl AsRef<Path>) -> Result<AsyncDocument>
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.
Sourcepub async fn open_with_password(
path: impl AsRef<Path>,
password: &str,
) -> Result<AsyncDocument>
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.
Sourcepub async fn from_bytes(bytes: impl Into<Bytes>) -> Result<AsyncDocument>
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.
Sourcepub async fn from_bytes_with_password(
bytes: impl Into<Bytes>,
password: &str,
) -> Result<AsyncDocument>
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.
Sourcepub async fn with_backend(backend: impl Backend) -> Result<AsyncDocument>
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.
Sourcepub async fn with_backend_with_password(
backend: impl Backend,
password: &str,
) -> Result<AsyncDocument>
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§impl AsyncDocument
impl AsyncDocument
Sourcepub async fn get_object(&self, r: ObjRef) -> Result<Object>
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.
Sourcepub async fn resolve(&self, o: &Object) -> Result<Object>
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.
Sourcepub async fn decode_stream(&self, s: &Stream) -> Result<Vec<u8>>
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.
Sourcepub async fn read_span(&self, span: Span) -> Result<Vec<u8>>
pub async fn read_span(&self, span: Span) -> Result<Vec<u8>>
Raw file bytes for span (for hex views), clamped to the file
length.
Sourcepub async fn metadata(&self) -> Result<Metadata>
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.
Sourcepub async fn oc_state(&self) -> Option<OcState>
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.
Sourcepub fn page_count(&self) -> usize
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.
Sourcepub fn page(&self, index: usize) -> Result<Page>
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.
Sourcepub fn elements(&self, opts: ElementOpts) -> ElementStream
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.
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§impl Clone for AsyncDocument
impl Clone for AsyncDocument
Source§fn clone(&self) -> AsyncDocument
fn clone(&self) -> AsyncDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more