This creates an API (AWS API Gateway and lambda) that converts HTML pages to PDF documents using wkhtmltopdf (0.12.4). It implements a simple interface to read an HTML input and output PDF content.
This project is a fork of zeplin/zeplin-html-to-pdf.
git clone https://github.com/kdcio/serverless-html-to-pdf.git
cd serverless-html-to-pdf
npm install
Requires docker to simulate lambda environment.
npm start
POST http://localhost:3000
Content-Type: application/json
{
"html": "<!DOCTYPE html><html><head><title>HTML doc</title></head><body>Content</body></html>"
}
See tests/api.http to try. You'll need to open this project on VS Code with REST Client extension for it to work.
It yields a response in the following format:
{
"data": "JVBERi0xLjQKMSAwIG9iago8PAovVGl0bGUgKP7..."
}
data
is base64 encoding of the converted PDF file.
Run example API client code in example/client.js:
npm run client
This will generate base64.pdf
file.
Deploy using your default
AWS profile in ap-southeast-1
region and Asia/Manila
timezone.
npm run deploy
Customize the parameters by creating a config for your stage. For example, create the file config.prod.yml
in the project root with the contents below.
REGION: us-east-1
PROFILE: production
TZ: America/New_York
To use that config file, run the command below:
npm run deploy prod
If you find this project useful, please consider giving a star. I would really appreciate it.
You can also: