pub struct PdfDocument {
pub version: (u8, u8),
pub xref: Xref,
/* private fields */
}Expand description
A parsed PDF document.
PdfDocument uses interior mutability (RwLock) for its object caches so
that resolve only requires &self. This makes the type Sync and enables
multi-threaded page parsing and rendering via shared references.
Fields§
§version: (u8, u8)PDF version, e.g. (1, 7) for PDF 1.7.
xref: XrefThe merged cross-reference table.
Implementations§
Source§impl PdfDocument
impl PdfDocument
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self>
pub fn from_bytes(data: Vec<u8>) -> Result<Self>
Parse a PDF from an in-memory byte vector.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Whether the document is encrypted.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Whether the document is encrypted and authentication has succeeded.
Sourcepub fn authenticate(&mut self, password: &[u8]) -> Result<()>
pub fn authenticate(&mut self, password: &[u8]) -> Result<()>
Authenticate with a password. Required for encrypted documents where the empty password doesn’t work.
Sourcepub fn permissions(&self) -> Option<Permissions>
pub fn permissions(&self) -> Option<Permissions>
Get the permission flags (if encrypted).
Sourcepub fn security_state(&self) -> Option<&SecurityState>
pub fn security_state(&self) -> Option<&SecurityState>
Get the security state (for advanced use).
Sourcepub fn object_count(&self) -> usize
pub fn object_count(&self) -> usize
Number of objects declared in xref.
Sourcepub fn catalog_ref(&self) -> Option<&IndirectRef>
pub fn catalog_ref(&self) -> Option<&IndirectRef>
The /Root (catalog) reference from the trailer.
Sourcepub fn resolve(&self, iref: &IndirectRef) -> Result<PdfObject>
pub fn resolve(&self, iref: &IndirectRef) -> Result<PdfObject>
Resolve an indirect reference to the actual object. Uses internal LRU cache. Detects circular references. Automatically decrypts if the document is encrypted and authenticated.
Returns a cloned PdfObject (owned). The interior LRU cache is
protected by a RwLock, so this method only requires &self and
can be called from multiple threads simultaneously.
Sourcepub fn object_refs(&self) -> impl Iterator<Item = IndirectRef> + '_
pub fn object_refs(&self) -> impl Iterator<Item = IndirectRef> + '_
Iterate over all in-use object references.
Sourcepub fn decode_stream(&self, dict: &PdfDict, raw_data: &[u8]) -> Result<Vec<u8>>
pub fn decode_stream(&self, dict: &PdfDict, raw_data: &[u8]) -> Result<Vec<u8>>
Decode a stream object’s data.
Sourcepub fn set_cache_capacity(&mut self, capacity: usize)
pub fn set_cache_capacity(&mut self, capacity: usize)
Set the maximum number of parsed objects to keep in the LRU cache.
Sourcepub fn cached_object_count(&self) -> usize
pub fn cached_object_count(&self) -> usize
Return the current number of cached objects.
Source§impl PdfDocument
impl PdfDocument
Sourcepub fn from_bytes_with_repair(data: Vec<u8>) -> Result<Self>
pub fn from_bytes_with_repair(data: Vec<u8>) -> Result<Self>
Parse a PDF from bytes, falling back to xref repair if the normal cross-reference table or trailer is damaged.
This tries PdfDocument::from_bytes first. If that fails
the file is scanned for object definitions and a synthetic xref
is built via rebuild_xref.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PdfDocument
impl RefUnwindSafe for PdfDocument
impl Send for PdfDocument
impl Sync for PdfDocument
impl Unpin for PdfDocument
impl UnsafeUnpin for PdfDocument
impl UnwindSafe for PdfDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more