Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jussiniinikoski/wasm-pdf
Generate PDF files with JavaScript and WASM (WebAssembly)
https://github.com/jussiniinikoski/wasm-pdf
javascript pdf pdf-generation rust rust-wasm wasm wasm-bindgen webassembly
Last synced: 3 months ago
JSON representation
Generate PDF files with JavaScript and WASM (WebAssembly)
- Host: GitHub
- URL: https://github.com/jussiniinikoski/wasm-pdf
- Owner: jussiniinikoski
- License: apache-2.0
- Archived: true
- Created: 2019-05-31T15:16:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-09T09:01:00.000Z (over 1 year ago)
- Last Synced: 2024-09-29T16:06:24.509Z (4 months ago)
- Topics: javascript, pdf, pdf-generation, rust, rust-wasm, wasm, wasm-bindgen, webassembly
- Language: Rust
- Homepage:
- Size: 612 KB
- Stars: 478
- Watchers: 6
- Forks: 51
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-rust-cn - WASM-PDF - ci.org/jussiniinikoski/wasm-pdf.svg?branch=master">](https://travis-ci.org/jussiniinikoski/wasm-pdf) (Libraries / Graphics)
- awesome-rust - WASM-PDF - ci.org/jussiniinikoski/wasm-pdf.svg?branch=master">](https://travis-ci.org/jussiniinikoski/wasm-pdf) (Libraries / Graphics)
- awesome-rust-cn - WASM-PDF
- awesome-rust-zh - WASM-PDF - ci.org/jussiniinikoski/wasm-pdf.svg?branch=master">](https://travis-ci.org/jussiniinikoski/wasm-pdf) (εΊ / εΎε)
- awesome-client-side - WASM-PDF - Generate PDF files with JavaScript and WASM (WebAssembly) - [Try it!](https://jussiniinikoski.github.io/wasm-pdf-demo/example2.html) (PDF / Video)
README
# WASM-PDF
## Generates PDF files directly in the browser with JavaScript and WASM (WebAssembly).[![Build Status](https://travis-ci.org/jussiniinikoski/wasm-pdf.svg?branch=master)](https://travis-ci.org/jussiniinikoski/wasm-pdf)
Idea here is to push all the work involved in creating a PDF to the browser side, instead of using precious server resources.
## Demos
[Example that generates a sample PDF document from JSON file.](https://jussiniinikoski.github.io/wasm-pdf-demo/) Title in PDF is changed dynamically (in JavaScript) to show current date. **Note:** this example routes directly to the PDF data blob, so 2 backsteps are needed to return to this page.
[Another example that generates 400 paragraphs of Lorem Ipsum](https://jussiniinikoski.github.io/wasm-pdf-demo/example2.html) and shows a download link when document has been generated (which is instantly π). Also shows page numbers.
[This example creates a task calendar.](https://jussiniinikoski.github.io/wasm-pdf-demo/example3.html)
## Features
* PDF contents are described as a JavaScript object and that gets passed to WASM-module, which generates the output
* Customizable output handler (e.g. load blob URL to a link or directly to window)
* Currently supported elements include:
* Paragraphs/text elements with basic fonts (Helvetica, Times, Courier)
* Images loaded from URL (converted automatically to bytes)
* Tables with rows and cells
* Spacers (they just eat space)
* Paths with points, strokes, fills and alignment
* Basic styling (all styling parameters are optional)
* Custom template size (defaults to A4 portrait with 50 px margins)
* Page numbers and stationary text can be included in template
* Inline links and bold text (a and b tags) inside paragraph text
* [The generator crate](./crates/wasm-pdf-gen/) can also be used standalone in a non-browser environment## Example input (JSON)
```json
{
"title": "Example Document",
"contents": [{
"obj_type": "Paragraph",
"params": {
"text": "Hello World!",
"font_size": 18,
"leading": 24,
"align": "center",
"font_name": "Helvetica-Bold"
}
}
]
}
```## How to generate an example PDF
### Option 1 (with Rust)
* First install [the Rust compiler](https://www.rust-lang.org)
* Clone this repo:```git clone https://github.com/jussiniinikoski/wasm-pdf.git```
* Change to directory: ```cd wasm-pdf```
* Install JavaScript libraries: ```npm install```
* Launch the local development server: ```npm run serve```
* Open your browser and visit the url provided by the server, usually ```http://localhost:8080```### Option 2 (with JavaScript only / npm package)
* Go to [starter template repo](https://github.com/jussiniinikoski/wasm-pdf-app/)## Special Thanks
* [rustwasm/wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)
* [kaj/rust-pdf](https://github.com/kaj/rust-pdf)
* [emreyaren/zero85](https://github.com/emreyaren/zero85)## License
This project is licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)