jeroencoumans / electron-pdf

A command line tool to generate PDF from URL, HTML or Markdown files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

electron-pdf

NPM version build status Downloads js-standard-style

A command line tool to generate PDF from URL, HTML or Markdown files with electron.

I have a blog post explain why PDF Generation On The Web

Production ready? See it in action for the Myanmar Election!

Install

npm install electron-pdf -g

For gnu/linux installations without a graphical environment:

$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
$ electron-pdf ...

There is also an example docker machine here.

Usage

To generate a PDF from a HTML file

$ electron-pdf index.html ~/Desktop/index.pdf

To generate a PDF from a Markdown file

$ electron-pdf index.md ~/Desktop/index.pdf

To generate a PDF from a Markdown file with custom CSS(defaut to Github markdown style)

$ electron-pdf index.html ~/Desktop/index.pdf -c my-awesome-css.css

To generate a PDF from a URL

$ electron-pdf https://fraserxu.me ~/Desktop/fraserxu.pdf

To generate a PDF from within a Docker container

$ docker build -t electron-pdf .
$ docker run electron-pdf
$ docker cp electron-pdf:/app/test.pdf docker-test.pdf .

To run a test inside Docker

$ docker run -i -t electron-pdf /bin/bash
$ Xvfb -ac -screen scrn 1280x2000x24 :9.0 & export DISPLAY=:9.0
$ ./cli.js test.html test.pdf -W ready -w 5000

More


  A command line tool to generate PDF from URL, HTML or Markdown files

  Options
    --help                     Show this help
    --version                  Current version of package
    -i | --input               String - The path to the HTML file or url
    -o | --output              String - The path of the output PDF
    -c | --css                 String - The path to custom CSS
    -b | --printBackground     Boolean - Whether to print CSS backgrounds.
                                 false - true
    -s | --printSelectionOnly  Boolean - Whether to print selection only
                                 false - default
    -p | --pageSize            String - Can be A3, A4, A5, Legal, Letter, Tabloid or an Object containing height and width in microns
                                "A4" - default
    -l | --landscape           Boolean - true for landscape, false for portrait.
                                 false - default
    -m | --marginsType          Integer - Specify the type of margins to use
                                 0 - default
                                 1 - none
                                 2 - minimum
    -d | --disableCache        Disable HTTP caching
    -w | --outputWait          Integer – Time to wait (in MS) between page load and PDF creation
                                 0 - default
    -W | --waitForTitle        String - Wait until window.title is equal to this string before rendering page, or until outputWait is done, whichever occurs first. If no outputWait is provided, a default time out of 30 seconds will be used.
                                 false - default


  Usage
    $ electron-pdf <input> <output>
    $ electron-pdf <input> <output> -l

  Examples
    $ electron-pdf http://fraserxu.me ~/Desktop/fraserxu.pdf
    $ electron-pdf ./index.html ~/Desktop/index.pdf
    $ electron-pdf ./README.md ~/Desktop/README.pdf -l
    $ electron-pdf ./README.md ~/Desktop/README.pdf -l -c my-awesome-css.css

Inspired by electron-mocha

License

MIT

About

A command line tool to generate PDF from URL, HTML or Markdown files.

License:MIT License


Languages

Language:JavaScript 95.6%Language:HTML 4.4%