gotenberg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

gotenberg — Go client for Gotenberg

A clean, dependency-free and idiomatic Go client for the Gotenberg HTTP API.

  • Request bodies are constructed with mime/multipart.
  • Adds optional webhook headers (Gotenberg-Webhook-*) and Gotenberg-Output-Filename when provided via options.
  • Returning *http.Response allows streaming large PDFs without buffering them entirely in memory.
  • No third-party dependencies: the client uses only the Go standard library (net/http, mime/multipart, context, etc.).

Usage example

ctx := context.Background()
httpClient := &http.Client{}
cli := gotenberg.NewClient(httpClient, "http://localhost:3000")

resp, err := cli.ConvertURLToPDF(ctx, "https://example.com")
if err != nil {
		// handle error
}
defer resp.Body.Close()

// stream or save the PDF
// out, _ := os.Create("out.pdf")
// io.Copy(out, resp.Body)

Recommendations

  • Always close resp.Body.
  • Use context.Context for timeouts and cancellations.
  • Inspect response headers (e.g. Gotenberg-Trace) when needed.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PaperSizeLetter  = [2]float64{8.5, 11}
	PaperSizeLegal   = [2]float64{8.5, 14}
	PaperSizeTabloid = [2]float64{11, 17}
	PaperSizeLedger  = [2]float64{17, 11}
	PaperSizeA0      = [2]float64{33.1, 46.8}
	PaperSizeA1      = [2]float64{23.4, 33.1}
	PaperSizeA2      = [2]float64{16.54, 23.4}
	PaperSizeA3      = [2]float64{11.7, 16.54}
	PaperSizeA4      = [2]float64{8.27, 11.7}
	PaperSizeA5      = [2]float64{5.83, 8.27}
	PaperSizeA6      = [2]float64{4.13, 5.83}
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(httpClient *http.Client, baseURL string) *Client

func (Client) ConvertHTMLToPDF

func (c Client) ConvertHTMLToPDF(ctx context.Context, indexHTML io.Reader, opts ...ConvOption) (*http.Response, error)

func (Client) ConvertURLToPDF

func (c Client) ConvertURLToPDF(ctx context.Context, url string, opts ...ConvOption) (*http.Response, error)

type ConvOption added in v0.0.3

type ConvOption func(*convConfig)

func WithFile added in v0.1.0

func WithFile(name string, r io.Reader) ConvOption

func WithLandscape

func WithLandscape(enabled bool) ConvOption

func WithMargins

func WithMargins(top, right, bottom, left float64) ConvOption

func WithOutputFilename

func WithOutputFilename(filename string) ConvOption

func WithPaperSize

func WithPaperSize(width, height float64) ConvOption

func WithPaperSizeA4 added in v0.0.3

func WithPaperSizeA4() ConvOption

func WithPaperSizeLetter added in v0.0.3

func WithPaperSizeLetter() ConvOption

func WithPrintBackground

func WithPrintBackground(enabled bool) ConvOption

func WithScale

func WithScale(scale float64) ConvOption

func WithSinglePage

func WithSinglePage(enabled bool) ConvOption

func WithWebhookError added in v0.1.0

func WithWebhookError(errorURL, errorMethod string) ConvOption

func WithWebhookExtraHeader added in v0.1.0

func WithWebhookExtraHeader(name, value string) ConvOption

func WithWebhookSuccess added in v0.1.0

func WithWebhookSuccess(url, method string) ConvOption

Directories

Path Synopsis
example
cmd/html2pdf command
cmd/url2pdf command

Jump to

Keyboard shortcuts

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