gotenberg

package module
v0.0.0-...-973c507 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 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.2 (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@latest

Preparing a documents

package main

import (
    "os"
	
    "github.com/dcaraxes/gotenberg-go-client"
    "github.com/dcaraxes/gotenberg-go-client/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 (
    "net/http"
    
    "github.com/dcaraxes/gotenberg-go-client"
    "github.com/dcaraxes/gotenberg-go-client/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.
    client.Store(req, "path/to/store.pdf")

    // If you wish to redirect the response directly to the browser, you may also use:
    resp, err := client.Send(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 (
    "net/http"

    "github.com/dcaraxes/gotenberg-go-client"
    "github.com/dcaraxes/gotenberg-go-client/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(req)
}

Reading metadata:

package main

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

    "github.com/dcaraxes/gotenberg-go-client"
    "github.com/dcaraxes/gotenberg-go-client/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(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 (
    "net/http"

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

func main() {
    c, 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(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

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

func (*Client) Screenshot

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

func (*Client) Send

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

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

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

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

func (HTMLRequest) EmulatePrintMediaType

func (req HTMLRequest) EmulatePrintMediaType()

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

func (HTMLRequest) EmulateScreenMediaType

func (req HTMLRequest) EmulateScreenMediaType()

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

func (HTMLRequest) ExtraHTTPHeaders

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

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

func (HTMLRequest) FailOnConsoleExceptions

func (req HTMLRequest) FailOnConsoleExceptions()

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

func (HTMLRequest) FailOnHTTPStatusCodes

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

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

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

Metadata sets the metadata to write.

func (HTMLRequest) NativePageRanges

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

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

func (req HTMLRequest) PdfA(pdfa PdfAFormat)

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

func (HTMLRequest) PdfUA

func (req HTMLRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (HTMLRequest) PreferCSSPageSize

func (req HTMLRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (HTMLRequest) PrintBackground

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

func (req HTMLRequest) ScreenshotClip()

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

func (HTMLRequest) ScreenshotHeight

func (req HTMLRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (HTMLRequest) ScreenshotOptimizeForSpeed

func (req HTMLRequest) ScreenshotOptimizeForSpeed()

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

func (HTMLRequest) ScreenshotQuality

func (req HTMLRequest) ScreenshotQuality(quality int)

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

func (HTMLRequest) ScreenshotWidth

func (req HTMLRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (HTMLRequest) SinglePage

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

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

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

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

type MainRequester

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

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

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

func (MarkdownRequest) EmulatePrintMediaType

func (req MarkdownRequest) EmulatePrintMediaType()

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

func (MarkdownRequest) EmulateScreenMediaType

func (req MarkdownRequest) EmulateScreenMediaType()

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

func (MarkdownRequest) ExtraHTTPHeaders

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

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

func (MarkdownRequest) FailOnConsoleExceptions

func (req MarkdownRequest) FailOnConsoleExceptions()

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

func (MarkdownRequest) FailOnHTTPStatusCodes

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

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

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

func (MarkdownRequest) NativePageRanges

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

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

func (req MarkdownRequest) PdfA(pdfa PdfAFormat)

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

func (MarkdownRequest) PdfUA

func (req MarkdownRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (MarkdownRequest) PreferCSSPageSize

func (req MarkdownRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (MarkdownRequest) PrintBackground

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

func (req MarkdownRequest) ScreenshotClip()

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

func (MarkdownRequest) ScreenshotHeight

func (req MarkdownRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (MarkdownRequest) ScreenshotOptimizeForSpeed

func (req MarkdownRequest) ScreenshotOptimizeForSpeed()

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

func (MarkdownRequest) ScreenshotQuality

func (req MarkdownRequest) ScreenshotQuality(quality int)

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

func (MarkdownRequest) ScreenshotWidth

func (req MarkdownRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (MarkdownRequest) SinglePage

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

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

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

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

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

Metadata sets the metadata to write.

func (MergeRequest) OutputFilename

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

func (req *MergeRequest) PdfA(pdfa PdfAFormat)

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

func (*MergeRequest) PdfUA

func (req *MergeRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (MergeRequest) SetWebhookErrorMethod

func (br MergeRequest) SetWebhookErrorMethod(method string)

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

func (MergeRequest) SetWebhookExtraHeaders

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

func (br MergeRequest) SetWebhookMethod(method string)

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

func (MergeRequest) Trace

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

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

UseBasicAuth sets the basic authentication credentials.

func (MergeRequest) UseWebhook

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

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

func (req *OfficeRequest) AllowDuplicateFieldNames()

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

func (*OfficeRequest) ConvertOooTargetToPdfTarget

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

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

func (req *OfficeRequest) ExportBookmarks(export bool)

ExportBookmarks specifies if bookmarks are exported to PDF.

func (*OfficeRequest) ExportBookmarksToPdfDestination

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

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

func (req *OfficeRequest) ExportHiddenSlides()

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

func (*OfficeRequest) ExportLinksRelativeFsys

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

func (req *OfficeRequest) ExportNotes()

ExportNotes specifies if notes are exported to PDF.

func (*OfficeRequest) ExportNotesInMargin

func (req *OfficeRequest) ExportNotesInMargin()

ExportNotesInMargin specifies if notes in margin are exported to PDF.

func (*OfficeRequest) ExportNotesPages

func (req *OfficeRequest) ExportNotesPages()

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

func (*OfficeRequest) ExportOnlyNotesPages

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

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

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

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

func (req *OfficeRequest) Merge()

Merge merges the resulting PDFs.

func (*OfficeRequest) Metadata

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

Metadata sets the metadata to write.

func (*OfficeRequest) NativePageRanges

func (req *OfficeRequest) NativePageRanges(ranges string)

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

func (OfficeRequest) OutputFilename

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

func (req *OfficeRequest) Password(password string)

Password sets the password for opening the source file.

func (*OfficeRequest) PdfA

func (req *OfficeRequest) PdfA(pdfa PdfAFormat)

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

func (*OfficeRequest) PdfUA

func (req *OfficeRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (*OfficeRequest) Quality

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

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

func (br OfficeRequest) SetWebhookErrorMethod(method string)

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

func (OfficeRequest) SetWebhookExtraHeaders

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

func (br OfficeRequest) SetWebhookMethod(method string)

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

func (*OfficeRequest) SinglePageSheets

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

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

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

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

UseBasicAuth sets the basic authentication credentials.

func (OfficeRequest) UseWebhook

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

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

type PaperDimensions

type PaperDimensions struct {
	Width  float64
	Height float64
	Unit   SizeUnit
}

type PdfAFormat

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

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

func NewReadMetadataRequest

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

func (ReadMetadataRequest) DownloadFrom

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

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

func (br ReadMetadataRequest) SetWebhookErrorMethod(method string)

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

func (ReadMetadataRequest) SetWebhookExtraHeaders

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

func (br ReadMetadataRequest) SetWebhookMethod(method string)

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

func (ReadMetadataRequest) Trace

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

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

UseBasicAuth sets the basic authentication credentials.

func (ReadMetadataRequest) UseWebhook

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

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

type SizeUnit

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

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

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

func (URLRequest) EmulatePrintMediaType

func (req URLRequest) EmulatePrintMediaType()

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

func (URLRequest) EmulateScreenMediaType

func (req URLRequest) EmulateScreenMediaType()

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

func (URLRequest) ExtraHTTPHeaders

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

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

func (URLRequest) FailOnConsoleExceptions

func (req URLRequest) FailOnConsoleExceptions()

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

func (URLRequest) FailOnHTTPStatusCodes

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

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

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

func (URLRequest) NativePageRanges

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

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

func (req URLRequest) PdfA(pdfa PdfAFormat)

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

func (URLRequest) PdfUA

func (req URLRequest) PdfUA()

PdfUA enables PDF for Universal Access for optimal accessibility.

func (URLRequest) PreferCSSPageSize

func (req URLRequest) PreferCSSPageSize()

PreferCSSPageSize forces page size as defined by CSS.

func (URLRequest) PrintBackground

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

func (req URLRequest) ScreenshotClip()

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

func (URLRequest) ScreenshotHeight

func (req URLRequest) ScreenshotHeight(height float64)

ScreenshotHeight sets the device screen height in pixels.

func (URLRequest) ScreenshotOptimizeForSpeed

func (req URLRequest) ScreenshotOptimizeForSpeed()

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

func (URLRequest) ScreenshotQuality

func (req URLRequest) ScreenshotQuality(quality int)

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

func (URLRequest) ScreenshotWidth

func (req URLRequest) ScreenshotWidth(width float64)

ScreenshotWidth Width sets the device screen width in pixels.

func (URLRequest) SinglePage

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

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

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

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

func NewWriteMetadataRequest

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

func (WriteMetadataRequest) DownloadFrom

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

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

func (WriteMetadataRequest) OutputFilename

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

func (br WriteMetadataRequest) SetWebhookErrorMethod(method string)

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

func (WriteMetadataRequest) SetWebhookExtraHeaders

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

func (br WriteMetadataRequest) SetWebhookMethod(method string)

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

func (WriteMetadataRequest) Trace

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

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

UseBasicAuth sets the basic authentication credentials.

func (WriteMetadataRequest) UseWebhook

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