Skip to content

Commit

Permalink
Progressing #77
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Mar 17, 2023
1 parent e30eec2 commit 524019d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 46 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ a PDF document longer than just a few pages will result in an unrecoverable out
The WASM builds of Pdfium at <https://github.com/paulocoutinhox/pdfium-lib/releases> are recommended
as they do not have this problem.

## Multithreading
## Multi-threading

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,
Expand Down Expand Up @@ -335,7 +335,7 @@ functions related to page rendering were prioritised. By 1.0, the functionality
`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.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`.
Expand All @@ -356,7 +356,8 @@ at <https://github.com/ajrcarey/pdfium-render/issues>.

* 0.8.0: removes the ability to acquire an owned `PdfPages` instance from `PdfDocument::pages()`
as per <https://github.com/ajrcarey/pdfium-render/issues/47>; adds new `PdfDocument::pages_mut()`
function to match reworked `PdfDocument::pages()` function.
function to match reworked `PdfDocument::pages()` function; fixes a bug in the WASM implementation
of `FPDFText_GetBoundedText` as detailed at <https://github.com/ajrcarey/pdfium-render/issues/77>.
* 0.7.34: replaces functions in `PdfPageLinks` using linear traversal with binary search traversal;
adds new `PdfFormField` enum; renames `PdfPageObjectFormFragment` to `PdfPageXObjectFormObject`
to disambiguate it from `PdfForm` and `PdfFormField`; adds `PdfPageAnnotationCommon::as_form_field()`
Expand Down
101 changes: 59 additions & 42 deletions examples/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,73 +30,90 @@ pub async fn log_page_metrics_to_console(url: String) {
log::info!("PDF file version: {:#?}", document.version());

log::info!("PDF metadata tags:");

document
.metadata()
.iter()
.enumerate()
.for_each(|(index, tag)| log::info!("{}: {:#?} = {}", index, tag.tag_type(), tag.value()));

let pages = document.pages();

match document.form() {
Some(form) => log::info!(
"PDF contains an embedded form of type {:#?}",
form.form_type()
),
Some(form) => {
log::info!(
"PDF contains an embedded form of type {:#?}",
form.form_type()
);

for (key, value) in form.field_values(&pages).iter() {
log::info!("{:?} => {:?}", key, value);
}
}
None => log::info!("PDF does not contain an embedded form"),
};

// Report labels, boundaries, and metrics for each page to the console.

document
.pages()
.iter()
.enumerate()
.for_each(|(page_index, page)| {
if let Some(label) = page.label() {
log::info!("Page {} has a label: {}", page_index, label);
}
pages.iter().enumerate().for_each(|(page_index, page)| {
if let Some(label) = page.label() {
log::info!("Page {} has a label: {}", page_index, label);
}

log::info!(
"Page {} width: {}, height: {}",
page_index,
page.width().value,
page.height().value
);

for boundary in page.boundaries().iter() {
log::info!(
"Page {} width: {}, height: {}",
"Page {} has defined {:#?} box ({}, {}) - ({}, {})",
page_index,
page.width().value,
page.height().value
boundary.box_type,
boundary.bounds.left.value,
boundary.bounds.top.value,
boundary.bounds.right.value,
boundary.bounds.bottom.value,
);
}

for boundary in page.boundaries().iter() {
log::info!(
"Page {} has defined {:#?} box ({}, {}) - ({}, {})",
page_index,
boundary.box_type,
boundary.bounds.left.value,
boundary.bounds.top.value,
boundary.bounds.right.value,
boundary.bounds.bottom.value,
);
}
log::info!(
"Page {} has paper size {:#?}",
page_index,
page.paper_size()
);

for (link_index, link) in page.links().iter().enumerate() {
log::info!(
"Page {} has paper size {:#?}",
"Page {} link {} has action of type {:?}",
page_index,
page.paper_size()
link_index,
link.action().map(|action| action.action_type())
);

for (link_index, link) in page.links().iter().enumerate() {
log::info!(
"Page {} link {} has action of type {:?}",
page_index,
link_index,
link.action().map(|action| action.action_type())
);
// For links that have URI actions, output the destination URI.

// For links that have URI actions, output the destination URI.

if let Some(action) = link.action() {
if let Some(uri_action) = action.as_uri_action() {
log::info!("Link URI destination: {:#?}", uri_action.uri())
}
if let Some(action) = link.action() {
if let Some(uri_action) = action.as_uri_action() {
log::info!("Link URI destination: {:#?}", uri_action.uri())
}
}
});
}

let text = page.text().unwrap();

for (annotation_index, annotation) in page.annotations().iter().enumerate() {
log::info!(
"Page {} annotation {} has text: {:?}, bounds: {:?}",
page_index,
annotation_index,
text.for_annotation(&annotation),
annotation.bounds()
);
}
});
}

/// Downloads the given url, opens it as a PDF document, then returns the ImageData for
Expand Down
4 changes: 3 additions & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7534,7 +7534,9 @@ impl PdfiumLibraryBindings for WasmPdfiumBindings {
.unwrap() as usize;

if result > 0 && result <= buffer_length {
state.copy_struct_from_pdfium(buffer_ptr, result, buffer);
// The return result is the number of _characters_ returned, _not_ the number of bytes.

state.copy_struct_from_pdfium(buffer_ptr, result * size_of::<c_ushort>(), buffer);
}

state.free(buffer_ptr);
Expand Down

0 comments on commit 524019d

Please sign in to comment.