Struct pdfium_render::pdfium::Pdfium
source · 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
impl Pdfium
sourcepub fn bind_to_statically_linked_library(
) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>
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.
sourcepub fn bind_to_system_library(
) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>
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.
sourcepub fn bind_to_library(
path: impl ToString
) -> Result<Box<dyn PdfiumLibraryBindings>, PdfiumError>
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.
sourcepub fn pdfium_platform_library_name() -> OsString
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.
sourcepub fn pdfium_platform_library_name_at_path(path: impl ToString) -> String
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.
sourcepub fn new(bindings: Box<dyn PdfiumLibraryBindings>) -> Self
pub fn new(bindings: Box<dyn PdfiumLibraryBindings>) -> Self
Creates a new Pdfium instance from the given external Pdfium library bindings.
sourcepub fn bindings(&self) -> &dyn PdfiumLibraryBindings
pub fn bindings(&self) -> &dyn PdfiumLibraryBindings
Returns the PdfiumLibraryBindings wrapped by this instance of Pdfium.
sourcepub fn load_pdf_from_byte_slice<'a>(
&'a self,
bytes: &'a [u8],
password: Option<&str>
) -> Result<PdfDocument<'a>, PdfiumError>
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.
sourcepub fn load_pdf_from_byte_vec(
&self,
bytes: Vec<u8>,
password: Option<&str>
) -> Result<PdfDocument<'_>, PdfiumError>
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.
sourcepub fn load_pdf_from_file<'a>(
&'a self,
path: &impl AsRef<Path> + ?Sized,
password: Option<&'a str>
) -> Result<PdfDocument<'_>, PdfiumError>
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
FileorBlobobject (such as aFileobject 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.
sourcepub fn load_pdf_from_reader<'a, R: Read + Seek + 'a>(
&'a self,
reader: R,
password: Option<&'a str>
) -> Result<PdfDocument<'a>, PdfiumError>
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
FileorBlobobject (such as aFileobject 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.
sourcepub async fn load_pdf_from_fetch<'a>(
&'a self,
url: impl ToString,
password: Option<&str>
) -> Result<PdfDocument<'a>, PdfiumError>
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.
sourcepub async fn load_pdf_from_blob<'a>(
&'a self,
blob: Blob,
password: Option<&str>
) -> Result<PdfDocument<'a>, PdfiumError>
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.
sourcepub fn create_new_pdf(&self) -> Result<PdfDocument<'_>, PdfiumError>
pub fn create_new_pdf(&self) -> Result<PdfDocument<'_>, PdfiumError>
Creates a new, empty PdfDocument in memory.
Trait Implementations§
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> 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
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
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>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().