Skip to content

Commit

Permalink
Progressing #47
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Oct 18, 2022
1 parent 58c146a commit 9a086cc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 55 deletions.
58 changes: 3 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,61 +210,9 @@ See <https://github.com/ajrcarey/pdfium-render/tree/master/examples> 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 `<input type="file">` 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 `<canvas>` 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 `<input type="file">`
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 `<input type="file">`
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 `<input type="file">` 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 <https://github.com/ajrcarey/pdfium-render/tree/master/examples>.

## Multithreading

Expand Down
74 changes: 74 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<input type="file">` 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 `<canvas>` 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 `<input type="file">`
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 `<input type="file">`
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 `<input type="file">` 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.

0 comments on commit 9a086cc

Please sign in to comment.