builder

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromImage

func FromImage(src image.Image) *semantic.Image

ImageFromGoImage converts a standard Go image.Image to *semantic.Image. It handles RGB color and creates a Soft Mask (SMask) for transparency if needed.

func ImageFromFile

func ImageFromFile(path string) (*semantic.Image, error)

ImageFromFile loads an image from a file path and converts it to *semantic.Image.

Types

type AppearanceGenerator

type AppearanceGenerator struct {
	Form *semantic.AcroForm
}

AppearanceGenerator handles the generation of appearance streams for form fields.

func NewAppearanceGenerator

func NewAppearanceGenerator(form *semantic.AcroForm) *AppearanceGenerator

func (*AppearanceGenerator) Generate

type CellPadding

type CellPadding struct {
	Top, Right, Bottom, Left float64
}

CellPadding defines per-side padding.

type Color

type Color struct {
	R, G, B float64
	A       float64
}

Color represents an RGB color (alpha is ignored for now).

type FormBuilder

type FormBuilder interface {
	// SetText sets the value of a text field.
	SetText(name, value string) FormBuilder
	// SetCheckbox sets the state of a checkbox.
	SetCheckbox(name string, checked bool) FormBuilder
	// SetChoice sets the selected value of a choice field (combo box or list box).
	SetChoice(name, value string) FormBuilder
	// Finish returns to the PDFBuilder.
	Finish() PDFBuilder
}

FormBuilder provides a fluent API for form filling.

type HAlign

type HAlign string

HAlign controls horizontal text alignment within a cell.

const (
	HAlignLeft   HAlign = "left"
	HAlignCenter HAlign = "center"
	HAlignRight  HAlign = "right"
)

type ImageOptions

type ImageOptions struct {
	Interpolate bool
	SMask       *semantic.Image
}

ImageOptions configures image drawing.

type LineOptions

type LineOptions struct {
	StrokeColor Color
	LineWidth   float64
	LineCap     contentstream.LineCap
	DashPattern []float64
	DashPhase   float64
}

LineOptions configures line drawing.

type Outline

type Outline struct {
	Title     string
	Page      *semantic.Page
	PageIndex int
	X         *float64
	Y         *float64
	Zoom      *float64
	Children  []Outline
}

Outline defines a bookmark entry for the builder API. Page or PageIndex can be set; if both are provided, Page takes precedence.

type PDFBuilder

type PDFBuilder interface {
	NewPage(width, height float64) PageBuilder
	AddPage(page *semantic.Page) PDFBuilder
	SetInfo(info *semantic.DocumentInfo) PDFBuilder
	SetMetadata(xmp []byte) PDFBuilder
	SetLanguage(lang string) PDFBuilder
	SetMarked(marked bool) PDFBuilder
	AddPageLabel(pageIndex int, prefix string) PDFBuilder
	AddOutline(out Outline) PDFBuilder
	SetEncryption(ownerPassword, userPassword string, perms raw.Permissions, encryptMetadata bool) PDFBuilder
	RegisterFont(name string, font *semantic.Font) PDFBuilder
	RegisterTrueTypeFont(name string, data []byte) PDFBuilder
	AddEmbeddedFile(file semantic.EmbeddedFile) PDFBuilder
	SetCalculationOrder(fields []semantic.FormField) PDFBuilder
	Form() FormBuilder
	Build() (*semantic.Document, error)
}

PDFBuilder provides a fluent API for PDF construction.

func NewBuilder

func NewBuilder() PDFBuilder

NewBuilder constructs a PDFBuilder.

type PageBuilder

type PageBuilder interface {
	DrawText(text string, x, y float64, opts TextOptions) PageBuilder
	DrawPath(path *contentstream.Path, opts PathOptions) PageBuilder
	DrawImage(img *semantic.Image, x, y, width, height float64, opts ImageOptions) PageBuilder
	DrawRectangle(x, y, width, height float64, opts RectOptions) PageBuilder
	DrawLine(x1, y1, x2, y2 float64, opts LineOptions) PageBuilder
	DrawTable(table Table, opts TableOptions) PageBuilder
	AddAnnotation(ann semantic.Annotation) PageBuilder
	AddFormField(field semantic.FormField) PageBuilder
	SetMediaBox(box semantic.Rectangle) PageBuilder
	SetCropBox(box semantic.Rectangle) PageBuilder
	SetRotation(degrees int) PageBuilder
	Finish() PDFBuilder
}

PageBuilder provides a fluent API for page construction.

type PathOptions

type PathOptions struct {
	StrokeColor Color
	FillColor   Color
	LineWidth   float64
	LineCap     contentstream.LineCap
	LineJoin    contentstream.LineJoin
	DashPattern []float64
	DashPhase   float64
	Fill        bool
	Stroke      bool
}

PathOptions configures path drawing.

type RectOptions

type RectOptions = PathOptions

RectOptions configures rectangle drawing (defaults to stroke if neither fill nor stroke is set).

type Table

type Table struct {
	Columns    []float64
	Rows       []TableRow
	HeaderRows int
}

Table defines a matrix of cells to draw.

type TableCell

type TableCell struct {
	Text            string
	Font            string
	FontSize        float64
	Padding         *CellPadding
	BackgroundColor Color
	TextColor       Color
	BorderColor     Color
	BorderWidth     float64
	ColSpan         int
	HAlign          HAlign
	VAlign          VAlign
	Tag             string
}

TableCell configures individual table cell rendering.

type TableOptions

type TableOptions struct {
	X             float64
	Y             float64
	RowHeight     float64
	CellPadding   float64
	BorderColor   Color
	BorderWidth   float64
	HeaderFill    Color
	RepeatHeaders bool
	Tagged        bool
	BottomMargin  float64
	DefaultFont   string
	DefaultSize   float64
	TopMargin     float64
	LeftMargin    float64
}

TableOptions configures table rendering.

type TableRow

type TableRow struct {
	Cells []TableCell
}

TableRow wraps a slice of cells.

type TextOptions

type TextOptions struct {
	Font         string
	FontSize     float64
	Color        Color
	RenderMode   contentstream.TextRenderMode
	CharSpacing  float64
	WordSpacing  float64
	HorizScaling float64
	Rise         float64
	Tag          string
	MCID         *int
	Rotate       float64 // Rotation in degrees (counter-clockwise)
}

TextOptions configures text drawing.

type VAlign

type VAlign string

VAlign controls vertical text alignment within a cell.

const (
	VAlignTop    VAlign = "top"
	VAlignMiddle VAlign = "middle"
	VAlignBottom VAlign = "bottom"
)

Jump to

Keyboard shortcuts

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