Crate pdfium_render
source ·Expand description
Idiomatic Rust bindings for Pdfium
pdfium-render provides an idiomatic high-level Rust interface to Pdfium, the C++ PDF library
used by the Google Chromium project. Pdfium can render pages in PDF files to bitmaps, load, edit,
and extract text and images from existing PDF files, and create new PDF files from scratch.
use pdfium_render::prelude::*;
fn export_pdf_to_jpegs(path: &str, password: Option<&str>) -> Result<(), PdfiumError> {
// Renders each page in the PDF file at the given path to a separate JPEG file.
// Bind to a Pdfium library in the same directory as our Rust executable;
// failing that, fall back to using a Pdfium library provided by the operating system.
let pdfium = Pdfium::new(
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("./"))
.or_else(|_| Pdfium::bind_to_system_library())?,
);
// Load the document from the given path...
let document = pdfium.load_pdf_from_file(path, password)?;
// ... set rendering options that will be applied to all pages...
let render_config = PdfRenderConfig::new()
.set_target_width(2000)
.set_maximum_height(2000)
.rotate_if_landscape(PdfBitmapRotation::Degrees90, true);
// ... then render each page to a bitmap image, saving each image to a JPEG file.
for (index, page) in document.pages().iter().enumerate() {
page.render_with_config(&render_config)?
.as_image() // Renders this page to an image::DynamicImage...
.as_rgba8() // ... then converts it to an image::Image...
.ok_or(PdfiumError::ImageError)?
.save_with_format(
format!("test-page-{}.jpg", index),
image::ImageFormat::Jpeg
) // ... and saves it to a file.
.map_err(|_| PdfiumError::ImageError)?;
}
Ok(())
}pdfium-render binds to a Pdfium library at run-time, allowing for flexible selection of
system-provided or bundled Pdfium libraries and providing idiomatic Rust error handling in
situations where a Pdfium library is not available. A key advantage of binding to Pdfium at run-time
rather than compile-time is that a Rust application using pdfium-render can be compiled to WASM
for running in a browser alongside a WASM-packaged build of Pdfium.
pdfium-render aims to eventually provide bindings to all non-interactive functionality provided
by Pdfium. This is a work in progress that will be completed by version 1.0 of this crate.
Examples
Short, commented examples that demonstrate all the major Pdfium document handling features are available at https://github.com/ajrcarey/pdfium-render/tree/master/examples. These examples demonstrate:
- Rendering pages to bitmaps.
- Text and image extraction.
- Document signature introspection.
- Document attachment creation and introspection.
- Document concatenation.
- Page object introspection.
- Page annotation introspection.
- Page link introspection.
- Creation of new documents and new pages.
- Creation of page objects for text, paths, and bitmaps.
- Multi-page tiled output.
- Watermarking.
- Thread safety.
- Compiling to WASM.
What’s new
Note: Upcoming release 0.8.0 will include a breaking change. The PdfDocument::pages() function,
which currently returns an owned PdfPages instance, will be changed so that it returns
an immutable &PdfPages reference instead. A new PdfDocument::pages_mut() function
will return a mutable &mut PdfPages reference. It will no longer be possible to retrieve
an owned PdfPages instance. For the motivation behind this change, see
https://github.com/ajrcarey/pdfium-render/issues/47.
Version 0.7.32 fixes off-by-one errors in PdfPageText::chars_inside_rect() and examples/chars.rs
thanks to an excellent contribution from https://github.com/luketpeterson, and adds support
for grayscale image processing to PdfPageImageObject thanks to an excellent contribution
from https://github.com/stephenjudkins.
Version 0.7.31 adds the PdfPageLinks collection, the PdfPage::links() and PdfPage::links_mut()
functions, the PdfLink and PdfDestination structs, and fleshes out the implementation of
PdfAction. It is now possible to retrieve the URI of an action associated with a link using the
PdfActionUri::uri() function. examples/links.rs demonstrates the new functionality.
Version 0.7.30 corrects a potential use-after-free error in the high level interface by deprecating
the PdfPages::delete_page_at_index() and PdfPages::delete_page_range() functions in favour of
the new PdfPage::delete() function. (Previously, it was possible to hold a PdfPage reference
after deleting the page from the containing PdfPages collection.) Deprecated items will be removed
in release 0.9.0.
Version 0.7.29 removes the sync crate feature from the list of default crate features.
sync is still available as an optional crate feature. For the motivation behind this change,
see https://github.com/ajrcarey/pdfium-render/issues/66.
Version 0.7.28 removes the PdfPageObjects::take_*() functions; bugs in Pdfium’s memory handling
make them too unreliable to be useful. Instead, new functions PdfPageObject::is_copyable() and
PdfPageObject::try_copy() are introduced, allowing most path, text, and image page objects to be copied.
New functions PdfPageObjectGroup::retain(), PdfPageObjectGroup::retain_if_copyable(),
PdfPageObjectGroup::is_copyable(), PdfPageObjectGroup::try_copy_onto_existing_page(),
PdfPageObjectGroup::copy_onto_new_page_at_start(), PdfPageObjectGroup::copy_onto_new_page_at_end(),
and PdfPageObjectGroup::copy_onto_new_page_at_index() allow a group of page objects to be copied
onto a destination page. The new examples/copy_objects.rs example demonstrates this functionality.
This release also fixes a bug in the propagation of a page’s content regeneration strategy from
the page to its collection of page objects collection and to any PdfPageObjectGroup objects
created from that page objects collection.
Binding to Pdfium
pdfium-render does not include Pdfium itself. You have several options:
- Bind to a dynamically-built Pdfium library provided by the operating system.
- Bind to a dynamically-built Pdfium library packaged alongside your Rust executable.
- Bind to a statically-built Pdfium library linked to your executable at compile time.
When compiling to WASM, packaging an external build of Pdfium as a separate WASM module is essential.
Dynamic linking
Binding to a pre-built Pdfium dynamic library at runtime is the simplest option. On Android, a pre-built
libpdfium.so is packaged as part of the operating system (although recent versions of Android no
longer permit user applications to access it); alternatively, you can package a dynamic library
appropriate for your operating system alongside your Rust executable.
Pre-built Pdfium dynamic libraries suitable for runtime binding are available from several sources:
- Native (i.e. non-WASM) builds of Pdfium for all major platforms: https://github.com/bblanchon/pdfium-binaries/releases
- Android, iOS, macOS, and WASM builds of Pdfium: https://github.com/paulocoutinhox/pdfium-lib/releases
If you are compiling a native (i.e. non-WASM) build, and you place an appropriate Pdfium library in the same folder as your compiled application, then binding to it at runtime is as simple as:
use pdfium_render::prelude::*;
let pdfium = Pdfium::new(
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("./")).unwrap()
);A common pattern used in the examples at https://github.com/ajrcarey/pdfium-render/tree/master/examples is to first attempt to bind to a Pdfium library in the same folder as the compiled example, and attempt to fall back to a system-provided library if that fails:
use pdfium_render::prelude::*;
let pdfium = Pdfium::new(
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("./"))
.or_else(|_| Pdfium::bind_to_system_library())
.unwrap() // Or use the ? unwrapping operator to pass any error up to the caller
);Static linking
The static crate feature offers an alternative to dynamic linking if you prefer to link Pdfium
directly into your executable at compile time. This enables the Pdfium::bind_to_statically_linked_library()
function which binds directly to the Pdfium functions compiled into your executable:
use pdfium_render::prelude::*;
let pdfium = Pdfium::new(Pdfium::bind_to_statically_linked_library().unwrap());As a convenience, pdfium-render can instruct cargo to link a statically-built Pdfium
library for you. Set the path to the directory containing your pre-built library using
the PDFIUM_STATIC_LIB_PATH environment variable when you run cargo build, like so:
PDFIUM_STATIC_LIB_PATH="/path/containing/your/static/pdfium/library" cargo buildpdfium-render will pass the following flags to cargo:
cargo:rustc-link-lib=static=pdfium
cargo:rustc-link-search=native=$PDFIUM_STATIC_LIB_PATHThis saves you writing a custom build.rs yourself. If you have your own build pipeline
that links Pdfium statically into your executable, simply leave the PDFIUM_STATIC_LIB_PATH
environment variable unset.
Note that the path you set in PDFIUM_STATIC_LIB_PATH should not include the filename of the
library itself; it should just be the path of the containing directory. You must make sure your
statically-built library is named in the appropriate way for your target platform
(libpdfium.a on Linux and macOS, for example) in order for the Rust compiler to locate it.
Depending on how your Pdfium library was built, you may need to also link against a C++ standard library.
To link against the GNU C++ standard library (libstdc++), use the optional libstdc++ feature.
pdfium-render will pass the following additional flag to cargo:
cargo:rustc-link-lib=dylib=stdc++To link against the LLVM C++ standard library (libc++), use the optional libc++ feature.
pdfium-render will pass the following additional flag to cargo:
cargo:rustc-link-lib=dylib=c++Alternatively, use the link-cplusplus crate to link against a C++ standard library. link-cplusplus
offers more options for deciding which standard library should be selected, including automatically
selecting the build platform’s installed default.
pdfium-render will not build Pdfium for you; you must build Pdfium yourself, or source a
pre-built static archive from elsewhere. For an overview of the build process, including a sample
build script, see https://github.com/ajrcarey/pdfium-render/issues/53.
Compiling to WASM
See https://github.com/ajrcarey/pdfium-render/tree/master/examples for a full example that shows
how to bundle a Rust application using pdfium-render alongside a pre-built Pdfium WASM module for
inspection and rendering of PDF files in a web browser.
Certain functions that access the file system are not available when compiling to WASM. In all cases, browser-specific alternatives are provided, as detailed at the link above.
At the time of writing, the WASM builds of Pdfium at https://github.com/bblanchon/pdfium-binaries/releases are compiled with a non-growable WASM heap memory allocator. This means that attempting to open a PDF document longer than just a few pages will result in an unrecoverable out of memory error. The WASM builds of Pdfium at https://github.com/paulocoutinhox/pdfium-lib/releases are recommended as they do not have this problem.
Multithreading
Pdfium makes no guarantees about thread safety and should be assumed not to be thread safe. The Pdfium authors specifically recommend that parallel processing, not multi-threading, be used to process multiple documents simultaneously.
pdfium-render achieves thread safety by locking access to Pdfium behind a mutex;
each thread must acquire exclusive access to this mutex in order to make any call to Pdfium.
This has the effect of sequencing all calls to Pdfium as if they were single-threaded,
even when using pdfium-render from multiple threads. This approach offers no performance benefit,
but it ensures that Pdfium will not crash when running as part of a multi-threaded application.
An example of safely using pdfium-render as part of a multithreaded parallel iterator is
available at https://github.com/ajrcarey/pdfium-render/tree/master/examples.
Crate features
This crate provides the following optional features:
bindings: usescbindgento generate Rust bindings to the Pdfium functions defined in theinclude/*.hfiles each timecargo buildis run. Ifcbindgenor any of its dependencies are not available then the build will fail.image: controls whether theimagecrate should be used bypdfium-renderto provide page and page object rendering functionality. Projects that do not require page or page object rendering can avoid having to include theimagecrate in their binaries.libstdc++: links against the GNU C++ standard library when compiling. Requires thestaticfeature. See the “Static linking” section above.libc++: links against the LLVM C++ standard library when compiling. Requires thestaticfeature. See the “Static linking” section above.static: enables binding to a statically-linked build of Pdfium. See the “Static linking” section above.sync: provides an implementation of theSendandSynctraits for thePdfiumstruct. This allows aPdfiuminstance to be shared across threads. This is particularly useful for creating a static instance that can be used withlazy_staticoronce_cell. Requires thethread_safefeature.thread_safe: wraps access to Pdfium behind a mutex to ensure thread-safe access to Pdfium. See the “Multithreading” section above.
The image and thread_safe features are enabled by default. All other features are disabled by default.
Porting existing Pdfium code from other languages
The high-level idiomatic Rust interface provided by pdfium-render is built on top of
raw FFI bindings defined in the PdfiumLibraryBindings trait. It is completely feasible to use
these raw FFI bindings directly if you wish, making porting existing code that calls FPDF_* functions
trivial while still gaining the benefits of late binding and WASM compatibility.
For instance, the following code snippet (taken from a C++ sample):
string test_doc = "test.pdf";
FPDF_InitLibrary();
FPDF_DOCUMENT doc = FPDF_LoadDocument(test_doc, NULL);
// ... do something with doc
FPDF_CloseDocument(doc);
FPDF_DestroyLibrary();
would translate to the following Rust code:
let bindings = Pdfium::bind_to_system_library().unwrap();
let test_doc = "test.pdf";
bindings.FPDF_InitLibrary();
let doc = bindings.FPDF_LoadDocument(test_doc, None);
// ... do something with doc
bindings.FPDF_CloseDocument(doc);
bindings.FPDF_DestroyLibrary();Pdfium’s API uses three different string types: classic C-style null-terminated char arrays,
UTF-8 byte arrays, and a UTF-16LE byte array type named FPDF_WIDESTRING. For functions that take a
C-style string or a UTF-8 byte array, pdfium-render’s binding will take the standard Rust &str type.
For functions that take an FPDF_WIDESTRING, pdfium-render exposes two functions: the vanilla
FPDF_*() function that takes an FPDF_WIDESTRING, and an additional FPDF_*_str() helper function
that takes a standard Rust &str and converts it internally to an FPDF_WIDESTRING before calling
Pdfium. Examples of functions with additional _str() helpers include FPDFBookmark_Find(),
FPDFText_SetText(), FPDFText_FindStart(), FPDFDoc_AddAttachment(), FPDFAnnot_SetStringValue(),
and FPDFAttachment_SetStringValue().
The PdfiumLibraryBindings::get_pdfium_utf16le_bytes_from_str() and
PdfiumLibraryBindings::get_string_from_pdfium_utf16le_bytes() utility functions are provided
for converting to and from FPDF_WIDESTRING in your own code.
Some Pdfium functions return classic C-style integer boolean values, aliased as FPDF_BOOL.
The PdfiumLibraryBindings::TRUE(), PdfiumLibraryBindings::FALSE(),
PdfiumLibraryBindings::is_true(), and PdfiumLibraryBindings::bool_to_pdfium() utility functions
are provided for converting to and from FPDF_BOOL in your own code.
Image pixel data in Pdfium is encoded in either three-channel BGR or four-channel BGRA.
The PdfiumLibraryBindings::bgr_to_rgba(), PdfiumLibraryBindings::bgra_to_rgba(),
PdfiumLibraryBindings::rgb_to_bgra(), and PdfiumLibraryBindings::rgba_to_bgra() utility functions
are provided for converting between RGB and BGR image data in your own code.
Development status
The initial focus of this crate was on rendering pages in a PDF file; consequently, FPDF_*
functions related to page rendering were prioritised. By 1.0, the functionality of all
FPDF_* functions exported by all Pdfium modules will be available, with the exception of certain
functions specific to interactive scripting, user interaction, and printing.
- Releases numbered 0.4.x added support for all page rendering Pdfium functions to
pdfium-render. - Releases numbered 0.5.x-0.6.x added support for most read-only Pdfium functions to
pdfium-render. - Releases numbered 0.7.x aim to progressively add support for all Pdfium page object creation and editing functions to
pdfium-render. - Releases numbered 0.8.x aim to progressively add support for all other Pdfium editing functions to
pdfium-render. - Releases numbered 0.9.x aim to fill any remaining gaps in the high-level interface prior to 1.0.
By version 0.8.0, pdfium-render should provide useful coverage for the vast majority of common
use cases, whether rendering existing documents or creating new ones.
There are 368 FPDF_* functions in the Pdfium API. As of version 0.7.32, 317 (86%) have
bindings available in PdfiumLibraryBindings, with the functionality of the vast majority of
these exposed through the pdfium-render high-level interface.
Some functions and type definitions in the high-level interface have been renamed or revised since their initial implementation. The initial implementations are still available but are marked as deprecated. These deprecated items will be removed in release 0.9.0.
If you need a binding to a Pdfium function that is not currently available, just raise an issue at https://github.com/ajrcarey/pdfium-render/issues.
Version history
- 0.7.32: fixes off-by-one errors in
PdfPageText::chars_inside_rect()andexamples/chars.rsthanks to an excellent contribution from https://github.com/luketpeterson, adds support for grayscale image processing toPdfPageImageObject::get_image_from_bitmap_handle()thanks to an excellent contribution from https://github.com/stephenjudkins, and corrects a missing dependency when usingpdfium-renderwithout the defaultimagecrate feature. - 0.7.31: adds the
PdfPageLinkscollection, thePdfPage::links()andPdfPage::links_mut()functions, thePdfLinkandPdfDestinationstructs, thePdfActionCommonandPdfActionPrivatetraits, structs for the action types supported by Pdfium, thePdfActionUri::uri()function to address https://github.com/ajrcarey/pdfium-render/issues/68, and the newexamples/links.rsexample. - 0.7.30: deprecates the
PdfPages::delete_page_at_index()andPdfPages::delete_page_range()functions; addsPdfPage::delete()function in response to https://github.com/ajrcarey/pdfium-render/issues/67. Deprecated items will be removed in release 0.9.0, although it may be possible to restore these functions if safer reference handling inPdfDocumentandPdfPagesis introduced as part of https://github.com/ajrcarey/pdfium-render/issues/47. - 0.7.29: removes the
synccrate feature from the list of default crate features in response to https://github.com/ajrcarey/pdfium-render/issues/66. - 0.7.28: removes the
PdfPageObjects::take_*()functions; addsPdfPageObject::is_copyable()PdfPageObject::try_copy(),PdfPageObjectGroup::retain(),PdfPageObjectGroup::retain_if_copyable(),PdfPageObjectGroup::is_copyable(),PdfPageObjectGroup::try_copy_onto_existing_page(),PdfPageObjectGroup::copy_onto_new_page_at_start(),PdfPageObjectGroup::copy_onto_new_page_at_end(), andPdfPageObjectGroup::copy_onto_new_page_at_index()functions; addsexamples/copy_objects.rsexample; fixes a bug in the propagation of a page’s content regeneration strategy; removes all use oflazy_static!macro in favour ofonce_cell::sync::Lazy. - 0.7.27: adjusts
examples/index.htmlto take into account upstream packaging changes in the WASM builds of Pdfium published at https://github.com/paulocoutinhox/pdfium-lib/releases; adds theimagecrate feature. - 0.7.26: adds
syncdefault crate feature providingSendandSyncimplementations forPdfiumstruct; addsDisplayandErrortrait implementations toPdfiumErrorforanyhowcompatibility; adjusts WASM example to account for upstream changes in Emscripten packaging of Pdfium WASM builds; corrects a lifetime problem inPdfium::load_pdf_from_bytes()and deprecatesPdfium::load_pdf_from_bytes()in favour ofPdfium::load_pdf_from_byte_slice()andPdfium::load_pdf_from_byte_vec(). Deprecated items will be removed in release 0.9.0. - 0.7.25: adds the
PdfPageAnnotationObjectscollection and thePdfPageAnnotation::objects(),PdfPageInkAnnotation::objects_mut(), andPdfPageStampAnnotation::objects_mut()functions to the high-level interface. - 0.7.24: adds bindings for
FPDFClipPath_CountPathSegments(),FPDFClipPath_GetPathSegment(),FPDFPath_CountSegments(),FPDFPath_GetPathSegment(), andFPDFPathSegment_*()functions; addsPdfFontGlyphsandPdfPagePathObjectSegmentscollections to the high-level interface, along with accessor functions inPdfFontandPdfPagePathObject; adds thePdfPathSegmentstrait; introduces some infrastructure necessary for the future implementation of aPdfClipPathobject; addsPdfPages::first(),PdfPages::last(), andPdfPage::fonts()convenience functions. - 0.7.23: removes some unnecessary mutable bindings in
PdfBitmap; uses#[cfg(doc)]declarations to ensurecargo docgenerates documentation for all functionality, irrespective of the platform. - 0.7.22: attempts to work around two problems in Pdfium’s bitmap generation when retrieving processed renderings of page image objects. See https://github.com/ajrcarey/pdfium-render/issues/52 for more information.
- 0.7.21: adds bindings for
FPDF_GetPageAAction(),FPDF_GetFileIdentifier(), and all remainingFPDFDest_*()andFPDFLink_*()functions; addsPdfAttachment::len()andPdfAttachment::is_empty()convenience functions; addslibstdc++andlibc++crate features; adds color conversion functions toPdfiumLibraryBindings; corrects bugs in color conversion when working withPdfPageImageObject, as detailed in https://github.com/ajrcarey/pdfium-render/issues/50; fixes a bug in the WASM implementation ofFPDFAnnot_GetAttachmentPoints(); corrects some small typos in examples. - 0.7.20: adds bindings for
FPDFPage_*Thumbnail*(),FPDFLink_*(), andFPDFText_Find*()functions; addsPdfAttachments::create_attachment_from_bytes(),PdfAttachments::create_attachment_from_file(),PdfAttachments::create_attachment_from_reader(),PdfAttachments::create_attachment_from_fetch(),
PdfAttachments::create_attachment_from_blob(),PdfAttachments::delete_at_index(),PdfAttachment::save_to_writer(),PdfAttachment::save_to_file(),PdfAttachment::save_to_blob(),PdfPage::has_embedded_thumbnail(),PdfPage::embedded_thumbnail(), andPdfPage::boundaries_mut()functions to the high-level interface; renamesPdfAttachment::bytes()function introduced in 0.7.19 toPdfAttachment::save_to_bytes(). - 0.7.19: adds bindings for
FPDFDoc_*Attachment*()functions; addsPdfAttachmentsandPdfSignaturescollections to the high-level interface. - 0.7.18: adds convenience
bindings()accessor functions toPdfDocument,PdfPage,PdfBitmap,PdfFont, and various other interfaces, thanks to an excellent contribution from https://github.com/LU15W1R7H; deprecatesPdfium::get_bindings()in favour ofPdfium::bindings()for consistency. Deprecated items will be removed in release 0.9.0. - 0.7.17: relaxes some unnecessarily restrictive lifetime bounds in
PdfPageObjectPath. - 0.7.16: adds
PdfPageObjects::create_path_object_bezier()andPdfPageObjectPath::new_bezier()convenience functions; corrects some typos in documentation. - 0.7.15: adds
PdfPageAnnotationCommon::name(),PdfPageAnnotationCommon::contents(),PdfPageAnnotationCommon::author(),PdfPageAnnotationCommon::creation_date(), andPdfPageAnnotationCommon::modification_date()functions for working with annotations; addsPdfPageText::for_annotation()andPdfPageText::chars_for_annotation()for more easily extracting text and characters associated with annotations; addsexamples/annotations.rsandexamples/image_extract.rs; renamesexamples/text.rstoexamples/text_extract.rs. - 0.7.14: fixes a bug in the WASM implementation of
FPDF_StructElement_GetStringAttribute(); pins required version ofimagecrate to at least 0.24.0 or later to avoid incompatibility between theimage::DynamicImagetrait definitions in 0.23.x and 0.24.x; adds compatibility with web workers to the WASM implementation, thanks to an excellent contribution from https://github.com/NyxCode. - 0.7.13: adds transformation and clipping functions to
PdfRenderConfig; adds bindings forFPDF_RenderPageBitmapWithMatrix(); deprecatesPdfRenderConfig::rotate_if_portait()in favour of the correctly-spelledPdfRenderConfig::rotate_if_portrait(). Deprecated items will be removed in release 0.9.0. - 0.7.12: adds
PdfPage::render_into_bitmap()andPdfPage::render_into_bitmap_with_config()functions for higher performance; deprecatesPdfPage::get_bitmap()in favour ofPdfPage::render(); deprecatesPdfPage::get_bitmap_with_config()in favour ofPdfPage::render_with_config(); deprecatesPdfBitmapConfigin favour ofPdfRenderConfig; deprecatesPdfBitmap::render()as the function is no longer necessary. Deprecated items will be removed in release 0.9.0. - 0.7.11: adds the new WASM-specific
PdfBitmap::as_array()function as a higher performance alternative to the cross-platformPdfBitmap::as_bytes()function, thanks to an excellent contribution from https://github.com/NyxCode. - 0.7.10: corrects some typos in documentation; adds additional constructors to
PdfPageImageObjectthat apply a specified width and/or height at object creation time. - 0.7.9: adds retrieval of the list of image filters applied to a
PdfPageImageObject; adds thePdfColorSpaceenum; adds bindings for theFPDF_*Signature*(),FPDFSignatureObj_*(), andFPDF_StructTree_*()functions. - 0.7.8: adds image support to the
PdfPageImageObjectstruct, thePdfPageObjects::add_image_object()andPdfPageObjects::create_image_object()functions, additional convenience functions for loading fonts from files and readers toPdfFont, and bindings forFPDF_VIEWERREF_Get*()functions. - 0.7.7: adds the
thread_safecrate feature and the accompanying example inexamples/thread_safe.rs. - 0.7.6: adds retrieval of text settings on a character-by-character basis to the
PdfPageTextandPdfPageTextObjectobjects; addsPdfPageTextSegmentandPdfPageTextCharstructs to the high-level interface; adds retrieval of current transformation settings to all page objects; adds thePdfPageTextObject::scaled_font_size()function and renamesPdfPageTextObject::font_size()toPdfPageTextObject::unscaled_font_size()as these names make clearer the differences between scaled and unscaled font sizes in text objects; adds bindings for all remainingFPDFText_*()functions. - 0.7.5: corrects a bug in error handling on Windows. See https://github.com/ajrcarey/pdfium-render/issues/24 for more information.
- 0.7.4: adds the
PdfPageGroupObject::remove_objects_from_page()function; renamedPdfPageObjects::delete_object()andPdfPageObjects::delete_object_at_index()functions toPdfPageObjects::remove_object()andPdfPageObjects::remove_object_at_index()as these names better reflect the underlying operation that occurs. - 0.7.3: corrects a bug in the implementation of
PdfPages::append()introduced in 0.7.2. - 0.7.2: adds object groups for manipulating and transforming groups of page objects as if they
were a single object, and the
PdfPages::watermark()function for applying individualized watermarks to any or all pages in a document. Fixes a potential double-free bug inPdfFont::drop(). - 0.7.1: adds path segment creation to the
PdfPagePathObjectobject, convenience functions for quickly creating rectangles, ellipses, and circles, and thePdfPageObjects::add_path_object()function. - 0.7.0: adds
PdfPermissionscollection, adds document loading and saving support, adds initial creation and editing support for documents, pages, and text objects, and improves WASM document file handling. - 0.6.0: fixes some typos in documentation, updates upstream Pdfium WASM package source repository name.
- 0.5.9: corrects a bug in the statically linked bindings implementation. Adjusted tests to cover both dynamic and statically linked bindings implementations.
- 0.5.8: corrects a bug in the WASM implementation of certain
FPDFAnnot_*()functions. Resolves a potential memory leak affecting the WASM implementation of variousFPDF_*()functions. - 0.5.7: adds support for binding to a statically-linked build of Pdfium, adds
bindgenandstaticcrate features. - 0.5.6: adds
pdfium_render::prelude, adds bindings forFPDFAnnot_*()andFPDFPage_*Annot*()functions, addsPdfPageAnnotationscollection andPdfPageAnnotationstruct to the high-level interface. - 0.5.5: fixes two bugs in the WASM implementation, one to do with colors, one to do with text extraction. See https://github.com/ajrcarey/pdfium-render/issues/9 and https://github.com/ajrcarey/pdfium-render/issues/11 for more information.
- 0.5.4: changes default setting of
PdfBitmapConfig::set_reverse_byte_order()totrueto switch from Pdfium’s default BGRA8 pixel format to RGBA8. This is necessary since theimagecrate dropped support for BGRA8 in version 0.24. See https://github.com/ajrcarey/pdfium-render/issues/9 for more information. - 0.5.3: adds bindings for
FPDFBookmark_*(),FPDFPageObj_*(),FPDFText_*(), andFPDFFont_*()functions, addsPdfPageObjects,PdfPageText, andPdfBookmarkscollections to the high-level interface. - 0.5.2: adds bindings for
FPDF_GetPageBoundingBox(),FPDFDoc_GetPageMode(),FPDFPage_Get*Box(), andFPDFPage_Set*Box()functions, addsPdfPageBoundariescollection to the high-level interface. - 0.5.1: adds bindings for
FPDFPage_GetRotation()andFPDFPage_SetRotation()functions, addsPdfMetadatacollection to the high-level interface. - 0.5.0: adds rendering of annotations and form field elements, thanks to an excellent contribution from https://github.com/inzanez.
- 0.4.2: bug fixes in
PdfBitmapConfigimplementation. - 0.4.1: improvements to documentation and READMEs.
- 0.4.0: initial release of minimal page rendering functionality.
Modules
- Defines the PdfAction struct, exposing functionality related to a single action associated with a clickable link or document bookmark.
- Defines the PdfActionEmbeddedDestination struct, exposing functionality related to a single action of type
PdfActionType::GoToDestinationInEmbeddedDocument. - Defines the PdfActionLaunch struct, exposing functionality related to a single action of type
PdfActionType::Launch. - Defines the PdfActionLocalDestination struct, exposing functionality related to a single action of type
PdfActionType::GoToDestinationInSameDocument. - Defines the PdfActionRemoteDestination struct, exposing functionality related to a single action of type
PdfActionType::GoToDestinationInRemoteDocument. - Defines the PdfActionUnsupported struct, exposing functionality related to a single action of type
PdfActionType::Unsupported. - Defines the PdfActionUri struct, exposing functionality related to a single action of type
PdfActionType::Uri. - Defines the PdfAttachment struct, exposing functionality related to a single attachment in a
PdfAttachmentscollection. - Defines the PdfiumLibraryBindings trait, containing run-time bindings to the FPDF_* functions exported by the Pdfium library.
- Defines the PdfBitmap struct, a bitmap image with a specific width and height.
- Defines the PdfBookmark struct, exposing functionality related to a single bookmark in a
PdfBookmarkscollection. - Defines the PdfBookmarks struct, exposing functionality related to the bookmarks contained within a single
PdfDocument. - Defines the PdfColor struct, a 32-bit RGB color value with an optional alpha channel.
- Defines the PdfColorSpace enum, defining all the color spaces supported by the PDF file format.
- Defines the PdfDestination struct, exposing functionality related to the target destination of a link contained within a single
PdfPage. - Defines the PdfDocument struct, the entry point to all Pdfium functionality related to a single PDF file.
- Defines the PdfiumError enum, used to wrap Pdfium errors as
Errvalues. - Defines the PdfFont struct, exposing functionality related to a single font used to render text in a
PdfDocument. - Defines the PdfFontGlyph struct, exposing functionality related to a single font glyph in a
PdfFontGlyphscollection. - Defines the PdfForm struct, exposing functionality related to a form embedded in a
PdfDocument. - Defines the PdfLink struct, exposing functionality related to a single link contained within a
PdfPage, aPdfPageAnnotation, or aPdfBookmark. - Defines the PdfMetadata struct, a collection of all the metadata tags in a
PdfDocument. - Defines the PdfPage struct, exposing functionality related to a single page in a
PdfPagescollection. - Defines the PdfPageAnnotation struct, exposing functionality related to a single annotation.
- Defines the PdfPageCircleAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Circle. - Defines the PdfPageFreeTextAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::FreeText. - Defines the PdfPageHighlightAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Highlight. - Defines the PdfPageInkAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Ink. - Defines the PdfPageLinkAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Link. - Defines the PdfPageAnnotationObjects struct, exposing functionality related to the page objects contained within a single
PdfPageAnnotation. - Defines the PdfPagePopupAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Popup. - Defines the PdfPageSquareAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Square. - Defines the PdfPageSquigglyAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Squiggly. - Defines the PdfPageStampAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Stamp. - Defines the PdfPageStrikeoutAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Strikeout. - Defines the PdfPageTextAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Text. - Defines the PdfPageUnderlineAnnotation struct, exposing functionality related to a single user annotation of type
PdfPageAnnotationType::Underline. - Defines the PdfPageUnsupportedAnnotation struct, exposing functionality related to any single annotation object of a type not supported by Pdfium.
- Defines the PdfPageAnnotations struct, exposing functionality related to the annotations that have been added to a single
PdfPage. - Defines the PdfPageBoundaries struct, exposing functionality related to the boundary boxes of a single
PdfPage. - Defines the PdfPageLinks struct, exposing functionality related to the links contained within a single
PdfPage. - Defines the PdfPageObject enum, exposing functionality related to a single page object.
- Defines the PdfPageFormFragmentObject struct, exposing functionality related to a single page object of type
PdfPageObjectType::FormFragment. - Defines the PdfPageGroupObject struct, exposing functionality related to a group of page objects contained in the same
PdfPageObjectscollection. - Defines the PdfPageImageObject struct, exposing functionality related to a single page object defining a bitmapped image.
- Defines the PdfPagePathObject struct, exposing functionality related to a single page object defining a path.
- Defines the PdfPageShadingObject struct, exposing functionality related to a single page object of type
PdfPageObjectType::Shading. - Defines the PdfPageTextObject struct, exposing functionality related to a single page object defining a piece of formatted text.
- Defines the PdfPageUnsupportedObject struct, exposing functionality related to a single page object of type
PdfPageObjectType::Unsupported. - Defines the PdfPageObjects struct, exposing functionality related to the page objects contained within a single
PdfPage. - Defines the PdfPageObjectsCommon trait, providing functionality common to all containers of multiple
PdfPageObjectobjects. - Defines the PdfPagePaperSize enum, a set of common ANSI and ISO paper sizes.
- Defines the PdfPageText struct, exposing functionality related to the collection of Unicode characters visible in a single
PdfPage. - Defines the PdfPageTextChar struct, exposing functionality related to a single character in a
PdfPageTextCharscollection. - Defines the PdfPageTextChars struct, a collection of all the distinct characters in a bounded rectangular region of a single
PdfPage. - Defines the PdfPageTextSegment struct, exposing functionality related to a single rectangular text segment in a
PdfPageTextSegmentscollection. - Defines the PdfPageTextSegments struct, a collection of all the distinct rectangular areas of a single
PdfPageoccupied by spans of text that share a common text style. - Defines the PdfPathSegment struct, exposing functionality related to a single path segment in a
PdfPathSegmentscollection. - Defines the PdfPathSegments trait, a collection of all the
PdfPathSegmentobjects in a path page object, a font glyph path, or a clip path. - Defines the Pdfium struct, a high-level idiomatic Rust wrapper around Pdfium.
- Defines the PdfPermissions collection, containing information on the permissions and security handlers set for a single
PdfDocument. - A prelude for conveniently importing all public
pdfium-renderdefinitions at once. - Defines the PdfRenderConfig struct, a builder-based approach to configuring the rendering of
PdfBitmapobjects from one or more PdfPage objects. - Defines the PdfSignature struct, exposing functionality related to a single digital signature in a
PdfSignaturescollection.