https://github.com/jeffotoni/gowkhtmltopdf
uma image docker com o programa wkhtmltopdf e um server em Go para converter html em pdf
https://github.com/jeffotoni/gowkhtmltopdf
docker go golang html pdf wkhtmltopdf
Last synced: 9 months ago
JSON representation
uma image docker com o programa wkhtmltopdf e um server em Go para converter html em pdf
- Host: GitHub
- URL: https://github.com/jeffotoni/gowkhtmltopdf
- Owner: jeffotoni
- Created: 2018-10-26T14:44:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-22T14:59:08.000Z (about 5 years ago)
- Last Synced: 2025-06-08T16:03:18.581Z (about 1 year ago)
- Topics: docker, go, golang, html, pdf, wkhtmltopdf
- Language: Go
- Size: 30.5 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gowkhtmltopdf
Uma image docker com o programa wkhtmltopdf e um server em Go para converter html em pdf
A API irá receber um HTML e retornar um PDF, o html terá que ser passado como json para API.
# Rodando API com Docker
```sh
$ docker run --restart=always -d -p 5010:5010 --name gowkhtmltopdf \
jeffotoni/gowkhtmltopdf:latest
$ docker logs -f
$ curl -X POST localhost:5010/v1/api/topdf -H "Content-Type: application/json" \
--data @table.html.json --output /tmp/meuteste.pdf
```
# Build em sua máquina local
```bash
$ docker build --no-cache -f DockerfileAlpine --build-arg PORT=5010 \
-t xxxxxxxxxxxxx/gowkhtmltopdf:latest .
$ docker run --restart=always -d -p 5010:5010 --name gowkhtmltopdf \
jeffotoni/gowkhtmltopdf:latest
// -- or
$ docker run -p 5010:5010 --name gowkhtmltopdf -e X_KEY=xxxxxx \
jeffotoni/gohtmltopdf
$ docker logs -f
$ curl -X POST localhost:5010/v1/api/topdf -H "Content-Type: application/json" \
-H "Authorization:Basic xxxxxx" \
--data @table.html.json --output /tmp/meuteste.pdf
```
# Gerando Json do seu HTML antes de enviar para API
A API recebe um JSON, o nome do arquivo e o html que deseja converter e retorna o PDF.
Para gerar seu HTML em JSON só rodar o programinha abaixo.
Campos permitidos
```json
{
"Nome":"meu_pdf",
"Html":"",
"grayscale":false,
"nocollate":false,
"image_dpi":600,
"image_quality":94,
"page_size":"A4",
"orientation":"Portrait",
"dpi":600,
"margin_bottom":2,
"margin_top":2,
"margin_left":2,
"margin_right":2
}
```
Este programa irá converter seu HTML em JSON e os campos necessários para geração do PDF
```sh
$ cd gerahtmljson
$ go run main.go --file table.html
```
# Rodando o server sem usar docker
```sh
$ go run gowkhtmltopdf.go
$ curl -X POST localhost:5010/v1/api/topdf -H "Content-Type: application/json" \
--data @table.html.json --output /tmp/meuteste.pdf
```