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

https://github.com/modfin/betterpress

html to pdf microservice
https://github.com/modfin/betterpress

Last synced: 11 months ago
JSON representation

html to pdf microservice

Awesome Lists containing this project

README

          

# Betterpress

Betterpress wraps [openhtmltopdf](https://github.com/danfickle/openhtmltopdf) in a Spark server inside a docker container. This makes for a convenient pdf generation service over http.

### User Guide

1. Download/run the docker image:
```bash
docker run -p 7357:8080 modfin/betterpress
```

1. Send files over http as multipart form data where the index file/entry point must have `name` property `index.html`. This looks something like the following:
```
POST /
User-Agent: myagent
Accept: */*
Host: localhost:7357
accept-encoding: gzip, deflate
content-type: multipart/form-data; boundary=myboundary
content-length: 192668

--myboundary
Content-Disposition: form-data; name="index.html"; filename="myindexfile.html"

[index.html binary]
--myboundary
Content-Disposition: form-data; name="styles.css"; filename="styles.css"

[styles.css binary]
--myboundary
Content-Disposition: form-data; name="font.ttf"; filename="font.ttf"

[font.ttf binary]
--myboundary--
```
:information_source: tip - don't write this by hand, use a http library :)

1. Betterpress will reply with the generated pdf file

### Notes

Betterpress always uses `W3CDom().fromJsoup(indexDoc)` mentioned in [the openhtmltopdf integration guide](https://github.com/danfickle/openhtmltopdf/wiki/Integration-Guide#html5-parser-support). I.e. make sure to send `index.html` in html5 format. Note that css2.1 still is a limit so e.g. for fonts we must use `@font-face` instead of `@import`.

### Dev

Release new versions of the docker image unto [dockerhub](https://hub.docker.com/r/modfin/betterpress):

```bash
docker login --username=yourhubusername # then enter pass
./docker-build-push.sh
```