config

package
v0.0.0-...-40a6ac2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

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.Size) 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 *properties.Font) Builder
	WithPageNumber(pageNumber ...properties.PageNumber) Builder
	WithProtection(protectionType protection.Protection, userPassword, ownerPassword string) Builder
	WithCompression(compression bool) Builder
	WithOrientation(orientation orientation.Orient) 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.Extension) 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.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

func main() {
	cfg := config.NewBuilder().Build()

	_ = bpdf.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.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

func main() {
	cfg := config.NewBuilder().Build()

	_ = bpdf.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.Extension) Builder

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

func (*CfgBuilder) WithBottomMargin

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

WithBottomMargin customize margin.

Example

ExampleCfgBuilder_WithBottomMargin demonstrates how to customize margin.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

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

	_ = bpdf.New(cfg)

	// generate document
}
Output:

func (*CfgBuilder) WithCompression

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

WithCompression defines compression.

func (*CfgBuilder) WithConcurrentMode

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.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

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

	_ = bpdf.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 bpdf will draw borders in everything.

func (*CfgBuilder) WithDefaultFont

func (b *CfgBuilder) WithDefaultFont(font *properties.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

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

WithKeywords defines the document's keyword metadata.

func (*CfgBuilder) WithLeftMargin

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

WithLeftMargin customize margin.

Example

ExampleCfgBuilder_WithLeftMargin demonstrates how to customize margin.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

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

	_ = bpdf.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.Orient) 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 ...properties.PageNumber) Builder

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

func (*CfgBuilder) WithPageSize

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

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

Example

ExampleCfgBuilder_WithPageSize demonstrates how to customize page size.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
	"github.com/pchchv/bpdf/consts/pagesize"
)

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

	_ = bpdf.New(cfg)

	// generate document
}
Output:

func (*CfgBuilder) WithProtection

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

WithProtection defines protection types to the PDF document.

func (*CfgBuilder) WithRightMargin

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

WithRightMargin customize margin.

Example

ExampleCfgBuilder_WithRightMargin demonstrates how to customize margin.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

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

	_ = bpdf.New(cfg)

	// generate document
}
Output:

func (*CfgBuilder) WithSequentialLowMemoryMode

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

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

func (*CfgBuilder) WithSequentialMode

func (b *CfgBuilder) WithSequentialMode() Builder

WithSequentialMode defines that bpdf 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

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

WithTopMargin customize margin.

Example

ExampleCfgBuilder_WithTopMargin demonstrates how to customize margin.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

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

	_ = bpdf.New(cfg)

	// generate document
}
Output:

Jump to

Keyboard shortcuts

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