Git Product home page Git Product logo

node-prince's Introduction

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

  • Prince([options]): Prince: constructor for the API. Call this once for every XML/HTML to PDF conversion process. This returns the Prince API for further method chaining.

  • Prince#binary(binary): Prince: set the path to the prince(1) binary. By default it is prince (in case PrinceXML was found globally installed at the Node API installation time) or the path to the prince binary of the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.

  • Prince#prefix(prefix): Prince: set the path to the PrinceXML installation. This by default is either empty (in case PrinceXML was found globally installed at the Node API installation time) or the path to the locally installed PrinceXML distribution (in case PrinceXML was not found globally installed at the Node API installation time). This returns the Prince API for further method chaining.

  • Prince#license(filename): Prince: set the path to the PrinceXML license file. This by default uses the path license/license.dat under the PrinceXML installation. This returns the Prince API for further method chaining.

  • Prince#timeout(timeout): Prince: set the execution timeout in milliseconds. The by default it is 10000 (10s). This returns the Prince API for further method chaining.

  • Prince#maxbuffer(maxbuffer): Prince: set the execution maximum stdout/stderr buffer size in bytes. The by default it is 10485760 (10MB). This returns the Prince API for further method chaining.

  • Prince#cwd(dirname): Prince: set the current working directory for execution. The by default it is . (current working directory). This returns the Prince API for further method chaining.

  • Prince#inputs(filename): Prince: set one (in case filename is a string) or multiple (in case filename is an array of strings) input XML/HTML files. This returns the Prince API for further method chaining.

  • Prince#output(filename): Prince: set the output PDF file. This returns the Prince API for further method chaining. This is optional if the PrinceXML option raster-output is given.

  • Prince#option(name, value[, forced]): Prince: set a PrinceXML option name name to a value value. The API knows the officially supported options of PrinceXML 9.0 and by default rejects unknown options. But arbitrary options can be passed by setting forced to true in case a different PrinceXML version should be used. This returns the Prince API for further method chaining.

  • Prince#execute(): Promise: asynchronously execute the conversion process. This returns a promise. On success it resolves to an object with stdout and stderr fields. On error, it resolves to an object with error, stdout and stderr fields.

See Also

Companion Grunt task grunt-princess

License

Copyright © 2014-2023 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.

node-prince's People

Contributors

adrianwong avatar denrat avatar dhollenbeck avatar emielwit avatar engelschall avatar jdus avatar junjie avatar kvcpr avatar pbrackenjci avatar rse avatar srbala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-prince's Issues

princexml wasn't found in path

When I run my application that uses node-prince as a dependency, it errors out saying Error: Prince#execute: cannot resolve binary "prince" to a filesystem path

Full error:

Error: Prince#execute: cannot resolve binary "prince" to a filesystem path
    at Prince._execute (/home/getpsyched/git/printer/node_modules/prince/prince-api.js:292:19)
    at Prince.execute (/home/getpsyched/git/printer/node_modules/prince/prince-api.js:359:17)
    at generatePDF (file:///home/getpsyched/git/printer/build/server/chunks/generate-012b0792.js:30:106)
    at async POST (file:///home/getpsyched/git/printer/build/server/chunks/_server.ts-b6de181a.js:8:15)
    at async render_endpoint (file:///home/getpsyched/git/printer/build/server/index.js:1575:20)
    at async resolve (file:///home/getpsyched/git/printer/build/server/index.js:4002:22)
    at async respond (file:///home/getpsyched/git/printer/build/server/index.js:3891:22)
    at async Array.ssr (file:///home/getpsyched/git/printer/build/handler.js:1221:3)

Mac download fails because download file is no longer gzipped

error /Users/beau/p/canvas/web-to-pdf/node_modules/prince: Command failed.
Exit code: 1
Command: node ./prince-npm.js install
Arguments:
Directory: /Users/beau/p/canvas/web-to-pdf/node_modules/prince
Output:
++ checking for globally installed PrinceXML
++ downloading PrinceXML distribution
-- download: https://www.princexml.com/download/prince-13.6-macos.zip

-- download: 10917819 bytes received.
++ locally unpacking PrinceXML distribution
node:events:346
      throw er; // Unhandled 'error' event
      ^

Error: incorrect header check
    at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
Emitted 'error' event on Gunzip instance at:
    at Gunzip.onerror (node:internal/streams/readable:769:14)
    at Gunzip.emit (node:events:369:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  errno: -3,

Download fails behind corporate proxy

After upgrading from 1.9.14 to 1.11.1 the download of the princexml package fails with following exception:

.../[email protected]/node_modules/prince install$ node ./prince-npm.js install
.../[email protected]/node_modules/prince install: ++ checking for globally installed PrinceXML
.../[email protected]/node_modules/prince install: ++ downloading PrinceXML distribution
.../[email protected]/node_modules/prince install: -- using proxy ($http_proxy): http://www.example.com:80
.../[email protected]/node_modules/prince install: -- download: https://www.princexml.com/download/prince-15.2-alpine3.17-x86_64.tar.gz
.../[email protected]/node_modules/prince install: (node:507) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
.../[email protected]/node_modules/prince install: (Use `node --trace-warnings ...` to show where the warning was created)
.../[email protected]/node_modules/prince install: ** ERROR: failed to download: download failed: Error: connect ECONNREFUSED ::1:443
.../[email protected]/node_modules/prince install: Done

We also tried to set the proxy configuration via npm config set proxy "http://www.example.com:80". https-proxy and noproxy were set too.

Upgrading to 1.10.0 produces the same exception.

Our used environment:

  • nodejs: 20.9.0
  • pnpm: 8.10.5
  • OS: containerimage based on node:lts-alpine3.17

If you need any further information please let me know.

Unable to install on Mac OS 10.13.1 (High sierra)

Attempted to install prince gem, but keep receiving the following errors.

Using Node 0.11.16

npm-debug.log

[master] ~/Projects/node-prince: npm install
npm WARN engine [email protected]: wanted: {"node":">= 4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4.5"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">= 0.12"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"iojs":">= 1.0.0","node":">= 0.12.0"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4.0.0"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=0.12"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=0.12.0"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"node":">=4"} (current: {"node":"0.11.16","npm":"2.3.0"})
npm WARN engine [email protected]: wanted: {"iojs":">= 1.0.0","node":">= 0.12.0"} (current: {"node":"0.11.16","npm":"2.3.0"})

> [email protected] install /Users/dave/Projects/node-prince
> node ./prince-npm.js install

/Users/dave/Projects/node-prince/node_modules/chalk/index.js:2
const escapeStringRegexp = require('escape-string-regexp');
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/dave/Projects/node-prince/prince-npm.js:46:21)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

npm ERR! Darwin 17.2.0
npm ERR! argv "/Users/dave/.nvm/v0.11.16/bin/node" "/Users/dave/.nvm/v0.11.16/bin/npm" "install"
npm ERR! node v0.11.16
npm ERR! npm  v2.3.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node ./prince-npm.js install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node ./prince-npm.js install'.
npm ERR! This is most likely a problem with the prince package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./prince-npm.js install
npm ERR! You can get their info via:
npm ERR!     npm owner ls prince
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/dave/Projects/node-prince/npm-debug.log
[npm-debug.log](https://github.com/rse/node-prince/files/1366372/npm-debug.log)

Supporting execution of --raster-output without --output

Thanks for maintaining this library 🤗

I would like to achieve an export of images à la

prince input.html --raster-format=jpeg --raster-pages=first --raster-dpi=90 --raster-output=page.jpg

But would need --output to be optional for that, since raster-output is used.

A workaround is to supply both options and just disregard the file produced by output, but it'd be nice to drop the option. I'd be happy to submit a pull request, where output is not forced when raster-output is set as an option.

Prince({
            'raster-format': 'jpeg',
            'raster-pages': 'first',
            'raster-dpi': 90,
            'raster-background': 'white',
            'raster-output': 'page.jpg'
        })
            [..]
            .output('unused')
[..]

Kindly
Frederik

Only the first error is reported on promise rejection

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

The rejection function will only log the first error that is returned by Prince. I have an html document that has at least 3 errors that I would like to log and return to the client but only have access to the first error. Please add support for an array of errors.

Bump to r7?

Should this package install the newest version of Prince?

Encounter Axios dependency vulnerabilities

We encountered a vulnerability in Axios, this should be fixed in the latest version.

$ pnpm audit --audit-level high
┌─────────────────────┬────────────────────────────────────────────────────────┐
│ high                │ Follow Redirects improperly handles URLs in the        │
│                     │ url.parse() function                                   
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Package             │ follow-redirects                                       │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Vulnerable versions │ <1.15.4                                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Patched versions    │ >=1.15.4                                               │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ Paths               │ . > [email protected] > [email protected] >                      │
│                     │ [email protected]                                │
├─────────────────────┼────────────────────────────────────────────────────────┤
│ More info           │ https://github.com/advisories/GHSA-jchw-25xp-jwwc      │
└─────────────────────┴────────────────────────────────────────────────────────┘

Passing options to Prince

I really like node-prince and I have issue figuring out how to pass option to export tagged PDF
I tried something like this but it didn't work

JS

Prince({ 'tagged-pdf': true })
  .inputs('./index.html')
  .output('./index.pdf')
  .execute()
  .then(
    function () {
      console.log('OK: done');
    },
    function (error) {
      console.log('ERROR: ', util.inspect(error));
    }
  );

This produce PDF file but PDF is missing accessibility formating implemented.
What I am actually trying to execute is following CLI command:

CLI

prince index.html --tagged-pdf

Not sure what am I missing?

macOS: Local installation of prince will not work because of incorrect permissions

If a global copy of prince is not installed, node-prince will attempt to install a local copy. However this local copy will not work. It results in an EACCES error when attempting to spawn prince.

Error occurred in handler for 'generatePDF': {
  error: Error: spawn /Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince/bin/prince EACCES
      at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
      at onErrorNT (node:internal/child_process:480:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -13,
    code: 'EACCES',
    syscall: 'spawn /Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince/bin/prince',
    path: '/Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince/bin/prince',
    spawnargs: [
      '--prefix',
      '/Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince',
      '/var/folders/1y/sf0qcwvd5csbzn8bkn1bndjc0000gn/T/output.html',
      '--output',
      '/var/folders/1y/sf0qcwvd5csbzn8bkn1bndjc0000gn/T/output-temp.pdf'
    ],
    cmd: '/Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince/bin/prince --prefix /Users/junjie/Documents/Git Repositories/sampleProject/node_modules/prince/prince/lib/prince /var/folders/1y/sf0qcwvd5csbzn8bkn1bndjc0000gn/T/output.html --output /var/folders/1y/sf0qcwvd5csbzn8bkn1bndjc0000gn/T/output-temp.pdf'
  },
  stdout: <Buffer >,
  stderr: <Buffer >
}

This is because the local installation does not have the appropriate permissions set, namely the +x executable flag. If you examine the install.sh script included with prince-14.2-macos.zip, you'll see this portion where the binary is copied to the destination and with the file permissions 755.

install_bin () {
    install -m 755 "$1" "$2"
}

I believe this would also affect the *nix builds, but I've not tested them. I'll be sending in a PR shortly to fix the Mac version.

error when running in GitHub Actions

I'm trying to use this package in GitHub Actions on Ubuntu-latest, but I keep encountering this error:

/home/runner/work/<repo-name>/<repo-name>/node_modules/prince/prince/lib/prince/bin/prince: error while loading shared libraries: libavif.so.13: cannot open shared object file: No such file or directory

I saw issue #33, so I followed the instructions for installing Prince on Linux and added these steps to my GitHub workflow (relevant steps below). No luck. Still getting the same error.

Can you offer any advice on what else I need to do to get node-prince running in GH Actions?

thanks!

      - name: Checkout
        uses: actions/checkout@v3

      - name: Install Node
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install dependencies
        run:  npm ci

      - name: Update apt
        run:  sudo apt-get update

      - name: Install gdebi-core
        run:  sudo apt install gdebi --fix-missing

      - name: Download Prince
        run:  wget https://www.princexml.com/download/prince_15-1_ubuntu22.04_amd64.deb

      - name: Install Prince
        run:  sudo gdebi prince_15-1_ubuntu22.04_amd64.deb

      - name: Run tests
        run:  npm test

      - name: Build site
        run:  npm run build # <- fails during build with the above error

installation error on Azure

I'm attempting to install node-prince on an Azure web app (so running Windows IIS), and I receive the following error:

> [email protected] install D:\home\site\wwwroot\node_modules\prince
> node ./prince-npm.js install


D:\home\site\wwwroot\node_modules\prince\node_modules\boom\lib\index.js:5
const Hoek = require('hoek');
^^^^^
SyntaxError: Use of const in strict mode.
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\home\site\wwwroot\node_modules\prince\node_modules\hawk\lib\index.js:5:33)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 8
npm ERR! [email protected] install: `node ./prince-npm.js install`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the [email protected] install script.

I'm running the app using Node v8.x. Any ideas how I might fix this error? Thanks!

Feature request: Implement using `stdin` and `stdout` with Prince

Thank you for writing this wrapper around Prince! It helped speed up my understanding of how to call Prince via a child process.

https://www.princexml.com/doc/command-line/#specifying-input-and-output

Prince called directly with the first argument - waits for stdin and passes back to stdout when - is passed to -o

ex. cat test.html | prince - -o -

Unfortunately, I have a need to be able to run Prince on lambda and having file I/O was some overhead that I needed to eliminate.

Following this example on how to run Prince on Lambda. I was able to write my own JS that handles this for my use case.

That being said I really like the API surface you provide here in this library and was hoping you could add something to address this. Whether that be a special chain able method or a modification to Prince.prototype.inputs and/or Prince.prototype.output

--debug option doesn't work

Looking at this link https://www.princexml.com/doc/command-line/ seems like this wrapper doesn't support many options without forcing it. Debug option should be provided without having to force it which is the first issue. But, even if it's forced, with the current code it will not work.

To make it work there should be some changes made to the child_process.execFile function inside _execute function. Adding something as a callback function of child_process.execFile in these lines would fix it:

if (self.config.option.debug) {
  const msgs = stderr.toString().split('\n')
  msgs.forEach(msg => {
    msg.match(/prince:/) && console.log(msg)
  })
}

PDF generation from node-webkit on PC

Hi, i've got some trouble implementing that function in node-webkit.
Everything works fine when my app is executed on OSX platform.
However the PDF can't be generated when i test it on a PC (win7 and winXP).

I don't think that it could be a question of permission because i am able to create files/folders from node-webkit.

The error returned by the node-webkit console is the following one :
"Error: err >= 0
at exports._errnoException (util.js:676:20)
at ChildProcess.spawn (child_process.js:973:11)
at exports.spawn (child_process.js:753:9)
at Object.exports.execFile (child_process.js:608:15)
at eval (myProject\Ressources\node_modules\prince\prince-api.js:242:27)
at doResolve (myProject\Ressources\node_modules\prince\node_modules\promise\core.js:91:5)
at new Promise (myProject\Ressources\node_modules\prince\node_modules\promise\core.js:71:3)
at Prince._execute (myProjectRessources\node_modules\prince\prince-api.js:237:12)
at Prince.execute (myProject\Ressources\node_modules\prince\prince-api.js:283:17)
at eval (file:///myProject/Ressources/js/HtmlToPdf.js:102:10)"

Thanks for your help!
STDI-multimedia

Installation error on Linux CI build server

Hi @rse ,

I'm using grunt-princess on node which is working great locally. However, when I try to automate it on a CI server (Ubuntu 14.04.3 LTS) I get the following error message.

> node ./prince-npm.js install

++ checking for globally installed PrinceXML
++ downloading PrinceXML distribution
ERROR: failed to determine platform details on platform "x64-linux"
npm ERR! Linux 3.19.0-51-generic
npm ERR! argv "/root/.nvm/versions/node/v0.12.15/bin/node" "/root/.nvm/versions/node/v0.12.15/bin/npm" "install"
npm ERR! node v0.12.15
npm ERR! npm  v2.15.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node ./prince-npm.js install`
npm ERR! Exit status 1

A quick look at your code, suggests to me that there's a problem running

sh + __dirname + /shtool platform -t binary

I put into my build script, near the top, a specific

sudo apt-get install -y shtool

to ensure it's there, but I still get the same error.

Any ideas what else I could try?

Thanks

Error ENOENT when using in Docker node image

On local and remotely I use docker and I have this error:

ERROR:  {
2021-01-16T13:18:05.223725+00:00 app[web.1]:   error: Error: spawn /home/app/node_modules/prince/prince/lib/prince/bin/prince ENOENT
2021-01-16T13:18:05.223726+00:00 app[web.1]:       at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
2021-01-16T13:18:05.223727+00:00 app[web.1]:       at onErrorNT (internal/child_process.js:470:16)
2021-01-16T13:18:05.223728+00:00 app[web.1]:       at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2021-01-16T13:18:05.223729+00:00 app[web.1]:     errno: 'ENOENT',
2021-01-16T13:18:05.223730+00:00 app[web.1]:     code: 'ENOENT',
2021-01-16T13:18:05.223730+00:00 app[web.1]:     syscall: 'spawn /home/app/node_modules/prince/prince/lib/prince/bin/prince',
2021-01-16T13:18:05.223731+00:00 app[web.1]:     path: '/home/app/node_modules/prince/prince/lib/prince/bin/prince',
2021-01-16T13:18:05.223731+00:00 app[web.1]:     spawnargs: [...]

Without docker it works locally.

UPDATE:
using the latest node version in the dockerfile, I don't have that error anymore but this new one:

/home/app/node_modules/prince/prince/lib/prince/bin/prince: error while loading shared libraries: libgif.so.7: cannot open shared object file: No such file or directory

Define Prince version per project

Thank you for this great module. At Electric Book Works, we're beginning to use it to make setup easier for new team members (i.e. no separate Prince installation).

We have a further need: we need to be sure that, on a given project, every team member uses the same version of Prince. In our particular case, our extensive book-design CSS library was created for Prince 11, and isn't entirely compatible with later versions.

I've forked and modified node-prince to meet our needs in electricbookworks#1.

With those modifications, we can now set the Prince version we need in a project's package.json. Our node-prince checks for that before downloading Prince.

We're still testing this approach and may still find issues with it, though it's looking very promising so far.

Would you be interested in implementing this or something similar in your module? I'd be happy to PR my changes, though you might prefer a different approach. My Javascript skills are not as sophisticated as yours! It would certainly be better for us to use your module directly, rather than maintaining our own fork.

Need example for working with encryption

I'm able to generate pdf files without encryption, but when I give the encrypt option its not creating a encrypted pdf.

Prince({"encrypt": true}, "key-bits": 128, "user-password": "12345")
    .inputs("sample.html")
    .output("tax/test-"+count+".pdf")
    .execute()
    .then(function () {
        console.log("OK: done");
    }, function (error) {
        console.log("ERROR: ", util.inspect(error));
    })

Guess need some examples and documentation on how to use options

pricexml stoped working

I am using pricexml and until today it was working fine.
it stopped working

` error: Error: Command failed: C:\Projects\pbd\html2pdf31.11.22\node_modules\prince\prince\program files\Prince\Engine\bin\prince.exe --prefix C:\Projects\pbd\html2pdf31.11.22\node_modules\prince\prince\program files\Prince\Engine 1679928942030.html --output 1679930020949.pdf

  at ChildProcess.exithandler (child_process.js:390:12)
  at ChildProcess.emit (events.js:400:28)
  at maybeClose (internal/child_process.js:1055:16)
  at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
killed: true,
code: null,
signal: 'SIGTERM',
cmd: 'C:\\Projects\\pbd\\html2pdf31.11.22\\node_modules\\prince\\prince\\program files\\Prince\\Engine\\bin\\prince.exe --prefix C:\\Projects\\pbd\\html2pdf31.11.22\\node_modules\\prince\\prince\\program files\\Prince\\Engine 1679928942030.html --output 1679930020949.pdf'

},
stdout: ,
stderr:
}`

Can't install because princexml.com is down

I can't install this module because princexml.com is down for the past few hours. Why aren't the binaries either included in the node module or downloaded from a resilient CDN?

Installation error on Linux CI build server

Hi @rse

Since originally posting about this, I've been running successfully by installing Prince separately before running Node. However, as of the beginning of Oct 2017, that approach has broken (gdebi-core has fallen out of the Ubuntu repository!!), so I've been playing around with getting it working the 'proper' way - i.e. letting node-prince handle the install.

This seems to work fine.

> node ./prince-npm.js install

++ checking for globally installed PrinceXML
++ downloading PrinceXML distribution
-- download: http://www.princexml.com/download/prince-11.3-ubuntu14.04-amd64.tar.gz

-- download: 5976344 bytes received.
++ locally unpacking PrinceXML distribution
-- OK: local PrinceXML installation now available

But when it came to generating a pdf (using grunt-princess), it was failing with:

Running "princess:main" (princess) task
Warning: Prince#execute: cannot resolve binary "prince" to a filesystem path� Use --force to continue.

I set the binary option to '/usr/local/bin', which got me further. But now i get the failure:

Running "princess:main" (princess) task
Fatal error: PrinceXML failed to generate "./dist/BG Proof.pdf":
| Error: spawn EACCES

I'm thinking that this is an OS permissions issue. Any idea how to go about fixing it?

Thanks.

Platform detection does not work for node:18.13.0-alpine base image on aarch64 architecture

The prince-npm.js file does not include handling for alpine on aarch64 architecture. Here's a patch we've needed to add to get prince to execute successfully in our containers. Alpine does not use glibc.

diff --git a/prince-npm.js b/prince-npm.js
index c191313fbf582f327ab4bf30380839fd244cada8..9c7a20fe7157a9af47e15674a2933b130f6f017c 100644
--- a/prince-npm.js
+++ b/prince-npm.js
@@ -141,6 +141,9 @@ var princeDownloadURL = function () {
                         resolve("https://www.princexml.com/download/prince-15.2-debian12-arm64.tar.gz");
                     else if (platform.match(/^arm64-debian11(?:\.\d+)*$/))
                         resolve("https://www.princexml.com/download/prince-15.2-debian11-arm64.tar.gz");
+                    else if (platform.match(/^aarch64-alpine[23](?:\.\d+)*$/))
+                        // Alpine linux ships with musl and not glibc, so we need a binary linked against musl.
+                        resolve("https://www.princexml.com/download/prince-15.2-linux-generic-aarch64-musl.tar.gz");
                     else
                         resolve("https://www.princexml.com/download/prince-15.2-linux-generic-aarch64.tar.gz");
                 }

Prince 11.2 is out !

Could be nice to update the module so that it downloads 11.2 ! ;)

Thanks for this wrapper, it helps a lot :)

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.