config

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: MIT Imports: 12 Imported by: 22

Documentation

Overview

Package config implements custom configuration builder.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	WithPageSize(size pagesize.Type) Builder
	WithDimensions(width float64, height float64) Builder
	WithLeftMargin(left float64) Builder
	WithTopMargin(top float64) Builder
	WithRightMargin(right float64) Builder
	WithBottomMargin(bottom float64) Builder
	WithConcurrentMode(chunkWorkers int) Builder
	WithSequentialMode() Builder
	WithSequentialLowMemoryMode(chunkWorkers int) Builder
	WithDebug(on bool) Builder
	WithMaxGridSize(maxGridSize int) Builder
	WithDefaultFont(font *props.Font) Builder
	WithPageNumber(pageNumber ...props.PageNumber) Builder
	WithProtection(protectionType protection.Type, userPassword, ownerPassword string) Builder
	WithCompression(compression bool) Builder
	WithOrientation(orientation orientation.Type) Builder
	WithAuthor(author string, isUTF8 bool) Builder
	WithCreator(creator string, isUTF8 bool) Builder
	WithSubject(subject string, isUTF8 bool) Builder
	WithTitle(title string, isUTF8 bool) Builder
	WithCreationDate(time time.Time) Builder
	WithCustomFonts([]*entity.CustomFont) Builder
	WithBackgroundImage([]byte, extension.Type) Builder
	WithDisableAutoPageBreak(disabled bool) Builder
	WithKeywords(keywordsStr string, isUTF8 bool) Builder
	Build() *entity.Config
}

Builder is the abstraction responsible for global customizations on the document.

func NewBuilder

func NewBuilder() Builder

NewBuilder is responsible to create an instance of Builder.

Example

ExampleNewBuilder demonstrates how to use builder.

cfg := config.NewBuilder().Build()

_ = maroto.New(cfg)

// generate document
Output:

type CfgBuilder

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

func (*CfgBuilder) Build

func (b *CfgBuilder) Build() *entity.Config

Build finalizes the customization returning the entity.Config.

Example

ExampleCfgBuilder_Build demonstrates how to build configs.

cfg := config.NewBuilder().Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithAuthor

func (b *CfgBuilder) WithAuthor(author string, isUTF8 bool) Builder

WithAuthor defines the author name metadata.

func (*CfgBuilder) WithBackgroundImage

func (b *CfgBuilder) WithBackgroundImage(bytes []byte, ext extension.Type) Builder

WithBackgroundImage defines the background image that will be applied in every page.

func (*CfgBuilder) WithBottomMargin added in v2.0.7

func (b *CfgBuilder) WithBottomMargin(bottom float64) Builder

WithBottomMargin customize margin.

Example

ExampleCfgBuilder_WithBottomMargin demonstrates how to customize margin.

// If top less than minimum, ignore customization.
cfg := config.NewBuilder().
	WithBottomMargin(15).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithCompression

func (b *CfgBuilder) WithCompression(compression bool) Builder

WithCompression defines compression.

func (*CfgBuilder) WithConcurrentMode added in v2.0.1

func (b *CfgBuilder) WithConcurrentMode(chunkWorkers int) Builder

WithConcurrentMode defines concurrent generation, chunk workers define how mano chuncks will be executed concurrently.

Example

ExampleCfgBuilder_WithConcurrentMode demonstrates how to enable concurrent generation.

// if chunkWorkers is less than 1, then ignore customization.
chunkWorkers := 7
cfg := config.NewBuilder().
	WithConcurrentMode(chunkWorkers).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithCreationDate

func (b *CfgBuilder) WithCreationDate(time time.Time) Builder

WithCreationDate defines the creation date metadata.

func (*CfgBuilder) WithCreator

func (b *CfgBuilder) WithCreator(creator string, isUTF8 bool) Builder

WithCreator defines the creator name metadata.

func (*CfgBuilder) WithCustomFonts

func (b *CfgBuilder) WithCustomFonts(customFonts []*entity.CustomFont) Builder

WithCustomFonts add custom fonts.

func (*CfgBuilder) WithDebug

func (b *CfgBuilder) WithDebug(on bool) Builder

WithDebug defines a debug behaviour where maroto will draw borders in everything.

func (*CfgBuilder) WithDefaultFont

func (b *CfgBuilder) WithDefaultFont(font *props.Font) Builder

WithDefaultFont defines a custom font, other than arial. This can be used to define a custom font as default.

func (*CfgBuilder) WithDimensions

func (b *CfgBuilder) WithDimensions(width float64, height float64) Builder

WithDimensions defines custom page dimensions, this overrides page size.

func (*CfgBuilder) WithDisableAutoPageBreak

func (b *CfgBuilder) WithDisableAutoPageBreak(disabled bool) Builder

WithDisableAutoPageBreak defines the option to disable automatic page breaks.

func (*CfgBuilder) WithKeywords added in v2.0.5

func (b *CfgBuilder) WithKeywords(keywordsStr string, isUTF8 bool) Builder

WithKeywords defines the document's keyword metadata.

func (*CfgBuilder) WithLeftMargin added in v2.0.7

func (b *CfgBuilder) WithLeftMargin(left float64) Builder

WithLeftMargin customize margin.

Example

ExampleCfgBuilder_WithLeftMargin demonstrates how to customize margin.

// If top less than minimum, ignore customization.
cfg := config.NewBuilder().
	WithLeftMargin(15).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithMaxGridSize

func (b *CfgBuilder) WithMaxGridSize(maxGridSize int) Builder

WithMaxGridSize defines a custom max grid sum which it will change the sum of column sizes.

func (*CfgBuilder) WithOrientation

func (b *CfgBuilder) WithOrientation(orientation orientation.Type) Builder

WithOrientation defines the page orientation. The default orientation is vertical, if horizontal is defined width and height will be flipped.

func (*CfgBuilder) WithPageNumber

func (b *CfgBuilder) WithPageNumber(pageNumber ...props.PageNumber) Builder

WithPageNumber defines a string pattern to write the current page and total.

func (*CfgBuilder) WithPageSize

func (b *CfgBuilder) WithPageSize(size pagesize.Type) Builder

WithPageSize defines the page size, ex: A4, A4 and etc.

Example

ExampleCfgBuilder_WithPageSize demonstrates how to customize page size.

// If pagesize is invalid, then ignore customization.
cfg := config.NewBuilder().
	WithPageSize(pagesize.A5).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithProtection

func (b *CfgBuilder) WithProtection(protectionType protection.Type, userPassword, ownerPassword string) Builder

WithProtection defines protection types to the PDF document.

func (*CfgBuilder) WithRightMargin added in v2.0.7

func (b *CfgBuilder) WithRightMargin(right float64) Builder

WithRightMargin customize margin.

Example

ExampleCfgBuilder_WithRightMargin demonstrates how to customize margin.

// If top less than minimum, ignore customization.
cfg := config.NewBuilder().
	WithRightMargin(15).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

func (*CfgBuilder) WithSequentialLowMemoryMode added in v2.0.1

func (b *CfgBuilder) WithSequentialLowMemoryMode(chunkWorkers int) Builder

WithSequentialLowMemoryMode defines that maroto will run focusing in reduce memory consumption, chunk workers define how many divisions the work will have.

func (*CfgBuilder) WithSequentialMode added in v2.0.1

func (b *CfgBuilder) WithSequentialMode() Builder

WithSequentialMode defines that maroto will run in default mode.

func (*CfgBuilder) WithSubject

func (b *CfgBuilder) WithSubject(subject string, isUTF8 bool) Builder

WithSubject defines the subject metadata.

func (*CfgBuilder) WithTitle

func (b *CfgBuilder) WithTitle(title string, isUTF8 bool) Builder

WithTitle defines the title metadata.

func (*CfgBuilder) WithTopMargin added in v2.0.7

func (b *CfgBuilder) WithTopMargin(top float64) Builder

WithTopMargin customize margin.

Example

ExampleCfgBuilder_WithTopMargin demonstrates how to customize margin.

// If top less than minimum, ignore customization.
cfg := config.NewBuilder().
	WithTopMargin(15).
	Build()

_ = maroto.New(cfg)

// generate document
Output:

Jump to

Keyboard shortcuts

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