Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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-service

docker 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.