Run a simple HTTP server, that awaits requests with URL parameter, loades website from that URL and respondes with PDF file.
This project depends on Node.js v12+.
It also depends on Chrome or Chromium browser. If you do not want to install additional Chrome with this module, make sure that there is a CHROME_BIN
environmental variable set, pointing to browser executable.
You can also run it using Docker or Podman, in which case no installation will be necessary (skip the "Installation" step).
Since this is a private project (at least at the moment), clone it, go to its directory and install it:
git clone [email protected]:ahwayakchih/node-pdf-print-server.git
cd node-pdf-print-server
npm install --production
If you have Chrome or Chromium browser enabled, set CHROME_BIN
environment variable pointing to its executable and install "thin" version of puppeteer
module:
npm install --no-save puppeteer-core
Otherwise, install "full" version of puppeteer
module (which will include local installation of Chrome browser):
npm install --no-save puppeteer
Start server from command line:
npm start 0.0.0.0:8080
That will start server listening for connections on any hostname, on port 8080
.
If you want to hide it behind some reverse-proxy (that could also serve as SSL terminator), you can run server as localhost only instead:
npm start localhost:8080
docker run --rm -v ~/www/pdf-printer:/app -p 8080:8080 -it ahwayakchih/nodeapp:puppeteer /bin/sh -c "npm install --production && npm start 0.0.0.0:8080"
podman run --rm --userns=keep-id -v ./:/app -p 8080:8080 -it ahwayakchih/nodeapp:puppeteer /bin/sh -c "npm install --production && npm start 0.0.0.0:8080"
Simply request server by passign additional url
query parameter:
curl -o test.pdf http://localhost:8080/?url=https://nodejs.org
or x-print-pdf-url
HTTP header:
curl -o test.pdf -H 'x-print-pdf-url: https://nodejs.org' http://localhost:8080