chromium

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gotenberg provides a client for the Gotenberg service. It offers a convenient API for converting HTML and URLs to PDF documents.

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"
)

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) File

func (r *Chromium) File(key, 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) MarkdownFile

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

MarkdownFile adds a markdown file to the conversion request. This method should be used with ConvertMarkdown to add .md files for conversion.

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) 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) 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