GithubHelp home page GithubHelp logo

fanxiaowei / wasm-pdf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jussiniinikoski/wasm-pdf

0.0 0.0 0.0 627 KB

Generate PDF files with JavaScript and WASM (WebAssembly)

License: Apache License 2.0

JavaScript 1.58% Rust 97.18% HTML 1.23%

wasm-pdf's Introduction

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

  • 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 can also be used standalone in a non-browser environment

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)

  • First install the Rust compiler
  • 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)

Special Thanks

License

This project is licensed under either of

wasm-pdf's People

Contributors

jussiniinikoski avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.