rse / node-prince

Node API for executing PrinceXML via prince(1) CLI
https://npmjs.com/prince
49 stars 24 forks source link
css generation html javascript pdf princexml wrapper xml

Node-Prince

Node API for executing the XML/HTML to PDF renderer PrinceXML via prince CLI.

Abstract

This is a Node API for executing the XML/HTML to PDF renderer PrinceXML CLI prince from within JavaScript. The essential point of this Node extension is not primarily to just abstract away the asynchronous CLI execution. Instead there are two other major points: First, this Node extension provides a fixed dependency, as other Node extensions which require PrinceXML can just depend (via their NPM package.json file) onto this extension. Second, as this Node extension can — across platforms — automatically download, locally unpack and use a PrinceXML distribution, there is no need for any previously available global PrinceXML installation. Just depend on this Node extension and PrinceXML is available!

Installation

Use the Node Package Manager (NPM) to install this module locally (default) or globally (with option -g):

$ npm install [-g] prince

ATTENTION: In case you are behind a corporate firewall, you usually have to configure your corporate proxy before installing this module. For this, either configure the proxy inside NPM (e.g. npm config set proxy http://proxy.example.com:3128) or alternatively set the environment variable http_proxy (e.g. export http_proxy=http://proxy.example.com:3128).

NOTICE: PrinceXML provides just distribution-specific and dynamically linked Linux binaries. The Node-Prince installation procedure tries to detect your particular distribution on npm install [-g] prince and downloads the corresponding binary. But because of the dynamic linking of PrinceXML binaries, it still can be that you first have to install some distribution-specific system dependencies. For instance, under Debian 8.0 you first have to install the necessary system packages with apt-get install nodejs nodejs-legacy npm libgif4 curl.

Usage

const Prince = require("prince")
const util   = require("util")

Prince()
    .inputs("test.html")
    .output("test.pdf")
    .execute()
    .then(function () {
        console.log("OK: done")
    }, function (error) {
        console.log("ERROR: ", util.inspect(error))
    })

API

See Also

Companion Grunt task grunt-princess

License

Copyright © 2014-2024 Dr. Ralf S. Engelschall (http://engelschall.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.