config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config implements custom configuration builder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeConfig

func NormalizeConfig(cfg *entity.Config) *entity.Config

NormalizeConfig returns an independent, valid config for Paper runtime use. It preserves caller-provided values where valid and falls back to builder defaults for required fields that are missing or invalid.

Types

type Builder

type Builder interface {
	Build() *entity.Config
	// contains filtered or unexported methods
}

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.

type CfgBuilder

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

func NewCfgBuilder

func NewCfgBuilder() *CfgBuilder

NewCfgBuilder creates a concrete configuration builder. NewBuilder keeps returning the public Builder interface, while this function exposes the concrete builder for callers that need fluent methods.

func (*CfgBuilder) Build

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

Build finalizes the customization returning the entity.Config.

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

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

WithBottomMargin customize margin.

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.

func (*CfgBuilder) WithCreationDate

func (b *CfgBuilder) WithCreationDate(creationDate 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 paper 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) WithHTMLLimits

func (b *CfgBuilder) WithHTMLLimits(limits entity.HTMLLimits) Builder

WithHTMLLimits configures resource limits for AddHTML/FromHTML translation.

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.

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(pageOrientation consts.Orientation) Builder

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

func (*CfgBuilder) WithOutlineFromHeadings added in v0.2.0

func (b *CfgBuilder) WithOutlineFromHeadings(enabled bool) Builder

WithOutlineFromHeadings makes HTML conversion (AddHTML/FromHTML) add h1-h6 headings to the PDF document outline: h1 becomes a level-0 entry, h2 a level-1 entry, and so on. Hidden headings are skipped. Default: off.

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.

func (*CfgBuilder) WithProtection

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

WithProtection defines protection types to the PDF document.

Protection uses the PDF standard security handler. RC4 is the compatibility default; use WithProtectionAlgorithm to select AES-128. Protection deters casual copying or printing, but is not confidentiality-grade encryption. For confidentiality, encrypt the file at rest or in transit.

func (*CfgBuilder) WithProtectionAlgorithm

func (b *CfgBuilder) WithProtectionAlgorithm(algorithm protection.Encryption) Builder

WithProtectionAlgorithm selects the protection encryption algorithm.

The default remains the legacy RC4 security handler for compatibility. AES128 selects AESV2, PDF standard security handler revision 4.

func (*CfgBuilder) WithRightMargin

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

WithRightMargin customize margin.

func (*CfgBuilder) WithSequentialLowMemoryMode

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

WithSequentialLowMemoryMode defines that paper 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 paper 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.

func (*CfgBuilder) WithUnsafeNoHTMLLimits

func (b *CfgBuilder) WithUnsafeNoHTMLLimits() Builder

WithUnsafeNoHTMLLimits disables resource limits for AddHTML/FromHTML.

func (*CfgBuilder) WithWatermark added in v0.2.0

func (b *CfgBuilder) WithWatermark(text string, ps ...props.Watermark) Builder

WithWatermark stamps every page with translucent diagonal text, drawn under the page content. Optional props customize font, size, color, opacity, and angle; zero values fall back to defaults (48pt, alpha 0.12, 45 degrees). An empty text removes the watermark.

Jump to

Keyboard shortcuts

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