pub struct Pdfium { /* private fields */ }
Expand description

A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project.

Implementations§

source§

impl Pdfium

source

pub fn bind_to_statically_linked_library( ) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>

Binds to a Pdfium library that was statically linked into the currently running executable, returning a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library. The application will immediately crash if Pdfium was not correctly statically linked into the executable at compile time.

This function is only available when this crate’s static feature is enabled.

source

pub fn bind_to_system_library( ) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>

Initializes the external Pdfium library, loading it from the system libraries. Returns a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded.

source

pub fn bind_to_library( path: impl ToString ) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>

Initializes the external pdfium library, loading it from the given path. Returns a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded.

source

pub fn pdfium_platform_library_name() -> OsString

Returns the name of the external Pdfium library on the currently running platform. On Linux and Android, this will be libpdfium.so or similar; on Windows, this will be pdfium.dll or similar; on MacOS, this will be libpdfium.dylib or similar.

source

pub fn pdfium_platform_library_name_at_path(path: impl ToString) -> String

Returns the name of the external Pdfium library on the currently running platform, prefixed with the given path string.

source

pub fn new(bindings: Box<dyn PdfiumLibraryBindings>) -> Self

Creates a new Pdfium instance from the given external Pdfium library bindings.

source

pub fn bindings(&self) -> &dyn PdfiumLibraryBindings

Returns the PdfiumLibraryBindings wrapped by this instance of Pdfium.

source

pub fn load_pdf_from_byte_slice<'a>( &'a self, bytes: &'a [u8], password: Option<&str> ) -> Result<PdfDocument<'a>, PdfiumError>

Attempts to open a PdfDocument from the given static byte buffer.

If the document is password protected, the given password will be used to unlock it.

source

pub fn load_pdf_from_byte_vec( &self, bytes: Vec<u8>, password: Option<&str> ) -> Result<PdfDocument<'_>, PdfiumError>

Attempts to open a PdfDocument from the given owned byte buffer.

If the document is password protected, the given password will be used to unlock it.

pdfium-render will take ownership of the given byte buffer, ensuring its lifetime lasts as long as the PdfDocument opened from it.

source

pub fn load_pdf_from_file<'a>( &'a self, path: &impl AsRef<Path> + ?Sized, password: Option<&'a str> ) -> Result<PdfDocument<'_>, PdfiumError>

Attempts to open a PdfDocument from the given file path.

If the document is password protected, the given password will be used to unlock it.

This function is not available when compiling to WASM. You have several options for loading your PDF document data in WASM:

  • Use the Pdfium::load_pdf_from_fetch() function to download document data from a URL using the browser’s built-in fetch() API. This function is only available when compiling to WASM.
  • Use the Pdfium::load_pdf_from_blob() function to load document data from a Javascript File or Blob object (such as a File object returned from an HTML <input type="file"> element). This function is only available when compiling to WASM.
  • Use another method to retrieve the bytes of the target document over the network, then load those bytes into Pdfium using either the Pdfium::load_pdf_from_byte_slice() function or the Pdfium::load_pdf_from_byte_vec() function.
  • Embed the bytes of the target document directly into the compiled WASM module using the include_bytes!() macro.
source

pub fn load_pdf_from_reader<'a, R: Read + Seek + 'a>( &'a self, reader: R, password: Option<&'a str> ) -> Result<PdfDocument<'a>, PdfiumError>

Attempts to open a PdfDocument from the given reader.

Pdfium will only load the portions of the document it actually needs into memory. This is more efficient than loading the entire document into memory, especially when working with large documents, and allows for working with documents larger than the amount of available memory.

Because Pdfium must know the total content length in advance prior to loading any portion of it, the given reader must implement the Seek trait as well as the Read trait.

If the document is password protected, the given password will be used to unlock it.

This function is not available when compiling to WASM. You have several options for loading your PDF document data in WASM:

  • Use the Pdfium::load_pdf_from_fetch() function to download document data from a URL using the browser’s built-in fetch() API. This function is only available when compiling to WASM.
  • Use the Pdfium::load_pdf_from_blob() function to load document data from a Javascript File or Blob object (such as a File object returned from an HTML <input type="file"> element). This function is only available when compiling to WASM.
  • Use another method to retrieve the bytes of the target document over the network, then load those bytes into Pdfium using either the Pdfium::load_pdf_from_byte_slice() function or the Pdfium::load_pdf_from_byte_vec() function.
  • Embed the bytes of the target document directly into the compiled WASM module using the include_bytes!() macro.
source

pub async fn load_pdf_from_fetch<'a>( &'a self, url: impl ToString, password: Option<&str> ) -> Result<PdfDocument<'a>, PdfiumError>

Attempts to open a PdfDocument by loading document data from the given URL. The Javascript fetch() API is used to download data over the network.

If the document is password protected, the given password will be used to unlock it.

This function is only available when compiling to WASM.

source

pub async fn load_pdf_from_blob<'a>( &'a self, blob: Blob, password: Option<&str> ) -> Result<PdfDocument<'a>, PdfiumError>

Attempts to open a PdfDocument by loading document data from the given Blob. A File object returned from a FileList is a suitable Blob:

<input id="filePicker" type="file">

const file = document.getElementById('filePicker').files[0];

If the document is password protected, the given password will be used to unlock it.

This function is only available when compiling to WASM.

source

pub fn create_new_pdf(&self) -> Result<PdfDocument<'_>, PdfiumError>

Creates a new, empty PdfDocument in memory.

Trait Implementations§

source§

impl Default for Pdfium

source§

fn default() -> Self

Binds to an external Pdfium library, loading it from the system libraries, by calling Pdfium::bind_to_system_library(). This function will panic if no suitable system library can be loaded.

source§

impl Drop for Pdfium

source§

fn drop(&mut self)

Closes the external Pdfium library, releasing held memory.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Pdfium

§

impl !Send for Pdfium

§

impl !Sync for Pdfium

§

impl Unpin for Pdfium

§

impl !UnwindSafe for Pdfium

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.