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
sourceimpl Pdfium
impl Pdfium
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 object from the given external pdfium library bindings.
sourcepub fn load_pdf_from_bytes(
&self,
bytes: &[u8],
password: Option<&str>
) -> Result<PdfDocument<'_>, PdfiumError>
pub fn load_pdf_from_bytes(
&self,
bytes: &[u8],
password: Option<&str>
) -> Result<PdfDocument<'_>, PdfiumError>
Attempts to open a PdfDocument from the given byte buffer.
If the document is password protected, the given password will be used to unlock it.
sourcepub fn load_pdf_from_file(
&self,
path: &impl AsRef<Path> + ?Sized,
password: Option<&str>
) -> Result<PdfDocument<'_>, PdfiumError>
pub fn load_pdf_from_file(
&self,
path: &impl AsRef<Path> + ?Sized,
password: Option<&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-infetch()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 the Pdfium::load_pdf_from_bytes() 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<R: Read + Seek + 'static>(
&self,
reader: R,
password: Option<&str>
) -> Result<PdfDocument<'_>, PdfiumError>
pub fn load_pdf_from_reader<R: Read + Seek + 'static>(
&self,
reader: R,
password: Option<&str>
) -> Result<PdfDocument<'_>, 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-infetch()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 the Pdfium::load_pdf_from_bytes() function.
- Embed the bytes of the target document directly into the compiled WASM module
using the
include_bytes!()macro.
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<R, P> ReadPrimitive<R> for P where
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for P where
R: Read + ReadEndian<P>,
P: Default,
sourcefn read_from_little_endian(read: &mut R) -> Result<Self, Error>
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().
sourcefn read_from_big_endian(read: &mut R) -> Result<Self, Error>
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().
sourcefn read_from_native_endian(read: &mut R) -> Result<Self, Error>
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().