diff --git a/README.md b/README.md index 9984223..d626273 100644 --- a/README.md +++ b/README.md @@ -210,61 +210,9 @@ See for a full 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. -The `Pdfium::load_pdf_from_file()` and `Pdfium::load_pdf_from_reader()` functions are not available -when running in the browser. The `Pdfium::load_pdf_from_bytes()` function is available, and -the following additional functions are provided: - -* The `Pdfium::load_pdf_from_fetch()` function uses the browser's built-in `fetch()` API - to download a URL over the network and open it as a PDF document. -* The `Pdfium::load_pdf_from_blob()` function opens a PDF document from the byte data in a Javascript - `Blob` or `File` object, including `File` objects returned from an `` element. - -The `PdfDocument::save_to_file()` function is not available when running in the browser. -The `PdfDocument::save_to_bytes()` and `PdfDocument::save_to_writer()` functions are -available, and the following additional function is provided: - -* The `PdfDocument::save_to_blob()` function returns the byte data for the document as a - Javascript `Blob` object. - -The following additional functions are provided during rendering: - -* The `PdfBitmap::as_image_data()` function renders directly to a Javascript `ImageData` object, - ready to display in an HTML `` element. -* The `PdfBitmap::as_array()` function renders directly to a Javascript `Uint8Array` object. - This function avoids a memory allocation and copy required by both `PdfBitmap::as_bytes()` - and `PdfBitmap::as_image_data()`, making it preferable for situations where performance is paramount. - -The `PdfFont::load_type1_from_file()` and `PdfFont::load_true_type_from_file()` functions are -not available when running in the browser. The following additional functions are provided: - -* The `PdfFont::load_type1_from_fetch()` function uses the browser's built-in `fetch()` API - to download a URL over the network and load it as a Type 1 font. -* The `PdfFont::load_true_type_from_fetch()` function uses the browser's built-in `fetch()` API - to download a URL over the network and load it as a TrueType font. -* The `PdfFont::load_type1_from_blob()` function loads a Type 1 font from the byte data in a - Javascript `Blob` or `File` object, including `File` objects returned from an `` - element. -* The `PdfFont::load_true_type_from_blob()` function loads a TrueType font from the byte data in a - Javascript `Blob` or `File` object, including `File` objects returned from an `` - element. - -The `PdfAttachments::create_attachment_from_file()` function is not available when running in -the browser. The `PdfAttachments::create_attachment_from_bytes()` and -`PdfAttachments::create_attachment_from_reader()` functions are available, and -the following additional functions are provided: - -* The `PdfAttachments::create_attachment_from_fetch()` function uses the brower's built-in `fetch()` API - to download a URL over the network and use it as an embedded attachment. -* The `PdfAttachments::create_attachment_from_blob()` function creates an embedded attachment - from the byte data in a Javascript `Blob` or `File` object, including `File` objects returned from - an `` element. - -The `PdfAttachment::save_to_file()` function is not available when running in the browser. -The `PdfAttachment::save_to_bytes()` and `PdfAttachment::save_to_writer()` functions are -available, and the following additional function is provided: - -* The `PdfAttachment::save_to_blob()` function returns the byte data for the attachment as a - Javascript `Blob` object. +Certain functions that access the filesystem are not available when compiling to WASM. Browser-specific +equivalents are provided instead. A complete list of functional differences between native and WASM +is available at . ## Multithreading diff --git a/examples/README.md b/examples/README.md index 3e57095..7c58074 100644 --- a/examples/README.md +++ b/examples/README.md @@ -45,3 +45,77 @@ WASM modules and bind them together dynamically at run time. The basic recipe is * Once Pdfium is instantiated, load and instantiate the WASM module for your compiled Rust application. * Once your WASM module is instantiated, call `pdfium-render`'s exported `initialize_pdfium_render()` function, passing it both instantiated WASM modules. * You can now call any Pdfium-related functions exported by your compiled Rust application. + +## Interface changes when compiling to WASM + +Certain `pdfium-render` functions that access the filesystem are not available when compiling to WASM, +due to the security model present in modern web browsers. Alternative functions for accessing files +over the network are provided instead. + +### Interface changes in the `Pdfium` struct + +The `Pdfium::load_pdf_from_file()` and `Pdfium::load_pdf_from_reader()` functions are not available +when running in the browser. The `Pdfium::load_pdf_from_bytes()` function is available, and +the following additional functions are provided: + +* The `Pdfium::load_pdf_from_fetch()` function uses the browser's built-in `fetch()` API + to download a URL over the network and open it as a PDF document. +* The `Pdfium::load_pdf_from_blob()` function opens a PDF document from the byte data in a Javascript + `Blob` or `File` object, including `File` objects returned from an `` element. + +### Interface changes in the `PdfDocument` struct + +The `PdfDocument::save_to_file()` function is not available when running in the browser. +The `PdfDocument::save_to_bytes()` and `PdfDocument::save_to_writer()` functions are +available, and the following additional function is provided: + +* The `PdfDocument::save_to_blob()` function returns the byte data for the document as a + Javascript `Blob` object. + +### Interface changes in the `PdfBitmap` struct + +The following additional functions are provided during rendering: + +* The `PdfBitmap::as_image_data()` function renders directly to a Javascript `ImageData` object, + ready to display in an HTML `` element. +* The `PdfBitmap::as_array()` function renders directly to a Javascript `Uint8Array` object. + This function avoids a memory allocation and copy required by both `PdfBitmap::as_bytes()` + and `PdfBitmap::as_image_data()`, making it preferable for situations where performance is paramount. + +### Interface changes in the `PdfFont` struct + +The `PdfFont::load_type1_from_file()` and `PdfFont::load_true_type_from_file()` functions are +not available when running in the browser. The following additional functions are provided: + +* The `PdfFont::load_type1_from_fetch()` function uses the browser's built-in `fetch()` API + to download a URL over the network and load it as a Type 1 font. +* The `PdfFont::load_true_type_from_fetch()` function uses the browser's built-in `fetch()` API + to download a URL over the network and load it as a TrueType font. +* The `PdfFont::load_type1_from_blob()` function loads a Type 1 font from the byte data in a + Javascript `Blob` or `File` object, including `File` objects returned from an `` + element. +* The `PdfFont::load_true_type_from_blob()` function loads a TrueType font from the byte data in a + Javascript `Blob` or `File` object, including `File` objects returned from an `` + element. + +### Interface changes in the `PdfAttachments` struct + +The `PdfAttachments::create_attachment_from_file()` function is not available when running in +the browser. The `PdfAttachments::create_attachment_from_bytes()` and +`PdfAttachments::create_attachment_from_reader()` functions are available, and +the following additional functions are provided: + +* The `PdfAttachments::create_attachment_from_fetch()` function uses the brower's built-in `fetch()` API + to download a URL over the network and use it as an embedded attachment. +* The `PdfAttachments::create_attachment_from_blob()` function creates an embedded attachment + from the byte data in a Javascript `Blob` or `File` object, including `File` objects returned from + an `` element. + +### Interface changes in the `PdfAttachment` struct + +The `PdfAttachment::save_to_file()` function is not available when running in the browser. +The `PdfAttachment::save_to_bytes()` and `PdfAttachment::save_to_writer()` functions are +available, and the following additional function is provided: + +* The `PdfAttachment::save_to_blob()` function returns the byte data for the attachment as a + Javascript `Blob` object.