pdf

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pdf provides a wrapper around different PDF generation tools to provide single conversion process regardless of implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Data        []byte
	Filename    string
	Description string
}

Attachment is used to embed files inside the PDF when supported by the implementation.

type Config

type Config func(any)

Config defines options used to configure the PDF convertor.

func WithAuthToken

func WithAuthToken(token string) Config

WithAuthToken defines an authentication token to use to connect to the remote server if required by the PDF service.

func WithURL

func WithURL(url string) Config

WithURL sets the URL to use for the connection to a remote server if needed.

type Convertor

type Convertor interface {
	// HTML is the default implementation that takes a raw HTML file and converts it
	// into a PDF.
	HTML(ctx context.Context, data []byte, opts ...Option) ([]byte, error)
}

Convertor defines the interface expected to be able to convert sources into PDF

func New

func New(provider string, conf ...Config) (Convertor, error)

New creates a new PDF convertor using the provider and any Config options that it might require. This method maps the provider to the correct implementation, or returns nil if no matching convertor was found.

type Metadata

type Metadata struct {
	Title    string
	Subject  string
	Author   string
	Keywords string
	Creator  string
}

Metadata contains additional information to add to the PDF

type Option

type Option func(*options)

Option defines a functional option to configure the PDF conversion

func WithAttachment

func WithAttachment(a *Attachment) Option

WithAttachment adds the attachment to the conversion request.

func WithMetadata

func WithMetadata(md *Metadata) Option

WithMetadata adds the provided metadata to include in the conversion request.

func WithStylesheets added in v0.6.0

func WithStylesheets(src fs.FS) Option

WithStylesheets prepares the stylesheets to be included in the PDF generation request.

type Stylesheet added in v0.6.0

type Stylesheet struct {
	Data     []byte
	Filename string
}

Stylesheet descriptions a document to upload with the HTML for styles.

Jump to

Keyboard shortcuts

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