diff --git a/README.md b/README.md index 6dba100..b99ce35 100644 --- a/README.md +++ b/README.md @@ -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 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, @@ -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`. @@ -356,7 +356,8 @@ at . * 0.8.0: removes the ability to acquire an owned `PdfPages` instance from `PdfDocument::pages()` as per ; 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 . * 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()` diff --git a/examples/wasm.rs b/examples/wasm.rs index 22d4535..32f19bb 100644 --- a/examples/wasm.rs +++ b/examples/wasm.rs @@ -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 diff --git a/src/wasm.rs b/src/wasm.rs index e23da0c..79893cc 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -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::(), buffer); } state.free(buffer_ptr);