chromium

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chromium provides a client for the Gotenberg Chromium service. It offers a convenient API for converting HTML, URLs, and Markdown to PDF documents and screenshots.

Index

Constants

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"
	HeaderOutputFilename          = "Gotenberg-Output-Filename"
	HeaderGotenbergTrace          = "Gotenberg-Trace"
)
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 (
	FieldURL                      = "url"
	FieldFiles                    = "files"
	FileIndexHTML                 = "index.html"
	FileFooterHTML                = "footer.html"
	FileHeaderHTML                = "header.html"
	FileStylesCSS                 = "styles.css"
	FieldWidth                    = "width"
	FieldHeight                   = "height"
	FieldClip                     = "clip"
	FieldFormat                   = "format"
	FieldQuality                  = "quality"
	FieldOmitBackgroundScreenshot = "omitBackground"
	FieldOptimizeForSpeed         = "optimizeForSpeed"
)

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 Chromium

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

Chromium represents a Gotenberg conversion request builder. It wraps the underlying multipart request and provides Gotenberg-specific methods.

func NewChromium

func NewChromium(client *httpclient.Client) *Chromium

func (*Chromium) Bool

func (r *Chromium) Bool(fieldName string, value bool) *Chromium

Bool adds a boolean form parameter to the conversion request.

func (*Chromium) ConvertHTML

func (r *Chromium) ConvertHTML(ctx context.Context, html io.Reader) *Chromium

ConvertHTML creates a request to convert HTML content to PDF. The html parameter should contain the HTML content to be converted.

func (*Chromium) ConvertMarkdown

func (r *Chromium) ConvertMarkdown(ctx context.Context, html io.Reader) *Chromium

ConvertMarkdown creates a request to convert Markdown content to PDF.

func (*Chromium) ConvertURL

func (r *Chromium) ConvertURL(ctx context.Context, url string) *Chromium

ConvertURL creates a request to convert a web page at the given URL to PDF.

func (*Chromium) DownloadFrom added in v1.7.1

func (r *Chromium) DownloadFrom(data any) *Chromium

DownloadFrom sets the downloadFrom parameter for downloading files from URLs. The data should be a slice of maps or structs representing the download configuration.

func (*Chromium) File

func (r *Chromium) File(filename string, content io.Reader) *Chromium

File adds a file to the conversion request.

func (*Chromium) Float

func (r *Chromium) Float(fieldName string, value float64) *Chromium

Float adds a float64 form parameter to the conversion request.

func (*Chromium) Header

func (r *Chromium) Header(key, value string) *Chromium

Header adds a header to the conversion request.

func (*Chromium) Margins

func (r *Chromium) Margins(top, right, bottom, left float64) *Chromium

Margins sets the page margins for the PDF in inches. Parameters are in order: top, right, bottom, left.

func (*Chromium) OutputFilename

func (r *Chromium) OutputFilename(filename string) *Chromium

OutputFilename sets the output filename for the generated PDF.

func (*Chromium) PaperSize

func (r *Chromium) PaperSize(width, height float64) *Chromium

PaperSize sets the paper size for the PDF using width and height in inches.

func (*Chromium) PaperSizeA4

func (r *Chromium) PaperSizeA4() *Chromium

PaperSizeA4 sets the paper size to A4 format.

func (*Chromium) PaperSizeA4Landscape

func (r *Chromium) PaperSizeA4Landscape() *Chromium

PaperSizeA4Landscape sets the paper size to A4 format in landscape orientation.

func (*Chromium) PaperSizeA6

func (r *Chromium) PaperSizeA6() *Chromium

PaperSizeA6 sets the paper size to A6 format.

func (*Chromium) PaperSizeA6Landscape

func (r *Chromium) PaperSizeA6Landscape() *Chromium

PaperSizeA6Landscape sets the paper size to A6 format in landscape orientation.

func (*Chromium) PaperSizeLetter

func (r *Chromium) PaperSizeLetter() *Chromium

PaperSizeLetter sets the paper size to Letter format.

func (*Chromium) PaperSizeLetterLandscape

func (r *Chromium) PaperSizeLetterLandscape() *Chromium

PaperSizeLetterLandscape sets the paper size to Letter format in landscape orientation.

func (*Chromium) Param

func (r *Chromium) Param(key, value string) *Chromium

Param adds a form parameter to the conversion request.

func (*Chromium) ScreenshotClip added in v1.7.1

func (r *Chromium) ScreenshotClip(clip bool) *Chromium

ScreenshotClip defines whether to clip the screenshot according to the device dimensions.

func (*Chromium) ScreenshotFormat added in v1.7.1

func (r *Chromium) ScreenshotFormat(format string) *Chromium

ScreenshotFormat sets the image compression format.

func (*Chromium) ScreenshotHTML added in v1.7.1

func (r *Chromium) ScreenshotHTML(ctx context.Context, html io.Reader) *Chromium

ScreenshotHTML creates a request to take a screenshot of HTML content.

func (*Chromium) ScreenshotHeight added in v1.7.1

func (r *Chromium) ScreenshotHeight(height int) *Chromium

ScreenshotHeight sets the device screen height in pixels.

func (*Chromium) ScreenshotMarkdown added in v1.7.1

func (r *Chromium) ScreenshotMarkdown(ctx context.Context, html io.Reader) *Chromium

ScreenshotMarkdown creates a request to take a screenshot of Markdown content.

func (*Chromium) ScreenshotOmitBackground added in v1.7.1

func (r *Chromium) ScreenshotOmitBackground(omit bool) *Chromium

ScreenshotOmitBackground hides the default white background and allows generating screenshots with transparency.

func (*Chromium) ScreenshotOptimizeForSpeed added in v1.7.1

func (r *Chromium) ScreenshotOptimizeForSpeed(optimize bool) *Chromium

ScreenshotOptimizeForSpeed defines whether to optimize image encoding for speed, not for resulting size.

func (*Chromium) ScreenshotQuality added in v1.7.1

func (r *Chromium) ScreenshotQuality(quality int) *Chromium

ScreenshotQuality sets the compression quality from range 0 to 100 (jpeg only).

func (*Chromium) ScreenshotURL added in v1.7.1

func (r *Chromium) ScreenshotURL(ctx context.Context, url string) *Chromium

ScreenshotURL creates a request to take a screenshot of a web page at the given URL.

func (*Chromium) ScreenshotWidth added in v1.7.1

func (r *Chromium) ScreenshotWidth(width int) *Chromium

ScreenshotWidth sets the device screen width in pixels.

func (*Chromium) Send

func (r *Chromium) Send() (*Response, error)

Send executes the conversion request and returns the response. Returns an error if the request fails or the conversion cannot be completed.

func (*Chromium) Trace added in v1.7.1

func (r *Chromium) Trace(trace string) *Chromium

Trace sets the request trace identifier for debugging and monitoring. If not set, Gotenberg will assign a unique UUID trace.

func (*Chromium) WebhookErrorURL

func (r *Chromium) WebhookErrorURL(url, method string) *Chromium

WebhookErrorURL sets the webhook URL and HTTP method for failed conversions.

func (*Chromium) WebhookHeader

func (r *Chromium) WebhookHeader(key, value string) *Chromium

WebhookHeader adds a custom header to be sent with webhook requests. Multiple headers can be added by calling this method multiple times.

func (*Chromium) WebhookURL

func (r *Chromium) WebhookURL(url, method string) *Chromium

WebhookURL sets the webhook URL and HTTP method for successful conversions.

type Response

type Response struct {
	*http.Response
	GotenbergTrace string
}

Response represents a Gotenberg conversion response. It wraps the HTTP response and provides access to the Gotenberg trace header.

Jump to

Keyboard shortcuts

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