Send a HTML or Mustache template and recieve a PDF stream as the response.
docker pull quay.io/ukhomeofficedigital/html-pdf-converter
docker run -p 8001:8001 html-pdf-converter
git clone [email protected]:UKHomeOffice/html-pdf-converter.git
cd html-pdf-converter
npm install
npm start
Mustache and Data
curl -H "Content-Type:application/json" \
-d '{
"template": "'"\
<html>\
<head>\
<title>{{title}}</title>\
</head>\
<body>\
<h1>{{header}}</h1>\
<p>{{para}}</p>\
</body>\
</html>\
"'",
"data": {
"title": "My title",
"header": "My header",
"para": "My content"
}
}' \
-i localhost:8001/convert
HTML
curl -H "Content-Type:application/json" \
-d '{
"template": "'"\
<html>\
<head>\
<title>My title</title>\
</head>\
<body>\
<p>Hello world</p>\
</body>\
</html>\
"'"
}' \
-i localhost:8001/convert
Response (example)
%PDF-1.4\n1 0 obj\n<<\n/Title ...
Chrome can accept a number of options to its PDF render function. These are documented here: https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
These can be set on a per-request basis by passing a pdfOptions
object as part of your request body.
{
"template":"<h1>Hello World!</h1>",
"pdfOptions": {
"printBackground": true
}
}
This service cannot resolve external resources such as linked CSS, JavaScript or images. If your template includes links to any of these resources, we suggest you use https://github.com/remy/inliner. The source for Inliner can be a URL, a file location or an HTML string.
APP_PORT: Defaults to 8001
APP_HOST: Defaults to 'localhost'