Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leocode/puppeteer-service
Containerized Puppeteer which allows to render images and PDFs of given webpage or HTML code
https://github.com/leocode/puppeteer-service
docker pdf puppeteer screenshot
Last synced: 7 days ago
JSON representation
Containerized Puppeteer which allows to render images and PDFs of given webpage or HTML code
- Host: GitHub
- URL: https://github.com/leocode/puppeteer-service
- Owner: leocode
- License: mit
- Created: 2021-03-26T11:52:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-07T13:43:08.000Z (about 3 years ago)
- Last Synced: 2023-03-07T19:17:42.158Z (almost 2 years ago)
- Topics: docker, pdf, puppeteer, screenshot
- Language: TypeScript
- Homepage:
- Size: 190 KB
- Stars: 2
- Watchers: 16
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# puppeteer-service
Containerized Puppeteer which allows to render images and PDFs of given webpage or HTML code
## Quick start - start container, convert HTML to PDF
For production: **Remember to select precise version tag for the image (e.g. leocode/puppeteer-service:1.1.0)**
```sh
docker build -t pup-test leocode/puppeteer-servicedocker run -it --rm -p 3000:3000 pup-test
curl -d '{"html":"Hello world"}' -H "Content-Type: application/json" -X POST http://localhost:3000/html/pdf > hello-world.pdf
```## Container installation
**Remember to select precise version tag for the image (e.g. leocode/puppeteer-service:1.1.0)**
```
docker run leocode/puppeteer-service
```The same can be used for docker-compose:
```yaml
services:
puppeteer:
image: leocode/puppeteer-service
```## Documentation
Starting container automatically starts API server.
It listens on port 3000.
### HTML to PDF
**Method**: `POST`
**URL**: `/html/pdf`
**Body**
```json
{
"html": "Content"
}
```**Response**
```
HTTP/1.1 200 OK
content-type: application/octet-stream```
### HTML to PNG
**Method**: `POST`
**URL**: `/html/png`
**Body**
```json
{
"html": "Content",
"viewport": {
"width": 1024,
"height": 768
}
}
```**Response**
```
HTTP/1.1 200 OK
content-type: application/octet-stream```
### URL to PDF
**Method**: `POST`
**URL**: `/url/pdf`
**Body**
```json
{
"url": "https://www.wikipedia.org/"
}
```**Response**
```
HTTP/1.1 200 OK
content-type: application/octet-stream```
### URL to PNG
**Method**: `POST`
**URL**: `/url/png`
**Body**
```json
{
"url": "https://www.wikipedia.org/",
"viewport": {
"width": 1024,
"height": 768
}
}
```**Response**
```
HTTP/1.1 200 OK
content-type: application/octet-stream```
## Development
Dependencies:
- Docker
```
yarn start:dev
```Start container with API. Wait until logs from server appear (due to one-line command `docker build` output is muted). It may take up to few minutes. Consecutive starts (after code change) should be faster.
You can test production build using
```
yarn start:prod
```### Versioning
We use semver for versioning. Release should be tagged with vX.Y.Z, so the version is picked up by Docker Hub autobuild.