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: &impl AsRef<Path>, 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.
// See the "Dynamic linking" section below.
let pdfium = Pdfium::default();
// 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(PdfPageRenderRotation::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...
.into_rgb8() // ... then converts it to an image::Image...
.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.
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, and portions of pages, to bitmaps.
- Text and image extraction.
- Form field introspection and filling of form fields.
- 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.
- Page object transformation.
- Multi-page tiled rendering.
- Watermarking.
- Thread safety.
- Compiling to WASM.
Note: upcoming release 0.9.0 will remove all deprecated items. For a complete list of deprecated items, see ajrcarey#36.
Release 0.8.24 fixes a bug in certain string handling operations in the WASM bindings implementation, and introduces the ability to control the version of the Pdfium API used by pdfium-render
. By default pdfium-render
uses the latest released version of the Pdfium API, potentially requiring you to upgrade your Pdfium library if the latest release contains breaking changes. This can be inconvenient! To explicitly use an older API version, select one of the crate's Pdfium version feature flags when taking pdfium-render
as a dependency in your project's Cargo.toml
. See the "Crate features" section below for more information.
Release 0.8.23 updates the Pdfium bindings to the latest upstream release, adds new function PdfPageTextChar::text_object()
for retrieving the page object containing a specific character in a text page, deprecates the PdfFont::name()
function in favour of PdfFont::family()
to match changes in upstream naming, adds new functions PdfFont::is_embedded()
and PdfFont::data()
for retrieving embedded font data, updates the examples/fonts.rs
example to demonstrate the new functionality, and adjusts the implementation of some internal functions in response to upstream changes. Deprecated items will be removed in release 0.9.0.
Release 0.8.22 updates all examples and tests that reference functionality from the image
crate
to use calls compatible with both image
0.25.x and 0.24.x, adds support for static linking to a
dynamic Pdfium library at compile time, adds the PdfPages::page_size()
and PdfPages::page_sizes()
functions for retrieving the size of one or all pages without first needing to load those pages
into memory, and removes an unneeded internal dependency on the iter_tools
crate, thanks to
excellent contributions from both https://github.com/DorianRudolph and https://github.com/aruediger.
Release 0.8.21 adds the PdfFormFieldText::set_value()
function for setting the values of text
form fields, thanks to an excellent contribution from https://github.com/liammcdermott.
A new examples/fill_form_field.rs
example demonstrates the new functionality.
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.
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
);
This pattern is used to provide an implementation of the Default
trait, so the above can be
written more simply as:
use pdfium_render::prelude::*;
let pdfium = Pdfium::default();
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 to either a dynamically-built or a
statically-built Pdfium library for you. To link to a dynamically-built library, set the
PDFIUM_DYNAMIC_LIB_PATH
environment variable when you run cargo build
, like so:
PDFIUM_DYNAMIC_LIB_PATH="/path/containing/your/dynamic/pdfium/library" cargo build
pdfium-render
will pass the following flags to cargo
:
cargo:rustc-link-lib=dylib=pdfium
cargo:rustc-link-search=native=$PDFIUM_DYNAMIC_LIB_PATH
To link to a statically-built library, set the path to the directory containing your 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 build
pdfium-render
will pass the following flags to cargo
:
cargo:rustc-link-lib=static=pdfium
cargo:rustc-link-search=native=$PDFIUM_STATIC_LIB_PATH
These two environment variables save you writing a custom build.rs
yourself. If you have your own
build pipeline that links Pdfium statically into your executable, simply leave these environment
variables unset.
Note that the path you set in either PDFIUM_DYNAMIC_LIB_PATH
or 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 library is named in the appropriate way for your target platform
(libpdfium.so
or 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, source a
pre-built static archive from elsewhere, or use a dynamically built library downloaded from one
of the sources listed above in the "Dynamic linking" section. If you wish to build a static library
yourself, an overview of the build process - including a sample build script - is available at
ajrcarey#53.
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.
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 multi-threaded parallel iterator is
available at https://github.com/ajrcarey/pdfium-render/tree/master/examples.
This crate provides the following optional features:
bindings
: usescbindgen
to generate Rust bindings to the Pdfium functions defined in theinclude/*.h
files each timecargo build
is run. Ifcbindgen
or any of its dependencies are not available then the build will fail.image
: controls whether theimage
crate should be used bypdfium-render
to provide page and page object rendering functionality. Projects that do not require page or page object rendering can disable this feature to avoid compiling theimage
crate into their binaries.libstdc++
: links against the GNU C++ standard library when compiling. Requires thestatic
feature. See the "Static linking" section above.libc++
: links against the LLVM C++ standard library when compiling. Requires thestatic
feature. See the "Static linking" section above.static
: enables binding to a statically-linked build of Pdfium. See the "Static linking" section above.sync
: provides implementations of theSend
andSync
traits for thePdfium
andPdfDocument
structs. This is useful for creating static instances that can be used withlazy_static
oronce_cell
, although those instances are not guaranteed to be thread-safe. Use entirely at your own risk. Requires thethread_safe
feature.thread_safe
: wraps access to Pdfium behind a mutex to ensure thread-safe access to Pdfium. See the "Multithreading" section above.
Release 0.8.24 introduced new features to explicitly control the version of the Pdfium API used by pdfium-render
:
pdfium_future
: bindsPdfiumLibraryBindings
to the latest published Pdfium API at https://pdfium.googlesource.com/pdfium/+/refs/heads/main/public, irrespective of whether those changes have been built into a release at https://github.com/bblanchon/pdfium-binaries/releases. Useful for testing unreleased changes. Automatically activates thebindings
feature.pdfium_latest
: bindsPdfiumLibraryBindings
to the latest released build of Pdfium at https://github.com/bblanchon/pdfium-binaries/releases, currently 6611.pdfium_6611
,pdfium_6569
,pdfium_6555
,pdfium_6490
,pdfium_6406
,pdfium_6337
,pdfium_6295
,pdfium_6259
,pdfium_6164
,pdfium_6124
,pdfium_6110
,pdfium_6084
,pdfium_6043
,pdfium_6015
,pdfium_5961
: bindsPdfiumLibraryBindings
to the specified version of the Pdfium API.
The image
, thread_safe
, and pdfium_latest
features are enabled by default. All other features are disabled by default.
The high-level idiomatic Rust interface provided by pdfium-render
is built on top of
raw FFI bindings to the Pdfium API defined in the PdfiumLibraryBindings
trait. It is completely feasible to use
these raw FFI bindings directly if you wish, making porting existing code that uses the Pdfium API
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 pdfium = Pdfium::default();
let bindings = pdfium.bindings();
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()
, PdfiumLibraryBindings::to_result()
, 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.
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 basic 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 added support for most Pdfium page object creation and editing functions to
pdfium-render
. - Releases numbered 0.8.x aim to progressively add support for all remaining 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.
There are 377 FPDF_*
functions in the Pdfium API. As of version 0.8.24, 334 (89%) have
bindings available in PdfiumLibraryBindings
, with the functionality of the majority of these
available via 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.
- 0.8.24: introduced crate feature flags for selecting Pdfium API versions to use in
PdfiumLibraryBindings
; reworkedbuild.rs
to output bindings for multiple sets of Pdfium header files; reworked bindings implementations to differentiate between API versions that include theFPDFFont_*
andFPDFText_GetTextObject()
functions added in 0.8.23, and API versions that do not; internally reorganize source code layout to make the code structure clearer. - 0.8.23: synchronized Pdfium API header files against mainline; removes binding for function
FPDFText_GetTextRenderMode()
in response to upstream change described at ajrcarey#151; adds bindings forFPDFText_GetTextObject()
,FPDFFont_GetFamilyName()
,FPDFFont_GetIsEmbedded()
, andFPDFFont_GetFontData()
functions; deprecatesPdfFont::name()
function in favour ofPdfFont::family()
to match upstream naming changes; adds new functionsPdfFont::is_embedded()
andPdfFont::data()
for retrieving embedded font data; updatesexamples/fonts.rs
example; adds new functionPdfPageTextChar::text_object()
for retrieving the page object containing a specific character; adds WASM bindings utility functioncopy_string_to_pdfium()
to correctly copy the string data of anFPDF_WIDESTRING
to Pdfium's WASM memory module, instead of just the pointer location. Deprecated items will be removed in release 0.9.0. - 0.8.22: adds bindings for
FPDFPage_TransformAnnots()
, thanks to an excellent contribution from https://github.com/liammcdermott; adds bindings forFPDF_GetPageSizeByIndexF()
, thanks to an excellent contribution from https://github.com/DorianRudolph; updates all examples and tests that reference functionality from theimage
crate to use calls compatible with bothimage
0.25.x and 0.24.x, thanks to an excellent contribution from https://github.com/DorianRudolph; adds support for both static linking to a dynamically-built Pdfium library at compile time and dynamic binding caching for improved runtime performance, thanks to an excellent contribution from https://github.com/DorianRudolph; adds thePdfPages::get_page_size()
andPdfPages::get_page_sizes()
functions, thanks to an excellent contribution from https://github.com/DorianRudolph; removes an unneeded internal dependency on theiter_tools
crate, thanks to an excellent contribution from https://github.com/aruediger. - 0.8.21: adds the
PdfFormFieldText::set_value()
function for setting the values of text form fields, thanks to an excellent contribution from https://github.com/liammcdermott; adds newexamples/fill_form_field.rs
example. - 0.8.20: adds
PdfPageAnnotationAttachmentPoints
struct and matching iterator; adds new annotation functions toPdfPageAnnotationCommon
along with their matching implementations inPdfPageAnnotationPrivate
, includingPdfPageAnnotationCommon::set_bounds()
,PdfPageAnnotationCommon::set_position()
,PdfPageAnnotationCommon::set_width()
,PdfPageAnnotationCommon::set_height()
,PdfPageAnnotationCommon::set_creation_date()
,PdfPageAnnotationCommon::set_modification_date()
;PdfPageAnnotationCommon::stroke_color()
,PdfPageAnnotationCommon::set_stroke_color()
,PdfPageAnnotationCommon::fill_color()
,PdfPageAnnotationCommon::set_fill_color()
functions; addsPdfPageAnnotationCommon::attachment_points()
accessor function; adds conversion fromchrono::DateTime
types to PDF date strings inutils::dates
; adds mutability and annotation creation functions toPdfPageAnnotations
collection; adds newcreate_annotations.rs
example; addsPdfPageTextSegment::chars()
convenience function. - 0.8.19: adds bindings for
FORM_OnAfterLoadPage()
,FORM_OnBeforeClosePage()
,FPDFCatalog_IsTagged()
,FPDFBookmark_GetCount()
, andFPDF_GetPageAAction()
functions; adds thePdfBookmark::children_len()
function; adjusts the behaviour ofPdfPage::flatten()
so that the page is reloaded after the call toFPDFPage_Flatten()
. This ensures that the effect of the flatten operation is immediately visible to the caller; previously, it was necessary for the caller to explicitly drop and reload the page. For more details, see ajrcarey#140. - 0.8.18: adjusts
PdfiumRenderWasmState::bind_to_pdfium()
to fall back toModule["wasmExports"]["__indirect_function_table"]
ifWindow.wasmTable
global variable is not available, in response to upstream packaging changes at https://github.com/paulocoutinhox/pdfium-lib/releases. For more details, see ajrcarey#134. - 0.8.17: updates all examples (except for
export.rs
) to use extendedPdfium::default()
implementation introduced in 0.8.12; fixes a segmentation fault inPdfDocument::drop()
that can occur when using a V8/XFA-enabled build of Pdfium; adjustsPdfiumRenderWasmState::bind_to_pdfium()
to fall back toModule["wasmExports"]["malloc"]
andModule["wasmExports"]["free"]
ifModule["_malloc"]
andModule["_free"]
are not available, in response to upstream packaging changes at https://github.com/paulocoutinhox/pdfium-lib/releases. For more details, see ajrcarey#128. - 0.8.16: deprecates
PdfBitmap::as_bytes()
function in favour ofPdfBitmap::as_raw_bytes()
; adds newPdfBitmap::as_rgba_bytes()
for returning pixel byte data with normalized color channels, irrespective of the original bitmap pixel format; updates the WASM-specificPdfBitmap::as_image_data()
function to usePdfBitmap::as_rgba_bytes()
instead ofPdfBitmap::as_raw_bytes()
, ensuring the color normalization behaviour of both WASM and non-WASM builds is identical; refactorsPdfBookmarksIterator
to use a standard depth-first graph traversal algorithm in response to ajrcarey#120; addsPdfBookmark::destination()
function for retrieving the target destination of the action assigned to a bookmark, thanks to an excellent contribution from https://github.com/xVanTuring. Deprecated items will be removed in release 0.9.0. - 0.8.15: adds new
reset_matrix()
andreset_matrix_to_identity()
functions to consumers of thecreate_transform_setters!()
macro; deprecatesset_matrix()
in favour ofapply_matrix()
andPdfPage::set_matrix_with_clip()
in favour ofPdfPage::apply_matrix_with_clip()
; adds a matching corrects a byte alignment bug that could occur when converting three-bytes-per-pixel bitmaps to four-bytes-per-pixel bitmaps, thanks to an excellent contribution from https://github.com/vladmovchan. Deprecated items will be removed in release 0.9.0. - 0.8.14: adjusts the
PdfSearchOptions::as_pdfium()
function introduced in 0.8.13 to return ac_ulong
in order to fix a build-time error specific to Windows. - 0.8.13: addresses incorrect results returned by
PdfPageTextObject::chars()
as described in ajrcarey#98; adds newPdfPageTextSearch
andPdfSearchOptions
objects and newPdfPageText::search()
function for running text searches across the text of a single page, thanks to an excellent contribution from https://github.com/zhonghua-wang; adds newexamples/text_search.rs
example. - 0.8.12: improves backwards compatibility with Rust versions prior to 1.62.0 for the
PdfAppearanceMode
enum added in 0.8.11 and theOrd
trait implementation forPdfPoints
added in 0.8.10; adds bindings forFPDF_PageToDevice()
andFPDF_DeviceToPage()
coordinate system conversion functions; exposes equivalent functionality in the high-level interface via newPdfPage::points_to_pixels()
andPdfPage::pixels_to_points()
functions; adds newexamples/export_clip_crop.rs
example; extends implementation ofPdfium::default()
to try to load a Pdfium library located in the current working directory as well as a system library. - 0.8.11: adds the
PdfAppearanceMode
enum, thePdfFormFieldCommon::appearance_stream()
andPdfFormFieldCommon::appearance_mode_value()
functions, supporting internal implementation of those functions inPdfFormFieldPrivate
; improves implementation ofPdfFormRadioButtonField::is_checked()
to take appearance streams into account; improves implementation ofPdfForm::field_values()
to take control groups into account. - 0.8.10: adds matrix math operations to
PdfMatrix
; addsPdfRect::transform()
andPdfMatrix::apply_to_points()
functions for transforming rectangles and points; uses matrix math operations inPdfMatrix
to simplify implementation ofPdfRenderConfig
; addsPdfPagePathObjectSegments::raw()
andPdfPagePathObjectSegments::transform()
functions to allow iteration over raw or transformed path segment coordinates respectively; addsPdfDestinationViewSettings
enum andPdfDestination::view()
function for retrieving the view settings for an internal document destination. - 0.8.9: changes
Pdfium::bind_to_library()
andPdfium::pdfium_platform_library_name_at_path()
to take and returnAsRef<Path>
andPathBuf
types rather than strings, thanks to an excellent contribution from https://github.com/heimmat. - 0.8.8: adjusts
PdfiumRenderWasmState::bind_to_pdfium()
to fall back toModule["asm"]["malloc"]
andModule["asm"]["free"]
ifModule["_malloc"]
andModule["_free"]
are not available, in response to upstream packaging changes at https://github.com/paulocoutinhox/pdfium-lib/releases. For more details, see ajrcarey#95. - 0.8.7: renames
PdfBitmapFormat::BRGx
toPdfBitmapFormat::BGRx
, deprecating the misspelled variant; addsSend
andSync
implementations forPdfDocument
struct when using thesync
crate feature; addsDebug
trait implementation toPdfium
for betteronce_cell
compatibility; adds new constantsPdfPoints::MAX
,PdfPoints::MIN
, andPdfRect::MAX
; corrects a clipping bug inPdfPage::transform()
andPdfPage::set_matrix()
by setting the default clipping area toPdfRect::MAX
rather thanPdfPage::size()
. Deprecated items will be removed in release 0.9.0. - 0.8.6: fixes a bug in
PdfColor::as_pdfium_color()
that resulted in the alpha value being ignored when composing theFPDF_DWORD
representation of the color value; renamesPdfBitmapRotation
enum toPdfPageRenderRotation
, deprecating the old enum; adds convenience functionsPdfColor::mix()
,PdfColor::mix_with()
,PdfColor::from_hex()
,PdfColor::to_hex()
, andPdfColor::to_hex_with_alpha()
; adds a wide variety of new color constants toPdfColor
, deprecating all existingPdfColor::SOLID_*
consts in favour of renamed consts with theSOLID_
prefix removed; movesPdfPoints
andPdfRect
structs out into new files; addsPdfQuadPoints
struct; adds implementations ofDisplay
toPdfPoints
,PdfRect
, andPdfQuadPoints
; fixes a double-free bug inPdfPageImageObject::get_image_from_bitmap_handle()
. Deprecated items will be removed in release 0.9.0. - 0.8.5: adds
PdfDestination::page_index()
function; addsPdfPageObjectCommon::dash_phase()
PdfPageObjectCommon::set_dash_phase()
,PdfPageObjectCommon::dash_array()
, andPdfPageObjectCommon::set_dash_array()
functions thanks to an excellent contribution from https://github.com/DorianRudolph. - 0.8.4: fixes conditional import of
PdfPoints
struct intoPdfPageImageObject
so it is no longer dependent on theimage
crate feature being enabled; corrects a bug in the calculation of rendered bitmap pixel dimensions, thanks to an excellent contribution from https://github.com/slawekkolodziej. - 0.8.3: adds
PdfFonts
collection,PdfDocument::fonts()
andPdfDocument::fonts_mut()
accessor functions, andPdfFontToken
struct; moves font constructors fromPdfFont
intoPdfFonts
, deprecating constructors inPdfFont
; addsToPdfFontToken
trait, along with implementations of the trait forPdfFont
,&PdfFont
, andPdfFontToken
; adjusts all functions that previously took aPdfFont
or&PdfFont
reference so that they now take aimpl ToPdfFontToken
. Deprecated items inPdfFont
will be removed in release 0.9.0. - 0.8.2: adds
PdfBitmap::from_bytes()
function in response to ajrcarey#83; relaxes lifetime requirements onPdfium::load_pdf_from_reader()
and related functions thanks to an excellent contribution from https://github.com/bavardage. - 0.8.1: changes the data type of
PdfBitmap::Pixels
fromu16
toc_int
and adds thePdfBitmap::bytes_required_for_size()
helper function in response to ajrcarey#80. - 0.8.0: removes the ability to acquire an owned
PdfPages
instance fromPdfDocument::pages()
as per ajrcarey#47; adds newPdfDocument::pages_mut()
function to match reworkedPdfDocument::pages()
function; fixes a bug in the WASM implementation ofFPDFText_GetBoundedText()
as detailed in ajrcarey#77; reworks handling ofFPDF_GetLastError()
as detailed in ajrcarey#78. - 0.7.34: replaces functions in
PdfPageLinks
using linear traversal with binary search traversal; adds newPdfFormField
enum; renamesPdfPageObjectFormFragment
toPdfPageXObjectFormObject
to disambiguate it fromPdfForm
andPdfFormField
; addsPdfPageAnnotationCommon::as_form_field()
accessor function; adds form field structsPdfFormPushButtonField
,PdfFormCheckboxField
,PdfFormComboBoxField
,PdfFormListBoxField
,PdfFormRadioButtonField
,PdfFormSignatureField
,PdfFormTextField
, andPdfFormUnknownField
; addsPdfFormFieldOption
struct andPdfFormFieldOptions
collection for retrieving the options displayed within a list box or combo box field; addsPdfFormFieldCommon
andPdfFormFieldPrivate
traits and associated implementations for allPdfFormField
field types; adds thePdfForm::field_values()
convenience function; addsexamples/form_fields.rs
example. - 0.7.33: adds the
create_transform_setters!()
andcreate_transform_getters!()
private macros, ensuring API consistency and maximising code reuse across all transformable objects; addsPdfPage::transform()
,PdfPage::transform_with_clip()
, andPdfPage::set_matrix_with_clip()
functions; addsexamples/matrix.rs
example; adds bindings for remainingFPDF_*ClipPath*()
functions. - 0.7.32: fixes off-by-one errors in
PdfPageText::chars_inside_rect()
andexamples/chars.rs
thanks 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-render
without the defaultimage
crate feature. - 0.7.31: adds the
PdfPageLinks
collection, thePdfPage::links()
andPdfPage::links_mut()
functions, thePdfLink
andPdfDestination
structs, thePdfActionCommon
andPdfActionPrivate
traits, structs for the action types supported by Pdfium, thePdfActionUri::uri()
function to address ajrcarey#68, and the newexamples/links.rs
example. - 0.7.30: deprecates the
PdfPages::delete_page_at_index()
andPdfPages::delete_page_range()
functions; addsPdfPage::delete()
function in response to ajrcarey#67. Deprecated items will be removed in release 0.9.0, although it may be possible to restore these functions if safer reference handling inPdfDocument
andPdfPages
is introduced as part of ajrcarey#47. - 0.7.29: removes the
sync
crate feature from the list of default crate features in response to ajrcarey#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.rs
example; 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.html
to take into account upstream packaging changes in the WASM builds of Pdfium published at https://github.com/paulocoutinhox/pdfium-lib/releases; adds theimage
crate feature. - 0.7.26: adds
sync
default crate feature providingSend
andSync
implementations forPdfium
struct; addsDisplay
andError
trait implementations toPdfiumError
foranyhow
compatibility; 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
PdfPageAnnotationObjects
collection 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; addsPdfFontGlyphs
andPdfPagePathObjectSegments
collections to the high-level interface, along with accessor functions inPdfFont
andPdfPagePathObject
; adds thePdfPathSegments
trait; introduces some infrastructure necessary for the future implementation of aPdfClipPath
object; addsPdfPages::first()
,PdfPages::last()
, andPdfPage::fonts()
convenience functions. - 0.7.23: removes some unnecessary mutable bindings in
PdfBitmap
; uses#[cfg(doc)]
declarations to ensurecargo doc
generates 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 ajrcarey#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 ajrcarey#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; addsPdfAttachments
andPdfSignatures
collections 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.rs
andexamples/image_extract.rs
; renamesexamples/text.rs
toexamples/text_extract.rs
. - 0.7.14: fixes a bug in the WASM implementation of
FPDF_StructElement_GetStringAttribute()
; pins required version ofimage
crate to at least 0.24.0 or later to avoid incompatibility between theimage::DynamicImage
trait 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()
; deprecatesPdfBitmapConfig
in 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
PdfPageImageObject
that 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 thePdfColorSpace
enum; adds bindings for theFPDF_*Signature*()
,FPDFSignatureObj_*()
, andFPDF_StructTree_*()
functions. - 0.7.8: adds image support to the
PdfPageImageObject
struct, 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_safe
crate 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
PdfPageText
andPdfPageTextObject
objects; addsPdfPageTextSegment
andPdfPageTextChar
structs 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 ajrcarey#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
PdfPagePathObject
object, convenience functions for quickly creating rectangles, ellipses, and circles, and thePdfPageObjects::add_path_object()
function. - 0.7.0: adds
PdfPermissions
collection, 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
bindgen
andstatic
crate features. - 0.5.6: adds
pdfium_render::prelude
, adds bindings forFPDFAnnot_*()
andFPDFPage_*Annot*()
functions, addsPdfPageAnnotations
collection andPdfPageAnnotation
struct 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 ajrcarey#9 and ajrcarey#11 for more information.
- 0.5.4: changes default setting of
PdfBitmapConfig::set_reverse_byte_order()
totrue
to switch from Pdfium's default BGRA8 pixel format to RGBA8. This is necessary since theimage
crate dropped support for BGRA8 in version 0.24. See ajrcarey#9 for more information. - 0.5.3: adds bindings for
FPDFBookmark_*()
,FPDFPageObj_*()
,FPDFText_*()
, andFPDFFont_*()
functions, addsPdfPageObjects
,PdfPageText
, andPdfBookmarks
collections to the high-level interface. - 0.5.2: adds bindings for
FPDF_GetPageBoundingBox()
,FPDFDoc_GetPageMode()
,FPDFPage_Get*Box()
, andFPDFPage_Set*Box()
functions, addsPdfPageBoundaries
collection to the high-level interface. - 0.5.1: adds bindings for
FPDFPage_GetRotation()
andFPDFPage_SetRotation()
functions, addsPdfMetadata
collection 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
PdfBitmapConfig
implementation. - 0.4.1: improvements to documentation and READMEs.
- 0.4.0: initial release of minimal page rendering functionality.