Categorygithub.com/lucas-gaitzsch/pdf-turtle
modulepackage
0.0.0-20240923052108-ac940399ce25
Repository: https://github.com/lucas-gaitzsch/pdf-turtle.git
Documentation: pkg.go.dev

# README

PdfTurtle 🐒 HTML to PDF generation service

build and test Go Report Card codecov Maintainability Rating Reliability Rating Security Rating Lines of Code Docker Pulls

A painless html to pdf rendering service

PdfTurtle generates PDF reports and documents from HTML templates or raw HTML.

Try it! Here's a DEMO__🐒__.

Screenshot

🎒 Features

  • βœ… Free, OpenSource and Self-Hosted
  • πŸ’¬ Generate PDFs in a descriptive way from HTML and CSS (with JavaScript support)
  • ✨ Supports modern HTML and CSS standards (uses latest Chromium engine)
  • πŸ‘» Builtin template engines (go-template, raymond and django)
  • πŸ’Ό Bundle template and assets in ZIP file (see Bundle workflow)
  • πŸš€ Fast generation with limited resources (limited multithreading)
  • πŸ”₯ Multiple replicas supported (stateless service design)
  • πŸ–₯ Frontend (Playground) for rapid development
  • πŸ’« Beautiful fonts included and preoptimized style (CSS) for PDF or print
  • πŸ“¦ Container image available (see Run with docker)

πŸ’₯ How to run the service

With docker container (recommended)

The container image is available on Docker Hub.

With the tag *-playground you get a bundled image with the web playground.

docker pull lucasgaitzsch/pdf-turtle

docker run -d \
    -p 8000:8000 \
    --name pdf-turtle \
    --restart unless-stopped \
    lucasgaitzsch/pdf-turtle

Included fonts:

  • Open Sans
  • Roboto
  • Noto Emoji

Config

command line argumentenvironment variabletypedefaultdescription
--help---Show help
--logDebugLOG_LEVEL_DEBUGbooleanfalseDebug log level active
--logJsonOutputLOG_JSON_OUTPUTbooleanfalseJson log output
--renderTimeoutRENDER_TIMEOUTinteger30Render timeout in seconds
--workerInstancesWORKER_INSTANCESinteger30Count of worker instances
--portPORTinteger8000Server port
--maxBodySizeMAX_BODY_SIZEinteger32Max body size in megabyte
--servePlaygroundSERVE_PLAYGROUNDbooleanfalseServe playground from path "./static-files/playground/"
--secretSECRETstring""Secret used as bearer token

πŸš€ How to use

Bundle Workflow (recommended)

flowchart LR
    subgraph PG[PdfTurtle-Playground]
        direction LR
        O(go to<br>pdfturtle.gaitzsch.dev) --> |go to model tab| MO(paste an<br> example model)
        click O href "https://pdfturtle.gaitzsch.dev" "https://pdfturtle.gaitzsch.dev"
        O --> |go to body tab| B(design the body)
        O --> |go to header tab| H(design the header)
        O --> |go to footer tab| F(design the footer)
        O --> |go in asstes menu| A(put your assets)

        OPT(set your<br> options)
        MO --> OPT
        B --> OPT
        H --> OPT
        F --> OPT
        A --> OPT
        OPT --> S(fa:fa-file-zipper save as<br> ZIP bundle)
    end

    subgraph YP[your fancy project]
        direction TB
        PA(provide as asset)
        PA-->CL(use clent lib)
        PA-->SGC(use swagger to<br> build or generate client)
        R(render PDF with<br> bundle and your model)
        CL-->R
        SGC-->R
        R-->BH(fa:fa-smile be happy!)
    end

    S-->|copy zip bundle<br> to your project|YP
    %%PG-->YP

1. Prepare project

Choose the fitting client lib for your language or generate / build your own by the OpenApi (Swagger) description.

2. Design your PDF in the playground

Go to 🐒PdfTurtle-Playground, put an example model as JSON and design your PDF. Download the bundle as ZIP file and put it in your resources/assets.

PdfTurtleBundle-Workflow

3. Call the service with the client and your data

Send a request to a PdfTurtle instance with your bundle and your model. You will get a rendered PDF.

And thats it.

Hint: You can split your bundle

If you want to have the same header for all documents, you can create a ZIP file with with only the header.html and the required assets. Now you can call the Service with multiple bundle files. The service will assemble the files together. Single files can be send as bundle-component without compressing to a ZIP file. All files with other names than "index.html", "header.html", "footer.html" and "options.json" will be put to the folder "/assets/".

PdfTurtle Playground

You can write and test templates with the builtin playground.

Client libs

Swagger

Use Swagger-UI under /swagger/index.html as API documentation.

You can use the swagger description (/swagger/doc.json or ./server/docs/swagger.json) to generate a API client for the language of your choice.

Postman

You can import the swagger file to test the service with Postman or an alternative.

Included template engines

Template stylePackagePdfTurtle keyURL
Golanghtml/templategolanghttps://pkg.go.dev/html/template
Django-syntax like (require model. prefix)pongo2djangohttps://github.com/flosch/pongo2
Handlebars-syntax likeraymondhandlebarshttps://github.com/aymerick/raymond

Included template functions

Function nameParametersDescription
marshalobjectEncodes provided object as JSON string
barcodeQrcontentRenders a SVG QR code from content
barcodeEancontentRenders a SVG EAN code from content
strContainshaystack, needleDoes the haystack contains the needle
strHasPrefixhaystack, needleDoes the first string starts with the second
strHasSuffixhaystack, needleDoes the first string end with the second
addfloat64, float64Adds two float64 numbers
subtractfloat64, float64Subtracts two float64 numbers
multiplyfloat64, float64Multiplies two float64 numbers
dividefloat64, float64Divides two float64 numbers
float64ToIntfloat64Convert a int to float64
intToFloat64intConvert a float64 to int
bitwiseAndint, inta & b

Development / Build from source

See README_DEV.md.

🚧 Roadmap

πŸ”¨ Contribution

Contributors are welcome! Feel you free to fork the project and open a pull request.

If you wrote a client lib for a uncovered language please contact me. I will create a repo for you or link your client lib in this readme file.

☒ Build with

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author