- Author: Fred Neumann
- Status: experimental
This is a simple node.js script to create a PDF from HTML using Puppeteer.
First install puppeteer:
npm install puppeteer
Then clone this repository to the directory in which you installed puppeteer.
To run the service go the cloned directory an execute:
node service.js
It should show you this message:
Server running on port 3000
You should put this service behind a reverse proxy to call it with https from outside.
The service is called with a POST request and returns the generated PDF as inline content. The POST must be delivered as
content-type: application/x-www-form-urlencoded
.
POST Field | Content |
---|---|
html | The HTML content to be rendered |
format | e.g. 'A4' |
landscape | '0' or '1' |
headerTemplate | html code of the template for the header |
footerTemplate | html code of the template for the footer |
see https://pptr.dev/api/puppeteer.pdfoptions for details.
The implementation adapts examples from: