https://github.com/kdcio/serverless-html-to-pdf
Serverless API that converts HTML pages to PDF documents
https://github.com/kdcio/serverless-html-to-pdf
aws convert html html-to-pdf lambda pdf pdf-generation serverless
Last synced: 7 months ago
JSON representation
Serverless API that converts HTML pages to PDF documents
- Host: GitHub
- URL: https://github.com/kdcio/serverless-html-to-pdf
- Owner: kdcio
- License: other
- Created: 2021-02-19T01:48:53.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-10T20:22:09.000Z (over 3 years ago)
- Last Synced: 2025-06-08T05:44:43.228Z (10 months ago)
- Topics: aws, convert, html, html-to-pdf, lambda, pdf, pdf-generation, serverless
- Language: JavaScript
- Homepage:
- Size: 17.3 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serverless HTML to PDF API
This creates an API (AWS API Gateway and lambda) that converts HTML pages to PDF documents using [wkhtmltopdf](https://wkhtmltopdf.org/) (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](https://github.com/zeplin/zeplin-html-to-pdf).
 [](https://github.com/kdcio/serverless-html-to-pdf/actions/workflows/push.yml)
## Setup
```bash
git clone https://github.com/kdcio/serverless-html-to-pdf.git
cd serverless-html-to-pdf
npm install
```
## Run in local environment
Requires docker to simulate lambda environment.
```bash
npm start
```
## Usage
### API POST
```http
POST http://localhost:3000
Content-Type: application/json
{
"html": "HTML docContent"
}
```
See [tests/api.http](tests/api.http) to try. You'll need to open this project on [VS Code](https://code.visualstudio.com/https://code.visualstudio.com/) with [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension for it to work.
### API Output
It yields a response in the following format:
```json
{
"data": "JVBERi0xLjQKMSAwIG9iago8PAovVGl0bGUgKP7..."
}
```
`data` is base64 encoding of the converted PDF file.
### Example
Run example API client code in [example/client.js](example/client.js):
```bash
npm run client
```
This will generate `base64.pdf` file.
## Deploying to AWS
Deploy using your `default` AWS profile in `ap-southeast-1` region and `Asia/Manila` timezone.
```bash
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.
```yml
REGION: us-east-1
PROFILE: production
TZ: America/New_York
```
To use that config file, run the command below:
```bash
npm run deploy prod
```
## Star Me
If you find this project useful, please consider giving a star. I would really appreciate it.
You can also:
[](https://www.buymeacoffee.com/o4f0WYV)
## License
[MIT](LICENSE)