gotenberg

package module
v0.1.1 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: 11 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

View Source
const (
	FieldSinglePage              = "singlePage"
	FieldPaperWidth              = "paperWidth"
	FieldPaperHeight             = "paperHeight"
	FieldMarginTop               = "marginTop"
	FieldMarginBottom            = "marginBottom"
	FieldMarginLeft              = "marginLeft"
	FieldMarginRight             = "marginRight"
	FieldPreferCSSPageSize       = "preferCssPageSize"
	FieldGenerateDocumentOutline = "generateDocumentOutline"
	FieldGenerateTaggedPDF       = "generateTaggedPdf"
	FieldPrintBackground         = "printBackground"
	FieldOmitBackground          = "omitBackground"
	FieldLandscape               = "landscape"
	FieldScale                   = "scale"
	FieldNativePageRanges        = "nativePageRanges"
)
View Source
const (
	HeaderWebhookURL              = "Gotenberg-Webhook-Url"
	HeaderWebhookErrorURL         = "Gotenberg-Webhook-Error-Url"
	HeaderWebhookMethod           = "Gotenberg-Webhook-Method"
	HeaderWebhookErrorMethod      = "Gotenberg-Webhook-Error-Method"
	HeaderWebhookExtraHTTPHeaders = "Gotenberg-Webhook-Extra-Http-Headers"
)

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 ...ClientOptions) (*http.Response, error)

func (*Client) ConvertURLToPDF

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

type ClientOptions added in v0.1.1

type ClientOptions func(*clientOptions)

func WithFile added in v0.1.0

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

func WithLandscape

func WithLandscape(enabled bool) ClientOptions

func WithMargins

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

func WithOutputFilename

func WithOutputFilename(filename string) ClientOptions

func WithPaperSize

func WithPaperSize(width, height float64) ClientOptions

func WithPaperSizeA4 added in v0.0.3

func WithPaperSizeA4() ClientOptions

func WithPaperSizeLetter added in v0.0.3

func WithPaperSizeLetter() ClientOptions

func WithPrintBackground

func WithPrintBackground(enabled bool) ClientOptions

func WithScale

func WithScale(scale float64) ClientOptions

func WithSinglePage

func WithSinglePage(enabled bool) ClientOptions

func WithWebhookError added in v0.1.0

func WithWebhookError(errorURL, errorMethod string) ClientOptions

func WithWebhookExtraHeader added in v0.1.0

func WithWebhookExtraHeader(name, value string) ClientOptions

func WithWebhookSuccess added in v0.1.0

func WithWebhookSuccess(url, method string) ClientOptions

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