Skip to main content

PdfDocument

Struct PdfDocument 

Source
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: Xref

The merged cross-reference table.

Implementations§

Source§

impl PdfDocument

Source

pub fn open(path: &Path) -> Result<Self>

Open a PDF file from a path.

Source

pub fn from_bytes(data: Vec<u8>) -> Result<Self>

Parse a PDF from an in-memory byte vector.

Source

pub fn is_encrypted(&self) -> bool

Whether the document is encrypted.

Source

pub fn is_authenticated(&self) -> bool

Whether the document is encrypted and authentication has succeeded.

Source

pub fn authenticate(&mut self, password: &[u8]) -> Result<()>

Authenticate with a password. Required for encrypted documents where the empty password doesn’t work.

Source

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

Get the permission flags (if encrypted).

Source

pub fn security_state(&self) -> Option<&SecurityState>

Get the security state (for advanced use).

Source

pub fn object_count(&self) -> usize

Number of objects declared in xref.

Source

pub fn catalog_ref(&self) -> Option<&IndirectRef>

The /Root (catalog) reference from the trailer.

Source

pub fn trailer(&self) -> &PdfDict

Get the trailer dictionary.

Source

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.

Source

pub fn object_refs(&self) -> impl Iterator<Item = IndirectRef> + '_

Iterate over all in-use object references.

Source

pub fn decode_stream(&self, dict: &PdfDict, raw_data: &[u8]) -> Result<Vec<u8>>

Decode a stream object’s data.

Source

pub fn raw_data(&self) -> &[u8]

Get the raw file data.

Source

pub fn set_cache_capacity(&mut self, capacity: usize)

Set the maximum number of parsed objects to keep in the LRU cache.

Source

pub fn cached_object_count(&self) -> usize

Return the current number of cached objects.

Source§

impl PdfDocument

Source

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§

Source§

impl Debug for PdfDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V