gotenberg

package module
v8.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 15 Imported by: 0

README

Gotenberg Go Client

The Go client for interacting with a Gotenberg API. This project is a further development of the client from TheCodingMachine, which does not support the new functionality since version 7 of Gotenberg.


Gotenberg version Client version
8.x (actual) 8.6.3 (actual)
7.x <= 8.5.0
6.x thecodingmachine/gotenberg-go-client

Installation

To get the latest version of the client:

$ go get github.com/dcaraxes/gotenberg-go-client/v8@latest

Preparing a documents

package main

import (
	"net/http"
    "os"
	
    "github.com/dcaraxes/gotenberg-go-client/v8"
    "github.com/dcaraxes/gotenberg-go-client/v8/document"
)

func main() {
    // Create the Gotenberg client.
    client, err := gotenberg.NewClient("localhost:3000", http.DefaultClient)

    // There are several ways to create documents.
    f1, err := document.FromPath("data.pdf", "/path/to/file")
    f2, err := document.FromString("index.html", "<html>Foo</html>")
    f3, err := document.FromBytes("index.html", []byte("<html>Foo</html>"))

    r, err := os.Open("index.html")
    f4, err := document.FromReader("index.html", r)
}

Converting HTML to PDF

[!TIP] Head to the documentation to learn about all request parameters. For the PaperSize method, you can use predefined parameters such as gotenberg.A4, gotenberg.A3 and so on. The full list of predefined parameters can be found in types file.

[!IMPORTANT] To use basic authorization, you must run Gotenberg with the --api-enable-basic-auth flag and have GOTENBERG_API_BASIC_AUTH_USERNAME and GOTENBERG_API_BASIC_AUTH_PASSWORD environment variables.

package main

import (
	"context"
    "net/http"
    
    "github.com/dcaraxes/gotenberg-go-client/v8"
    "github.com/dcaraxes/gotenberg-go-client/v8/document"
)

func main() {
    client, err := gotenberg.NewClient("localhost:3000", http.DefaultClient)

    // Creates the Gotenberg documents from a files paths.
    index, err := document.FromPath("index.html", "/path/to/file")

    // Create the HTML request.
    req := gotenberg.NewHTMLRequest(index)

    // Loading style and image from the specified urls. 
    downloads := make(map[string]map[string]string)
    downloads["http://my.style.css"] = nil
    downloads["http://my.img.gif"] = map[string]string{"X-Header": "Foo"}

    req.DownloadFrom(downloads)

    // Setting up basic auth (if needed).
    req.UseBasicAuth("username", "password")

    // Set the document parameters to request (optional).
    req.Margins(gotenberg.NoMargins)
    req.Scale(0.75)
    req.PaperSize(gotenberg.A4)

    // Skips the IDLE events for faster PDF conversion.
    req.SkipNetworkIdleEvent()

    // Store method allows you to store the resulting PDF in a particular destination.
    err := client.Store(context.Background(), req, "path/to/store.pdf")

    // If you wish to redirect the response directly to the browser, you may also use:
    resp, err := client.Send(context.Background(), req)
}

Working with metadata

Reading metadata available only for PDF files, but you can write metadata to all Gotenberg supporting files.

Writing metadata:

[!TIP] You can write metadata to PDF for any request using the Metadata method.

package main

import (
	"context"
	"encoding/json"
    "net/http"

    "github.com/dcaraxes/gotenberg-go-client/v8"
    "github.com/dcaraxes/gotenberg-go-client/v8/document"
)

func main() {
    client, err := gotenberg.NewClient("localhost:3000", http.DefaultClient)
	
    // Prepare the files required for your conversion.
    doc, err := document.FromPath("filename.ext", "/path/to/file")
    req := gotenberg.NewWriteMetadataRequest(doc)

    // Sets result file name.
    req.OutputFilename("foo.pdf")

    data := struct {
        Author    string `json:"Author"`
        Copyright string `json:"Copyright"`
    }{
        Author:    "Author name",
        Copyright: "Copyright",
    }

    md, err := json.Marshal(data)
    req.Metadata(md)

    resp, err := client.Send(context.Background(), req)
}

Reading metadata:

package main

import (
	"context"
	"encoding/json"
	"net/http"

	"github.com/dcaraxes/gotenberg-go-client/v8"
	"github.com/dcaraxes/gotenberg-go-client/v8/document"
)

func main() {
	client, err := gotenberg.NewClient("localhost:3000", http.DefaultClient)

	// Prepare the files required for your conversion.
	doc, err := document.FromPath("filename.ext", "/path/to/file")
	req := gotenberg.NewReadMetadataRequest(doc)

	resp, err := client.Send(context.Background(), req)

	var data = struct {
		FooPdf struct {
			Author    string `json:"Author"`
			Copyright string `json:"Copyright"`
		} `json:"foo.pdf"`
	}

	// Decode metadata into a struct.
	err = json.NewDecoder(resp.Body).Decode(&data)
}

Creating screenshots

[!NOTE] Screenshot creation is only available for HTML, URL and Markdown requests.

package main

import (
	"context"
    "net/http"

    "github.com/dcaraxes/gotenberg-go-client/v8"
    "github.com/dcaraxes/gotenberg-go-client/v8/document"
)

func main() {
    client, err := gotenberg.NewClient("localhost:3000", http.DefaultClient)

    index, err := document.FromPath("index.html", "/path/to/file")

    // Create the HTML request and set the image format (optional).
    req := gotenberg.NewHTMLRequest(index)
    req.Format(gotenberg.JPEG)

    resp, err := client.Screenshot(context.Background(), req)
}


For more complete usages, head to the documentation.

Documentation

Overview

Package gotenberg is a Go client for interacting with a Gotenberg API.

For more complete usages, head to the documentation: https://gotenberg.dev/

Index

Constants

This section is empty.

Variables

View Source
var (
	// A0 paper size.
	A0 = PaperDimensions{
		Height: 46.8,
		Width:  33.1,
		Unit:   IN,
	}
	// A1 paper size.
	A1 = PaperDimensions{
		Height: 33.1,
		Width:  23.4,
		Unit:   IN,
	}
	// A2 paper size.
	A2 = PaperDimensions{
		Height: 23.4,
		Width:  16.5,
		Unit:   IN,
	}
	// A3 paper size.
	A3 = PaperDimensions{
		Height: 16.5,
		Width:  11.7,
		Unit:   IN,
	}
	// A4 paper size.
	A4 = PaperDimensions{
		Height: 11.7,
		Width:  8.27,
		Unit:   IN,
	}
	// A5 paper size.
	A5 = PaperDimensions{
		Height: 8.3,
		Width:  5.8,
		Unit:   IN,
	}
	// A6 paper size.
	A6 = PaperDimensions{
		Height: 5.8,
		Width:  4.1,
		Unit:   IN,
	}
	// Letter paper size.
	Letter = PaperDimensions{
		Height: 11,
		Width:  8.5,
		Unit:   IN,
	}
	// Legal paper size.
	Legal = PaperDimensions{
		Height: 14,
		Width:  8.5,
		Unit:   IN,
	}
	// Tabloid paper size.
	Tabloid = PaperDimensions{
		Height: 17,
		Width:  11,
		Unit:   IN,
	}
	// Ledger paper size.
	Ledger = PaperDimensions{
		Height: 17,
		Width:  11,
		Unit:   IN,
	}
)

nolint: gochecknoglobals

View Source
var (
	// NoMargins removes margins.
	NoMargins = PageMargins{
		Top:    0,
		Bottom: 0,
		Left:   0,
		Right:  0,
		Unit:   IN,
	}
	// NormalMargins uses 1-inch margins.
	NormalMargins = PageMargins{
		Top:    1,
		Bottom: 1,
		Left:   1,
		Right:  1,
		Unit:   IN,
	}
	// LargeMargins uses 2 inch margins.
	LargeMargins = PageMargins{
		Top:    2,
		Bottom: 2,
		Left:   2,
		Right:  2,
		Unit:   IN,
	}
)

nolint: gochecknoglobals

Functions

This section is empty.

Types

type Client

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

Client facilitates interacting with the Gotenberg API.

func NewClient added in v8.6.3

func NewClient(hostname string, httpClient *http.Client) (*Client, error)

func (*Client) Screenshot added in v8.0.1

func (c *Client) Screenshot(ctx context.Context, scr ScreenshotRequester) (*http.Response, error)

func (*Client) Send added in v8.6.3

func (c *Client) Send(ctx context.Context, req MainRequester) (*http.Response, error)

Send sends a request to the Gotenberg API and returns the response.

func (*Client) Store

func (c *Client) Store(ctx context.Context, req MainRequester, dest string) error

Store creates the resulting file to given destination.

func (*Client) StoreScreenshot added in v8.2.0

func (c *Client) StoreScreenshot(ctx context.Context, req ScreenshotRequester, dest string) error

type HTMLRequest

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

HTMLRequest facilitates HTML conversion with the Gotenberg API.

func NewHTMLRequest

func NewHTMLRequest(index document.Document) *HTMLRequest

func (*HTMLRequest) Assets

func (req *HTMLRequest) Assets(assets ...document.Document)

Assets sets assets form files.

func (HTMLRequest) Cookies added in v8.6.3

func (req HTMLRequest) Cookies(cookies []byte)

Cookies to store in the Chromium cookie jar (JSON array format).

func (HTMLRequest) EmulatePrintMediaType added in v8.6.3

func (req HTMLRequest) EmulatePrintMediaType()

EmulatePrintMediaType forces Chromium to emulate the media type "print".

func (HTMLRequest) EmulateScreenMediaType added in v8.6.3

func (req HTMLRequest) EmulateScreenMediaType()

EmulateScreenMediaType forces Chromium to emulate the media type "screen".

func (HTMLRequest) ExtraHTTPHeaders added in v8.6.3

func (req HTMLRequest) ExtraHTTPHeaders(headers []byte)

ExtraHTTPHeaders sets extra HTTP headers that Chromium will send when loading the HTML document.

func (HTMLRequest) FailOnConsoleExceptions added in v8.6.3

func (req HTMLRequest) FailOnConsoleExceptions()

FailOnConsoleExceptions forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console.

func (HTMLRequest) FailOnHTTPStatusCodes added in v8.6.3

func (req HTMLRequest) FailOnHTTPStatusCodes(statusCodes []byte)

FailOnHTTPStatusCodes forces Gotenberg to return a 409 Conflict response if the HTTP status code from the main page is not acceptable.

func (HTMLRequest) Footer

func (req HTMLRequest) Footer(footer document.Document)

Footer adds a footer to each page.

func (HTMLRequest) Format added in v8.0.3

func (req HTMLRequest) Format(format ImageFormat)

Format sets the image compression format, either PNG, JPEG or WEBP. Default is PNG.

func (HTMLRequest) Header

func (req HTMLRequest) Header(header document.Document)

Header adds a header to each page.

func (HTMLRequest) Landscape

func (req HTMLRequest) Landscape()

Landscape sets the paper orientation to landscape.

func (HTMLRequest) Margins

func (req HTMLRequest) Margins(margins PageMargins)

Margins sets marginTop, marginBottom, marginLeft and marginRight form fields. Default unit is inches.

func (HTMLRequest) Metadata added in v8.2.0

func (req HTMLRequest) Metadata(jsonData []byte)

Metadata sets the metadata to write.

func (HTMLRequest) NativePageRanges added in v8.6.3

func (req HTMLRequest) NativePageRanges(ranges string)

NativePageRanges sets the page ranges to print, e.g., "1-5, 8, 11-13". Empty means all pages.

func (HTMLRequest) OmitBackground added in v8.1.2

func (req HTMLRequest) OmitBackground()

OmitBackground hides default white background and allows generating PDFs with transparency.

func (HTMLRequest) PaperSize

func (req HTMLRequest) PaperSize(size PaperDimensions)

PaperSize sets paperWidth and paperHeight form fields with the provided unit. If unit is empty, it defaults to inches. Default is Letter (8.5 x 11 inches).

func (HTMLRequest) PdfA added in v8.5.0

func (req HTMLRequest) PdfA(pdfa PdfAFormat)

PdfA sets the PDF/A format of the resulting PDF.

func (HTMLRequest) PdfUA added in v8.5.0

func (req HTMLRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (HTMLRequest) PreferCSSPageSize added in v8.6.3

func (req HTMLRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (HTMLRequest) PrintBackground added in v8.1.2

func (req HTMLRequest) PrintBackground()

PrintBackground prints the background graphics.

func (HTMLRequest) Scale

func (req HTMLRequest) Scale(factor float64)

Scale overrides the default scale of the page rendering (i.e., 1.0).

func (HTMLRequest) ScreenshotClip added in v8.6.3

func (req HTMLRequest) ScreenshotClip()

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

func (HTMLRequest) ScreenshotHeight added in v8.6.3

func (req HTMLRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (HTMLRequest) ScreenshotOptimizeForSpeed added in v8.6.3

func (req HTMLRequest) ScreenshotOptimizeForSpeed()

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

func (HTMLRequest) ScreenshotQuality added in v8.6.3

func (req HTMLRequest) ScreenshotQuality(quality int)

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

func (HTMLRequest) ScreenshotWidth added in v8.6.3

func (req HTMLRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (HTMLRequest) SinglePage added in v8.0.1

func (req HTMLRequest) SinglePage()

SinglePage defines whether to print the entire content in one single page.

func (HTMLRequest) SkipNetworkIdleEvent

func (req HTMLRequest) SkipNetworkIdleEvent()

SkipNetworkIdleEvent specifies whether Chromium have to wait or not for its network to be idle. Enabled by default in Gotenberg >= 8.11.0.

func (HTMLRequest) UserAgent added in v8.6.3

func (req HTMLRequest) UserAgent(ua string)

UserAgent overrides the default User-Agent HTTP header.

func (HTMLRequest) WaitDelay

func (req HTMLRequest) WaitDelay(delay time.Duration)

WaitDelay sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML document before converting it to PDF.

func (HTMLRequest) WaitForExpression added in v8.6.3

func (req HTMLRequest) WaitForExpression(expression string)

WaitForExpression sets the JavaScript expression to wait before converting an HTML document into PDF until it returns true.

type ImageFormat added in v8.3.0

type ImageFormat string
const (
	PNG  ImageFormat = "png"
	JPEG ImageFormat = "jpeg"
	WebP ImageFormat = "webp"
)

type MainRequester added in v8.6.3

type MainRequester interface {
	// contains filtered or unexported methods
}

MainRequester is a type for sending form fields and form files (documents) to the Gotenberg API.

type MarkdownRequest

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

MarkdownRequest facilitates Markdown conversion with the Gotenberg API.

func NewMarkdownRequest

func NewMarkdownRequest(index document.Document, markdowns ...document.Document) *MarkdownRequest

func (*MarkdownRequest) Assets

func (req *MarkdownRequest) Assets(assets ...document.Document)

Assets sets assets form files.

func (MarkdownRequest) Cookies added in v8.6.3

func (req MarkdownRequest) Cookies(cookies []byte)

Cookies to store in the Chromium cookie jar (JSON array format).

func (MarkdownRequest) EmulatePrintMediaType added in v8.6.3

func (req MarkdownRequest) EmulatePrintMediaType()

EmulatePrintMediaType forces Chromium to emulate the media type "print".

func (MarkdownRequest) EmulateScreenMediaType added in v8.6.3

func (req MarkdownRequest) EmulateScreenMediaType()

EmulateScreenMediaType forces Chromium to emulate the media type "screen".

func (MarkdownRequest) ExtraHTTPHeaders added in v8.6.3

func (req MarkdownRequest) ExtraHTTPHeaders(headers []byte)

ExtraHTTPHeaders sets extra HTTP headers that Chromium will send when loading the HTML document.

func (MarkdownRequest) FailOnConsoleExceptions added in v8.6.3

func (req MarkdownRequest) FailOnConsoleExceptions()

FailOnConsoleExceptions forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console.

func (MarkdownRequest) FailOnHTTPStatusCodes added in v8.6.3

func (req MarkdownRequest) FailOnHTTPStatusCodes(statusCodes []byte)

FailOnHTTPStatusCodes forces Gotenberg to return a 409 Conflict response if the HTTP status code from the main page is not acceptable.

func (MarkdownRequest) Footer

func (req MarkdownRequest) Footer(footer document.Document)

Footer adds a footer to each page.

func (MarkdownRequest) Format added in v8.0.3

func (req MarkdownRequest) Format(format ImageFormat)

Format sets the image compression format, either PNG, JPEG or WEBP. Default is PNG.

func (MarkdownRequest) Header

func (req MarkdownRequest) Header(header document.Document)

Header adds a header to each page.

func (MarkdownRequest) Landscape

func (req MarkdownRequest) Landscape()

Landscape sets the paper orientation to landscape.

func (MarkdownRequest) Margins

func (req MarkdownRequest) Margins(margins PageMargins)

Margins sets marginTop, marginBottom, marginLeft and marginRight form fields. Default unit is inches.

func (*MarkdownRequest) Metadata added in v8.2.0

func (req *MarkdownRequest) Metadata(jsonData []byte)

func (MarkdownRequest) NativePageRanges added in v8.6.3

func (req MarkdownRequest) NativePageRanges(ranges string)

NativePageRanges sets the page ranges to print, e.g., "1-5, 8, 11-13". Empty means all pages.

func (MarkdownRequest) OmitBackground added in v8.1.2

func (req MarkdownRequest) OmitBackground()

OmitBackground hides default white background and allows generating PDFs with transparency.

func (MarkdownRequest) PaperSize

func (req MarkdownRequest) PaperSize(size PaperDimensions)

PaperSize sets paperWidth and paperHeight form fields with the provided unit. If unit is empty, it defaults to inches. Default is Letter (8.5 x 11 inches).

func (MarkdownRequest) PdfA added in v8.5.0

func (req MarkdownRequest) PdfA(pdfa PdfAFormat)

PdfA sets the PDF/A format of the resulting PDF.

func (MarkdownRequest) PdfUA added in v8.5.0

func (req MarkdownRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (MarkdownRequest) PreferCSSPageSize added in v8.6.3

func (req MarkdownRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (MarkdownRequest) PrintBackground added in v8.1.2

func (req MarkdownRequest) PrintBackground()

PrintBackground prints the background graphics.

func (MarkdownRequest) Scale

func (req MarkdownRequest) Scale(factor float64)

Scale overrides the default scale of the page rendering (i.e., 1.0).

func (MarkdownRequest) ScreenshotClip added in v8.6.3

func (req MarkdownRequest) ScreenshotClip()

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

func (MarkdownRequest) ScreenshotHeight added in v8.6.3

func (req MarkdownRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (MarkdownRequest) ScreenshotOptimizeForSpeed added in v8.6.3

func (req MarkdownRequest) ScreenshotOptimizeForSpeed()

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

func (MarkdownRequest) ScreenshotQuality added in v8.6.3

func (req MarkdownRequest) ScreenshotQuality(quality int)

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

func (MarkdownRequest) ScreenshotWidth added in v8.6.3

func (req MarkdownRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (MarkdownRequest) SinglePage added in v8.0.1

func (req MarkdownRequest) SinglePage()

SinglePage defines whether to print the entire content in one single page.

func (MarkdownRequest) SkipNetworkIdleEvent

func (req MarkdownRequest) SkipNetworkIdleEvent()

SkipNetworkIdleEvent specifies whether Chromium have to wait or not for its network to be idle. Enabled by default in Gotenberg >= 8.11.0.

func (MarkdownRequest) UserAgent added in v8.6.3

func (req MarkdownRequest) UserAgent(ua string)

UserAgent overrides the default User-Agent HTTP header.

func (MarkdownRequest) WaitDelay

func (req MarkdownRequest) WaitDelay(delay time.Duration)

WaitDelay sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML document before converting it to PDF.

func (MarkdownRequest) WaitForExpression added in v8.6.3

func (req MarkdownRequest) WaitForExpression(expression string)

WaitForExpression sets the JavaScript expression to wait before converting an HTML document into PDF until it returns true.

type MergeRequest

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

MergeRequest facilitates work with PDF files with the Gotenberg API.

func NewMergeRequest

func NewMergeRequest(pdfs ...document.Document) *MergeRequest

func (MergeRequest) DownloadFrom added in v8.6.3

func (br MergeRequest) DownloadFrom(downloads map[string]map[string]string)

DownloadFrom sets the URLs to download files from. This method accepts a JSON string e.g., [{"url":"http://localhost:80/","extraHttpHeaders":{"X-Foo":"Bar"}}]. For Go, this is equivalent to map[string]map[string]string, which this method accepts, but headers map can be nil.

URLs MUST return a Content-Disposition header with a filename parameter.

func (*MergeRequest) Metadata added in v8.2.0

func (req *MergeRequest) Metadata(md []byte)

Metadata sets the metadata to write.

func (MergeRequest) OutputFilename added in v8.6.3

func (br MergeRequest) OutputFilename(filename string)

OutputFilename overrides the default UUID output filename.

NOTE: Gotenberg adds the file extension automatically; you don't have to set it.

func (*MergeRequest) PdfA added in v8.6.3

func (req *MergeRequest) PdfA(pdfa PdfAFormat)

PdfA sets the PDF/A format of the resulting PDF.

func (*MergeRequest) PdfUA added in v8.6.3

func (req *MergeRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (MergeRequest) SetWebhookErrorMethod added in v8.6.3

func (br MergeRequest) SetWebhookErrorMethod(method string)

SetWebhookErrorMethod overrides the default HTTP method that Gotenberg will use to call the error webhook.

func (MergeRequest) SetWebhookExtraHeaders added in v8.6.3

func (br MergeRequest) SetWebhookExtraHeaders(headers []byte)

SetWebhookExtraHeaders sets the extra HTTP headers that Gotenberg will send alongside the request to the webhook and error webhook.

func (MergeRequest) SetWebhookMethod added in v8.6.3

func (br MergeRequest) SetWebhookMethod(method string)

SetWebhookMethod Overrides the default HTTP method that Gotenberg will use to call the webhook.

func (MergeRequest) Trace added in v8.6.3

func (br MergeRequest) Trace(trace string)

Trace overrides the default UUID trace, or request ID, that identifies a request in Gotenberg's logs.

func (MergeRequest) UseBasicAuth added in v8.6.3

func (br MergeRequest) UseBasicAuth(username, password string)

UseBasicAuth sets the basic authentication credentials.

func (MergeRequest) UseWebhook added in v8.6.3

func (br MergeRequest) UseWebhook(hookURL string, errorURL string)

UseWebhook sets the callback and error callback that Gotenberg will use to send respectively the output file and the error response.

type OfficeRequest

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

OfficeRequest facilitates LibreOffice documents conversion with the Gotenberg API.

func NewOfficeRequest

func NewOfficeRequest(docs ...document.Document) *OfficeRequest

func (*OfficeRequest) AddOriginalDocumentAsStream added in v8.4.1

func (req *OfficeRequest) AddOriginalDocumentAsStream()

AddOriginalDocumentAsStream specifies that a stream is inserted to the PDF file which contains the original document for archiving purposes.

func (*OfficeRequest) AllowDuplicateFieldNames added in v8.4.1

func (req *OfficeRequest) AllowDuplicateFieldNames()

AllowDuplicateFieldNames specifies whether multiple form fields exported are allowed to have the same field name.

func (*OfficeRequest) ConvertOooTargetToPdfTarget added in v8.4.1

func (req *OfficeRequest) ConvertOooTargetToPdfTarget()

ConvertOooTargetToPdfTarget specifies that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched.

func (OfficeRequest) DownloadFrom added in v8.6.3

func (br OfficeRequest) DownloadFrom(downloads map[string]map[string]string)

DownloadFrom sets the URLs to download files from. This method accepts a JSON string e.g., [{"url":"http://localhost:80/","extraHttpHeaders":{"X-Foo":"Bar"}}]. For Go, this is equivalent to map[string]map[string]string, which this method accepts, but headers map can be nil.

URLs MUST return a Content-Disposition header with a filename parameter.

func (*OfficeRequest) ExportBookmarks added in v8.6.3

func (req *OfficeRequest) ExportBookmarks(export bool)

ExportBookmarks specifies if bookmarks are exported to PDF.

func (*OfficeRequest) ExportBookmarksToPdfDestination added in v8.4.1

func (req *OfficeRequest) ExportBookmarksToPdfDestination()

ExportBookmarksToPdfDestination specifies that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination.

func (*OfficeRequest) ExportFormFields added in v8.6.3

func (req *OfficeRequest) ExportFormFields(export bool)

ExportFormFields specifies whether form fields are exported as widgets or only their fixed print representation is exported.

func (*OfficeRequest) ExportHiddenSlides added in v8.4.1

func (req *OfficeRequest) ExportHiddenSlides()

ExportHiddenSlides exports, for LibreOffice Impress, slides that are not included in slide shows.

func (*OfficeRequest) ExportLinksRelativeFsys added in v8.4.1

func (req *OfficeRequest) ExportLinksRelativeFsys()

ExportLinksRelativeFsys specifies that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location.

func (*OfficeRequest) ExportNotes added in v8.4.1

func (req *OfficeRequest) ExportNotes()

ExportNotes specifies if notes are exported to PDF.

func (*OfficeRequest) ExportNotesInMargin added in v8.4.1

func (req *OfficeRequest) ExportNotesInMargin()

ExportNotesInMargin specifies if notes in margin are exported to PDF.

func (*OfficeRequest) ExportNotesPages added in v8.4.1

func (req *OfficeRequest) ExportNotesPages()

ExportNotesPages specifies if notes pages are exported to PDF. Notes pages are available in Impress documents only.

func (*OfficeRequest) ExportOnlyNotesPages added in v8.4.1

func (req *OfficeRequest) ExportOnlyNotesPages()

ExportOnlyNotesPages specifies, if the form field exportNotesPages is set to true, if only notes pages are exported to PDF.

func (*OfficeRequest) ExportPlaceholders added in v8.4.1

func (req *OfficeRequest) ExportPlaceholders()

ExportPlaceholders exports the placeholders fields visual markings only. The exported placeholder is ineffective.

func (*OfficeRequest) Landscape

func (req *OfficeRequest) Landscape()

Landscape sets the paper orientation to landscape.

func (*OfficeRequest) LosslessImageCompression added in v8.5.0

func (req *OfficeRequest) LosslessImageCompression()

LosslessImageCompression specifies if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format.

func (*OfficeRequest) MaxImageResolution added in v8.5.0

func (req *OfficeRequest) MaxImageResolution(res int)

MaxImageResolution If the form field reduceImageResolution is set to true, tells if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200.

func (*OfficeRequest) Merge added in v8.5.0

func (req *OfficeRequest) Merge()

Merge merges the resulting PDFs.

func (*OfficeRequest) Metadata added in v8.2.0

func (req *OfficeRequest) Metadata(md []byte)

Metadata sets the metadata to write.

func (*OfficeRequest) NativePageRanges added in v8.6.3

func (req *OfficeRequest) NativePageRanges(ranges string)

NativePageRanges sets the page ranges to print, e.g., "1-4". Empty means all pages.

func (OfficeRequest) OutputFilename added in v8.6.3

func (br OfficeRequest) OutputFilename(filename string)

OutputFilename overrides the default UUID output filename.

NOTE: Gotenberg adds the file extension automatically; you don't have to set it.

func (*OfficeRequest) Password added in v8.6.3

func (req *OfficeRequest) Password(password string)

Password sets the password for opening the source file.

func (*OfficeRequest) PdfA added in v8.5.0

func (req *OfficeRequest) PdfA(pdfa PdfAFormat)

PdfA sets the PDF/A format of the resulting PDF.

func (*OfficeRequest) PdfUA added in v8.5.0

func (req *OfficeRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (*OfficeRequest) Quality added in v8.5.0

func (req *OfficeRequest) Quality(quality int)

Quality specifies the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.

func (*OfficeRequest) ReduceImageResolution added in v8.5.0

func (req *OfficeRequest) ReduceImageResolution()

ReduceImageResolution Specifies if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution.

func (OfficeRequest) SetWebhookErrorMethod added in v8.6.3

func (br OfficeRequest) SetWebhookErrorMethod(method string)

SetWebhookErrorMethod overrides the default HTTP method that Gotenberg will use to call the error webhook.

func (OfficeRequest) SetWebhookExtraHeaders added in v8.6.3

func (br OfficeRequest) SetWebhookExtraHeaders(headers []byte)

SetWebhookExtraHeaders sets the extra HTTP headers that Gotenberg will send alongside the request to the webhook and error webhook.

func (OfficeRequest) SetWebhookMethod added in v8.6.3

func (br OfficeRequest) SetWebhookMethod(method string)

SetWebhookMethod Overrides the default HTTP method that Gotenberg will use to call the webhook.

func (*OfficeRequest) SinglePageSheets added in v8.6.3

func (req *OfficeRequest) SinglePageSheets()

SinglePageSheets ignores each sheet’s paper size, print ranges and shown/hidden status and puts every sheet (even hidden sheets) on exactly one page.

func (*OfficeRequest) SkipEmptyPages added in v8.4.1

func (req *OfficeRequest) SkipEmptyPages()

SkipEmptyPages Specifies that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents.

func (OfficeRequest) Trace added in v8.6.3

func (br OfficeRequest) Trace(trace string)

Trace overrides the default UUID trace, or request ID, that identifies a request in Gotenberg's logs.

func (OfficeRequest) UseBasicAuth added in v8.6.3

func (br OfficeRequest) UseBasicAuth(username, password string)

UseBasicAuth sets the basic authentication credentials.

func (OfficeRequest) UseWebhook added in v8.6.3

func (br OfficeRequest) UseWebhook(hookURL string, errorURL string)

UseWebhook sets the callback and error callback that Gotenberg will use to send respectively the output file and the error response.

type PageMargins added in v8.1.3

type PageMargins struct {
	Top    float64
	Bottom float64
	Left   float64
	Right  float64
	Unit   SizeUnit
}

type PaperDimensions added in v8.1.3

type PaperDimensions struct {
	Width  float64
	Height float64
	Unit   SizeUnit
}

type PdfAFormat added in v8.5.0

type PdfAFormat string
const (
	// Deprecated: Beginning with version 7.6, LibreOffice has discontinued support for PDF/A-1a.
	PdfA1b PdfAFormat = "PDF/A-1b"
	PdfA2b PdfAFormat = "PDF/A-2b"
	PdfA3b PdfAFormat = "PDF/A-3b"
)

type ReadMetadataRequest added in v8.2.0

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

func NewReadMetadataRequest added in v8.2.0

func NewReadMetadataRequest(pdfs ...document.Document) *ReadMetadataRequest

func (ReadMetadataRequest) DownloadFrom added in v8.6.3

func (br ReadMetadataRequest) DownloadFrom(downloads map[string]map[string]string)

DownloadFrom sets the URLs to download files from. This method accepts a JSON string e.g., [{"url":"http://localhost:80/","extraHttpHeaders":{"X-Foo":"Bar"}}]. For Go, this is equivalent to map[string]map[string]string, which this method accepts, but headers map can be nil.

URLs MUST return a Content-Disposition header with a filename parameter.

func (ReadMetadataRequest) OutputFilename added in v8.6.3

func (br ReadMetadataRequest) OutputFilename(filename string)

OutputFilename overrides the default UUID output filename.

NOTE: Gotenberg adds the file extension automatically; you don't have to set it.

func (ReadMetadataRequest) SetWebhookErrorMethod added in v8.6.3

func (br ReadMetadataRequest) SetWebhookErrorMethod(method string)

SetWebhookErrorMethod overrides the default HTTP method that Gotenberg will use to call the error webhook.

func (ReadMetadataRequest) SetWebhookExtraHeaders added in v8.6.3

func (br ReadMetadataRequest) SetWebhookExtraHeaders(headers []byte)

SetWebhookExtraHeaders sets the extra HTTP headers that Gotenberg will send alongside the request to the webhook and error webhook.

func (ReadMetadataRequest) SetWebhookMethod added in v8.6.3

func (br ReadMetadataRequest) SetWebhookMethod(method string)

SetWebhookMethod Overrides the default HTTP method that Gotenberg will use to call the webhook.

func (ReadMetadataRequest) Trace added in v8.6.3

func (br ReadMetadataRequest) Trace(trace string)

Trace overrides the default UUID trace, or request ID, that identifies a request in Gotenberg's logs.

func (ReadMetadataRequest) UseBasicAuth added in v8.6.3

func (br ReadMetadataRequest) UseBasicAuth(username, password string)

UseBasicAuth sets the basic authentication credentials.

func (ReadMetadataRequest) UseWebhook added in v8.6.3

func (br ReadMetadataRequest) UseWebhook(hookURL string, errorURL string)

UseWebhook sets the callback and error callback that Gotenberg will use to send respectively the output file and the error response.

type ScreenshotRequester added in v8.6.3

type ScreenshotRequester interface {
	// contains filtered or unexported methods
}

type SizeUnit added in v8.1.3

type SizeUnit string
const (
	PT SizeUnit = "pt" // Points.
	PX SizeUnit = "px" // Pixels.
	IN SizeUnit = "in" // Inches.
	MM SizeUnit = "mm" // Millimeters.
	CM SizeUnit = "cm" // Centimeters.
	PC SizeUnit = "pc" // Picas.
)

type URLRequest

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

URLRequest facilitates remote URL conversion with the Gotenberg API.

func NewURLRequest

func NewURLRequest(url string) *URLRequest

func (URLRequest) Cookies added in v8.6.3

func (req URLRequest) Cookies(cookies []byte)

Cookies to store in the Chromium cookie jar (JSON array format).

func (URLRequest) EmulatePrintMediaType added in v8.6.3

func (req URLRequest) EmulatePrintMediaType()

EmulatePrintMediaType forces Chromium to emulate the media type "print".

func (URLRequest) EmulateScreenMediaType added in v8.6.3

func (req URLRequest) EmulateScreenMediaType()

EmulateScreenMediaType forces Chromium to emulate the media type "screen".

func (URLRequest) ExtraHTTPHeaders added in v8.6.3

func (req URLRequest) ExtraHTTPHeaders(headers []byte)

ExtraHTTPHeaders sets extra HTTP headers that Chromium will send when loading the HTML document.

func (URLRequest) FailOnConsoleExceptions added in v8.6.3

func (req URLRequest) FailOnConsoleExceptions()

FailOnConsoleExceptions forces Gotenberg to return a 409 Conflict response if there are exceptions in the Chromium console.

func (URLRequest) FailOnHTTPStatusCodes added in v8.6.3

func (req URLRequest) FailOnHTTPStatusCodes(statusCodes []byte)

FailOnHTTPStatusCodes forces Gotenberg to return a 409 Conflict response if the HTTP status code from the main page is not acceptable.

func (URLRequest) Footer

func (req URLRequest) Footer(footer document.Document)

Footer adds a footer to each page.

func (URLRequest) Format added in v8.0.3

func (req URLRequest) Format(format ImageFormat)

Format sets the image compression format, either PNG, JPEG or WEBP. Default is PNG.

func (URLRequest) Header

func (req URLRequest) Header(header document.Document)

Header adds a header to each page.

func (URLRequest) Landscape

func (req URLRequest) Landscape()

Landscape sets the paper orientation to landscape.

func (URLRequest) Margins

func (req URLRequest) Margins(margins PageMargins)

Margins sets marginTop, marginBottom, marginLeft and marginRight form fields. Default unit is inches.

func (*URLRequest) Metadata added in v8.2.0

func (req *URLRequest) Metadata(jsonData []byte)

func (URLRequest) NativePageRanges added in v8.6.3

func (req URLRequest) NativePageRanges(ranges string)

NativePageRanges sets the page ranges to print, e.g., "1-5, 8, 11-13". Empty means all pages.

func (URLRequest) OmitBackground added in v8.1.2

func (req URLRequest) OmitBackground()

OmitBackground hides default white background and allows generating PDFs with transparency.

func (URLRequest) PaperSize

func (req URLRequest) PaperSize(size PaperDimensions)

PaperSize sets paperWidth and paperHeight form fields with the provided unit. If unit is empty, it defaults to inches. Default is Letter (8.5 x 11 inches).

func (URLRequest) PdfA added in v8.5.0

func (req URLRequest) PdfA(pdfa PdfAFormat)

PdfA sets the PDF/A format of the resulting PDF.

func (URLRequest) PdfUA added in v8.5.0

func (req URLRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (URLRequest) PreferCSSPageSize added in v8.6.3

func (req URLRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (URLRequest) PrintBackground added in v8.1.2

func (req URLRequest) PrintBackground()

PrintBackground prints the background graphics.

func (URLRequest) Scale

func (req URLRequest) Scale(factor float64)

Scale overrides the default scale of the page rendering (i.e., 1.0).

func (URLRequest) ScreenshotClip added in v8.6.3

func (req URLRequest) ScreenshotClip()

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

func (URLRequest) ScreenshotHeight added in v8.6.3

func (req URLRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (URLRequest) ScreenshotOptimizeForSpeed added in v8.6.3

func (req URLRequest) ScreenshotOptimizeForSpeed()

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

func (URLRequest) ScreenshotQuality added in v8.6.3

func (req URLRequest) ScreenshotQuality(quality int)

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

func (URLRequest) ScreenshotWidth added in v8.6.3

func (req URLRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (URLRequest) SinglePage added in v8.0.1

func (req URLRequest) SinglePage()

SinglePage defines whether to print the entire content in one single page.

func (URLRequest) SkipNetworkIdleEvent

func (req URLRequest) SkipNetworkIdleEvent()

SkipNetworkIdleEvent specifies whether Chromium have to wait or not for its network to be idle. Enabled by default in Gotenberg >= 8.11.0.

func (URLRequest) UserAgent added in v8.6.3

func (req URLRequest) UserAgent(ua string)

UserAgent overrides the default User-Agent HTTP header.

func (URLRequest) WaitDelay

func (req URLRequest) WaitDelay(delay time.Duration)

WaitDelay sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML document before converting it to PDF.

func (URLRequest) WaitForExpression added in v8.6.3

func (req URLRequest) WaitForExpression(expression string)

WaitForExpression sets the JavaScript expression to wait before converting an HTML document into PDF until it returns true.

type WriteMetadataRequest added in v8.2.0

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

func NewWriteMetadataRequest added in v8.2.0

func NewWriteMetadataRequest(pdfs ...document.Document) *WriteMetadataRequest

func (WriteMetadataRequest) DownloadFrom added in v8.6.3

func (br WriteMetadataRequest) DownloadFrom(downloads map[string]map[string]string)

DownloadFrom sets the URLs to download files from. This method accepts a JSON string e.g., [{"url":"http://localhost:80/","extraHttpHeaders":{"X-Foo":"Bar"}}]. For Go, this is equivalent to map[string]map[string]string, which this method accepts, but headers map can be nil.

URLs MUST return a Content-Disposition header with a filename parameter.

func (*WriteMetadataRequest) Metadata added in v8.2.0

func (wmd *WriteMetadataRequest) Metadata(md []byte)

func (WriteMetadataRequest) OutputFilename added in v8.6.3

func (br WriteMetadataRequest) OutputFilename(filename string)

OutputFilename overrides the default UUID output filename.

NOTE: Gotenberg adds the file extension automatically; you don't have to set it.

func (WriteMetadataRequest) SetWebhookErrorMethod added in v8.6.3

func (br WriteMetadataRequest) SetWebhookErrorMethod(method string)

SetWebhookErrorMethod overrides the default HTTP method that Gotenberg will use to call the error webhook.

func (WriteMetadataRequest) SetWebhookExtraHeaders added in v8.6.3

func (br WriteMetadataRequest) SetWebhookExtraHeaders(headers []byte)

SetWebhookExtraHeaders sets the extra HTTP headers that Gotenberg will send alongside the request to the webhook and error webhook.

func (WriteMetadataRequest) SetWebhookMethod added in v8.6.3

func (br WriteMetadataRequest) SetWebhookMethod(method string)

SetWebhookMethod Overrides the default HTTP method that Gotenberg will use to call the webhook.

func (WriteMetadataRequest) Trace added in v8.6.3

func (br WriteMetadataRequest) Trace(trace string)

Trace overrides the default UUID trace, or request ID, that identifies a request in Gotenberg's logs.

func (WriteMetadataRequest) UseBasicAuth added in v8.6.3

func (br WriteMetadataRequest) UseBasicAuth(username, password string)

UseBasicAuth sets the basic authentication credentials.

func (WriteMetadataRequest) UseWebhook added in v8.6.3

func (br WriteMetadataRequest) UseWebhook(hookURL string, errorURL string)

UseWebhook sets the callback and error callback that Gotenberg will use to send respectively the output file and the error response.

Directories

Path Synopsis
Package test contains useful functions used across tests.
Package test contains useful functions used across tests.

Jump to

Keyboard shortcuts

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