Skip to content

Commit

Permalink
Progressing #137
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Aug 15, 2024
1 parent 1a855fe commit 81caaed
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pdfium-render"
version = "0.8.24"
version = "0.8.25"
edition = "2018"
publish = true
description = "A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project."
Expand All @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0"
keywords = ["pdf", "pdfium"]
categories = ["api-bindings", "multimedia::images", "visualization", "wasm"]
authors = ["Alastair Carey <alastair@alastaircarey.com>"]
exclude = ["test/*.pdf"]

[lib]
name = "pdfium_render"
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ functions specific to interactive scripting, user interaction, and printing.
* 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
There are 377 `FPDF_*` functions in the Pdfium API. As of version 0.8.25, 338 (90%) have
bindings available in `PdfiumLibraryBindings`, with the functionality of the majority of these
available via the `pdfium-render` high-level interface.

Expand All @@ -367,19 +367,25 @@ at <https://github.com/ajrcarey/pdfium-render/issues>.

## Version history

* 0.8.24: introduced crate feature flags for selecting Pdfium API versions to use in
* 0.8.25: adds bindings for `FPDFAnnot_GetFormAdditionalActionJavaScript()`,
`FPDFAnnot_GetFormFieldAlternateName()`, `FPDFAnnot_GetFileAttachment()`, and
`FPDFAnnot_AddFileAttachment()`.
* 0.8.24: introduces crate feature flags for selecting Pdfium API versions to use in
`PdfiumLibraryBindings`; reworked `build.rs` to output bindings for multiple sets of Pdfium header
files; reworked bindings implementations to differentiate between API versions that include the
files; reworks bindings implementations to differentiate between API versions that include the
`FPDFFont_*` and `FPDFText_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
adds WASM bindings utility function `copy_string_to_pdfium()` to correctly copy the string data of an
`FPDF_WIDESTRING` to Pdfium's WASM memory module, instead of just the pointer location;
adds `PdfiumLibraryBindings::version()` function for reporting the currently configured API version;
internally reorganized source code layout to make the code structure clearer.
* 0.8.23: synchronizes Pdfium API header files against mainline; removes binding for function
`FPDFText_GetTextRenderMode()` in response to upstream change described at
<https://github.com/ajrcarey/pdfium-render/issues/151>; adds bindings for `FPDFText_GetTextObject()`,
`FPDFFont_GetFamilyName()`, `FPDFFont_GetIsEmbedded()`, and `FPDFFont_GetFontData()` functions;
deprecates `PdfFont::name()` function in favour of `PdfFont::family()` to match upstream naming
changes; adds new functions `PdfFont::is_embedded()` and `PdfFont::data()` for retrieving embedded font data; updates `examples/fonts.rs` example; adds new function `PdfPageTextChar::text_object()`
for retrieving the page object containing a specific character; adds WASM bindings utility function
`copy_string_to_pdfium()` to correctly copy the string data of an `FPDF_WIDESTRING` to Pdfium's WASM memory module, instead of just the pointer location. Deprecated items will be removed in release 0.9.0.
for retrieving the page object containing a specific character. 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 for `FPDF_GetPageSizeByIndexF()`, thanks to an excellent
contribution from <https://github.com/DorianRudolph>; updates all examples and tests that reference
Expand Down
137 changes: 137 additions & 0 deletions src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ pub trait PdfiumLibraryBindings {
#[allow(non_snake_case)]
fn FPDFPage_GenerateContent(&self, page: FPDF_PAGE) -> FPDF_BOOL;

#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
#[allow(clippy::too_many_arguments)]
fn FPDFPage_TransformAnnots(
Expand Down Expand Up @@ -1328,6 +1329,63 @@ pub trait PdfiumLibraryBindings {
border_width: *mut c_float,
) -> FPDF_BOOL;

/// Get the JavaScript of an event of the annotation's additional actions.
///
/// `buffer` is only modified if `buflen` is large enough to hold the whole
/// JavaScript string. If `buflen` is smaller, the total size of the JavaScript
/// is still returned, but nothing is copied. If there is no JavaScript for
/// `event` in `annot`, an empty string is written to `buf` and 2 is returned,
/// denoting the size of the null terminator in the buffer. On other errors,
/// nothing is written to `buffer` and 0 is returned.
///
/// `hHandle` - handle to the form fill module, returned by
/// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment()].
///
/// `annot` - handle to an interactive form annotation.
///
/// `event` - event type, one of the `FPDF_ANNOT_AACTION_*` values.
///
/// `buffer` - buffer for holding the value string, encoded in UTF-16LE.
///
/// `buflen` - length of the buffer in bytes.
///
/// Returns the length of the string value in bytes, including the 2-byte null terminator.
#[allow(non_snake_case)]
fn FPDFAnnot_GetFormAdditionalActionJavaScript(
&self,
hHandle: FPDF_FORMHANDLE,
annot: FPDF_ANNOTATION,
event: c_int,
buffer: *mut FPDF_WCHAR,
buflen: c_ulong,
) -> c_ulong;

/// Gets the alternate name of `annot`, which is an interactive form annotation.
///
/// `buffer` is only modified if `buflen` is longer than the length of contents.
/// In case of error, nothing will be added to `buffer` and the return value will be 0.
/// Note that return value of empty string is 2 for `\0\0`.
///
/// `hHandle` - handle to the form fill module, returned by
/// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment()].
///
/// `annot` - handle to an interactive form annotation.
///
/// `buffer` - buffer for holding the alternate name string, encoded in
/// UTF-16LE.
///
/// `buflen` - length of the buffer in bytes.
///
/// Returns the length of the string value in bytes.
#[allow(non_snake_case)]
fn FPDFAnnot_GetFormFieldAlternateName(
&self,
hHandle: FPDF_FORMHANDLE,
annot: FPDF_ANNOTATION,
buffer: *mut FPDF_WCHAR,
buflen: c_ulong,
) -> c_ulong;

/// Check if `annot`'s dictionary has `key` as a key.
///
/// `annot` - handle to an annotation.
Expand Down Expand Up @@ -1894,6 +1952,80 @@ pub trait PdfiumLibraryBindings {
#[allow(non_snake_case)]
fn FPDFAnnot_SetURI(&self, annot: FPDF_ANNOTATION, uri: &str) -> FPDF_BOOL;

/// Get the attachment from `annot`.
///
/// `annot` - handle to a file annotation.
///
/// Returns the handle to the attachment object, or NULL on failure.
#[cfg(any(
feature = "pdfium_6337",
feature = "pdfium_6406",
feature = "pdfium_6490",
feature = "pdfium_6555",
feature = "pdfium_6569",
feature = "pdfium_6611",
feature = "pdfium_future"
))]
#[allow(non_snake_case)]
fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT;

/// Add an embedded file with `name` to `annot`.
///
/// `annot` - handle to a file annotation.
///
/// `name` - name of the new attachment.
///
/// Returns a handle to the new attachment object, or NULL on failure.
///
/// A [&str]-friendly helper function is available for this function.
/// See [PdfiumLibraryBindings::FPDFAnnot_AddFileAttachment_str].
#[cfg(any(
feature = "pdfium_6337",
feature = "pdfium_6406",
feature = "pdfium_6490",
feature = "pdfium_6555",
feature = "pdfium_6569",
feature = "pdfium_6611",
feature = "pdfium_future"
))]
#[allow(non_snake_case)]
fn FPDFAnnot_AddFileAttachment(
&self,
annot: FPDF_ANNOTATION,
name: FPDF_WIDESTRING,
) -> FPDF_ATTACHMENT;

/// A [&str]-friendly helper function for [PdfiumLibraryBindings::FPDFAnnot_AddFileAttachment].
///
/// Add an embedded file with `name` to `annot`.
///
/// `annot` - handle to a file annotation.
///
/// `name` - name of the new attachment.
///
/// Returns a handle to the new attachment object, or NULL on failure.
#[cfg(any(
feature = "pdfium_6337",
feature = "pdfium_6406",
feature = "pdfium_6490",
feature = "pdfium_6555",
feature = "pdfium_6569",
feature = "pdfium_6611",
feature = "pdfium_future"
))]
#[inline]
#[allow(non_snake_case)]
fn FPDFAnnot_AddFileAttachment_str(
&self,
annot: FPDF_ANNOTATION,
name: &str,
) -> FPDF_ATTACHMENT {
self.FPDFAnnot_AddFileAttachment(
annot,
get_pdfium_utf16le_bytes_from_str(name).as_ptr() as FPDF_WIDESTRING,
)
}

/// Initializes the form fill environment.
///
/// `document` - Handle to document from [PdfiumLibraryBindings::FPDF_LoadDocument].
Expand Down Expand Up @@ -1929,6 +2061,7 @@ pub trait PdfiumLibraryBindings {
///
/// `hHandle` - Handle to the form fill module, as returned by
/// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment].
#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
fn FORM_OnAfterLoadPage(&self, page: FPDF_PAGE, hHandle: FPDF_FORMHANDLE);

Expand All @@ -1939,6 +2072,7 @@ pub trait PdfiumLibraryBindings {
///
/// `hHandle` - Handle to the form fill module, as returned by
/// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment].
#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
fn FORM_OnBeforeClosePage(&self, page: FPDF_PAGE, hHandle: FPDF_FORMHANDLE);

Expand Down Expand Up @@ -2042,6 +2176,7 @@ pub trait PdfiumLibraryBindings {
/// (open state). If the value is negative, child items shall be hidden by
/// default (closed state). Please refer to PDF 32000-1:2008, Table 153.
/// Returns 0 if the bookmark has no children or is invalid.
#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
fn FPDFBookmark_GetCount(&self, bookmark: FPDF_BOOKMARK) -> c_int;

Expand Down Expand Up @@ -2388,6 +2523,7 @@ pub trait PdfiumLibraryBindings {
///
/// If this function returns a valid handle, it is valid as long as `page` is
/// valid.
#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
fn FPDF_GetPageAAction(&self, page: FPDF_PAGE, aa_type: c_int) -> FPDF_ACTION;

Expand Down Expand Up @@ -3659,6 +3795,7 @@ pub trait PdfiumLibraryBindings {
/// `document` - handle to a document.
///
/// Returns `true` if `document` is a tagged PDF.
#[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))]
#[allow(non_snake_case)]
fn FPDFCatalog_IsTagged(&self, document: FPDF_DOCUMENT) -> FPDF_BOOL;
}
Expand Down
Loading

0 comments on commit 81caaed

Please sign in to comment.