HTTP service to generate PDF from Json requests

Related tags

Miscellaneous pdf
Overview

pdfgen

Build Status Go Report Card

HTTP service to generate PDF from Json requests

Install and run

The recommended method is to use the docker container by mounting your template directory (here with the provided example template directory):

docker run --rm -it -p 8888:8888 \
  --mount src=my_templates/,target=/etc/pdfgen/templates,type=bind \
  hyperboloide/pdfgen

If you rather not using Docker, you need to install wkhtmltopdf first, then run:

go install github.com/hyperboloide/pdfgen
PDFGEN_TEMPLATES=./templates pdfgen

Once installed you can test with something like this:

curl -H "Content-Type: application/json" -X POST -d @my_json_file.json \
  http://localhost:8888/invoice > result.pdf

Note that the rendering may differ depending on your os (especially OSX) and installed fonts, that's why it is recommended to test and develop on the Docker environment to get the same result in production.

Templates

The PDF are generated from HTML templates. These templates closely ressemble Django Templates.

the following template:

<h1>Hello, {{ user }}</h1>

can be generated with a application/json POST request:

{"user": "fred"}

The response is of type application/pdf and contains the resulting PDF.

Each PDF template should be in it's own directory under the root directory defined in the PDFGEN_TEMPLATES environment variable.

The urls endpoints will be generated from these directories names. For example a template in the directory invoice will be a reachable at a url that look like that: http://host:port/invoice

The template directory must contain an index.html file and optionnaly a footer.html file. Other assets like images and CSS should be in that directory too. Note that each PDF is generated in isolation and so your templates should use absolutes paths. For example if you use bower and have a path like that: invoices/bower_components/ you should have:

<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css" media='screen,print'>

Finally don't forget to set the PDFGEN_TEMPLATES env variable to the path of your templates parent directory Alternatively you copy your templates to either : /etc/pdfgen/templates or ~/.templates.

Adding fonts

You could just create a new container with your fonts and rebuild the cache. Bellow an example Dockerfile.

FROM hyperboloide/pdfgen
COPY my_fonts /usr/local/share/fonts/
RUN  fc-cache -f -v
Owner
Hyperboloide
Hyperboloide
wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion

wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion. Implements wkhtmltopdf Go bindings. It can be used to convert HTML docume

Adrian-George Bostan 119 Jul 24, 2022
A vitamin C rich, book, pdf & documentation brewing library for e-readers/e-ink readers

go-Cbook A vitamin C rich, book, pdf & documentation brewing library for e-readers/e-ink readers. Now take priviliges of (eye-safe) e-readers to read

VOrishirne 6 Dec 28, 2021
Go-keymap - Generate keymap.c, layers.h and keymap.svg from visual keymaps defined through keymaps.json and .layer files

generating keymap.c This utility can generate a keymap.c, layers.h and keymap.sv

Jur93n 1 Feb 15, 2022
CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonster Cloud API.

✨ CapMonsterTool ✨ About this module What is ✨ CapMonsterTool ✨ ? CapMonsterTool is a set of Go tools designed to simply make requests to the CapMonst

Louis Billaut 19 Jun 29, 2022
Kong Verifier plugin for HSDP API signed requests

Kong Verifier plugin for HSDP API signed requests

Andy Lo-A-Foe 2 Jan 7, 2022
An HTTP service for customizing import path of your Go packages.

Go Packages A self-host HTTP service that allow customizing your Go package import paths. Features Reports. Badges. I18N. Preview I launch up a free H

Razon Yang 18 Nov 18, 2021
An in-memory, key-value store HTTP API service

This is an in-memory key-value store HTTP API service, with the following endpoints: /get/{key} : GET method. Returns the value of a previously set ke

Ujjwal Goyal 1 May 23, 2022
A Simple Bank Web Service implemented in Go, HTTP & GRPC, PostgreSQL, Docker, Kubernetes, GitHub Actions CI

simple-bank Based on this Backend Master Class by TECH SCHOOL: https://youtube.com/playlist?list=PLy_6D98if3ULEtXtNSY_2qN21VCKgoQAE Requirements Insta

Tien La 0 Dec 9, 2021
Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Charles Weill 4.1k Aug 1, 2022
generate fake data in go

Faker for Go Usage package main import ( "github.com/manveru/faker" ) func main() { fake, err := faker.New("en") if err != nil { panic(err

Michael Fellinger 163 Jul 6, 2022
:runner:runs go generate recursively on a specified path or environment variable and can filter by regex

Package generate Package generate runs go generate recursively on a specified path or environment variable like $GOPATH and can filter by regex Why wo

Go Playgound 27 Jul 23, 2022
A command line tool to generate sequence diagrams

goseq - text based sequence diagrams A small command line utility used to generate UML sequence diagrams from a text-base definition file. Inspired by

Leon Mika 182 Jul 28, 2022
generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

yihong 93 Aug 3, 2022
Generate spreadsheets based on GitHub contributions

pullsheet generates a CSV (comma separated values) & HTML output about GitHub activity across a series of repositories.

Google 58 Jun 21, 2022
Generate type-safe Go converters by simply defining an interface

goverter a "type-safe Go converter" generator goverter is a tool for creating type-safe converters. All you have to do is create an interface and exec

Jannis Mattheis 136 Aug 3, 2022
Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.

Codename an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superheroe like" codenames, consisting of a random combinatio

Luca Sepe 82 Jul 2, 2022
An application that is developed to generate application by API specification

GO boilerplate is an application that is developed to generate application by API specification and Database schema with the collaboration with opn-generator.

Rafi Mahmud 0 Oct 14, 2021
A tool to generate Pulumi Package schemas from Go type definitions

MkSchema A tool to generate Pulumi Package schemas from Go type definitions. This tool translates annotated Go files into Pulumi component schema meta

Joe Duffy 2 Jun 5, 2022
Generate FIRST/FOLLOW/PREDICT Set from BNF.

Generate FIRST/FOLLOW/PREDICT Set from BNF. We can use it to study parser theory. Feature FirstSet generate. Output pretty. FollowSet generate. Output

imtf 1 Oct 30, 2021