ХабрПостыНовостиМегапосты?

Stream-first Gotenberg Client for Go

https://gotenberg.dev/
https://gotenberg.dev/

Go client for Gotenberg — document conversion service supporting Chromium, LibreOffice, and PDF manipulation engines.

go get github.com/nativebpm/gotenberg

Features

Conversion Engines

Chromium

Convert web content to PDF:

Supports:

LibreOffice

Convert Office documents:

PDF Engines

PDF operations:

Webhook Mode

Async conversions with callbacks:

See Gotenberg webhook docs for details.

Example with Docker:

docker run \
  -p 3000:3000 \
  --name gotenberg \
  --add-host="host.docker.internal:host-gateway" \
  gotenberg/gotenberg:8
package main

import (
 "context"
 "io"
 "log"
 "net/http"
 "os"
 "time"

 "github.com/nativebpm/gotenberg"
)

func main() {
 client, err := gotenberg.NewClient(&http.Client{}, "http://localhost:3000")
 if err != nil {
  log.Fatal(err)
 }

 // Convert web page from URL to PDF
 resp, err := client.
  Chromium().
  ConvertURL(context.Background(), "https://gotenberg.dev/docs/getting-started/introduction").
  PaperSizeA4().
  Margins(1, 1, 1, 1).
  PrintBackground().
  Timeout(30 * time.Second).
  Send()
 if err != nil {
  log.Fatal(err)
 }
 defer resp.Body.Close()

 f, err := os.Create("converturl-chromium.pdf")
 if err != nil {
  log.Fatal(err)
 }
 defer f.Close()

 _, err = io.Copy(f, resp.Body)
 if err != nil {
  log.Fatal(err)
 }

 log.Println("PDF generated from URL: converturl-chromium.pdf")
}
package main

import (
 "context"
 "io"
 "log"
 "net/http"
 "os"
 "strings"

 "github.com/nativebpm/gotenberg"
)

func main() {
 client, err := gotenberg.NewClient(&http.Client{}, "http://localhost:3000")
 if err != nil {
  log.Fatal(err)
 }

 html := strings.NewReader("<html><body><h1>Hello World!</h1></body></html>")

 resp, err := client.Chromium().
  ConvertHTML(context.Background(), html).
  PaperSizeA6().
  Margins(0.5, 0.5, 0.5, 0.5).
  Send()
 if err != nil {
  log.Fatal(err)
 }
 defer resp.Body.Close()

 f, _ := os.Create("out.pdf")
 io.Copy(f, resp.Body)
 f.Close()
}

Full Examples

Github: https://github.com/nativebpm/gotenberg

@
02.11.2025 16:35 UTC
Первоисточник