gotenberg

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gotenberg is a document.Renderer backed by a Gotenberg server's Chromium HTML route. It talks plain HTTP (no Go SDK), so it depends only on the standard library and the document package.

The request shape follows the Gotenberg docs (https://gotenberg.dev/docs/convert-with-chromium/convert-html-to-pdf, verified 2026-10-20): POST {base}/forms/chromium/convert/html with a multipart form whose "files" field carries a file named "index.html"; a 200 response body is the PDF. Gotenberg answers 400 on a main-page network error, 403 on a forbidden URL, and 409 when a page returns a failing HTTP status.

Index

Constants

View Source
const (
	// DefaultTimeout bounds one conversion when Config.Timeout is zero.
	DefaultTimeout = 30 * time.Second
	// DefaultMaxResponseBytes bounds the PDF read from Gotenberg when
	// Config.MaxResponseBytes is zero.
	DefaultMaxResponseBytes int64 = 32 << 20
)

Variables

View Source
var (
	// ErrResponseTooLarge reports a PDF larger than Config.MaxResponseBytes;
	// the body is discarded. It also wraps document.ErrRenderRejected.
	ErrResponseTooLarge = errors.New("gotenberg: response exceeds the configured size limit")
	// ErrUnexpectedStatus reports a non-2xx response. The error text carries
	// the status code and the start of Gotenberg's plain-text message. A 400,
	// 409 or 422 also wraps document.ErrRenderRejected.
	ErrUnexpectedStatus = errors.New("gotenberg: unexpected response status")
)

Sentinel errors callers can branch on via errors.Is.

Functions

This section is empty.

Types

type Config

type Config struct {
	// BaseURL is the Gotenberg server, e.g. "http://gotenberg:3000". Required;
	// it must be an absolute http or https URL. A trailing slash is ignored.
	BaseURL string
	// HTTPClient sends the requests. Nil uses a new *http.Client; inject one
	// to add tracing (otel.Transport), proxies or TLS settings.
	HTTPClient *http.Client
	// Timeout bounds one conversion, on top of any deadline already on the
	// caller's ctx. Zero uses DefaultTimeout.
	Timeout time.Duration
	// MaxResponseBytes bounds the PDF read into memory. Zero uses
	// DefaultMaxResponseBytes.
	MaxResponseBytes int64
}

Config configures a Renderer.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer converts HTML to PDF through Gotenberg. It is safe for concurrent use.

func New

func New(cfg Config) (*Renderer, error)

New validates cfg and returns a Renderer.

func (*Renderer) Render

func (r *Renderer) Render(ctx context.Context, html []byte) ([]byte, error)

Render posts html as index.html and returns the PDF bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL