jussiniinikoski / wasm-pdf

Generate PDF files with JavaScript and WASM (WebAssembly)
Apache License 2.0
479 stars 51 forks source link
javascript pdf pdf-generation rust rust-wasm wasm wasm-bindgen webassembly

WASM-PDF

Generates PDF files directly in the browser with JavaScript and WASM (WebAssembly).

Build Status

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. 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 and shows a download link when document has been generated (which is instantly 🙂). Also shows page numbers.

This example creates a task calendar.

Features

Example input (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)

Option 2 (with JavaScript only / npm package)

Special Thanks

License

This project is licensed under either of