DEV Community

Željko Šević
Željko Šević

Posted on • Originally published at sevic.dev on

PDF generation with Gotenberg

Gotenberg is a Docker-based stateless API for PDF generation from HTML and Markdown files.

To get started, configure Docker compose and run the docker-compose up command.

version: '3.8'

services:
  gotenberg:
    image: gotenberg/gotenberg:7
    ports:
      - 3000:3000
Enter fullscreen mode Exit fullscreen mode

API is available on http://localhost:3000 address.

Run the following commands to generate PDFs

  • from the given URL
  curl \
    --request POST 'http://localhost:3000/forms/chromium/convert/url' \
    --form 'url="https://sparksuite.github.io/simple-html-invoice-template/"' \
    --form 'pdfFormat="PDF/A-1a"' \
    -o curl-url-response.pdf
Enter fullscreen mode Exit fullscreen mode
  • from the given HTML file
  curl \
    --request POST 'http://localhost:3000/forms/chromium/convert/html' \
    --form 'files=@"./index.html"' \
    --form 'pdfFormat="PDF/A-1a"' \
    -o curl-html-response.pdf
Enter fullscreen mode Exit fullscreen mode

PDF/A-1a format is used for the long-term preservation of electronic documents, ensuring that documents can be accessed and read even as technology changes.

Demo

The demo with the mentioned examples is available here. It also contains examples using Fetch API and Axios package.

Top comments (5)

Collapse
 
ucok23 profile image
Ucok I. L

I wonder if you ever try it using port other than 3000, becouse you know I use react in that port

Collapse
 
zsevic profile image
Željko Šević

other ports like 3001 can be used by changing the docker-compose configuration to 3001:3000

Collapse
 
ucok23 profile image
Ucok I. L

Gonna try it, thanks

Collapse
 
paulfelce profile image
paulfelce

Is the demo for using the API with fetch still available?

Collapse
 
zsevic profile image
Željko Šević

Yes, I added you access to Demos repository, you should get an invite via e-mail