primitives

package
v0.16.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 28 Imported by: 18 modules, 31 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package primitives renders declarative page content and interactive form elements.

Index

Constants

This section is empty.

Variables

View Source
var ISO639Codes = []string{}/* 183 elements not displayed */

ISO639Codes contains supported ISO 639-1 language codes.

Functions

func CalcCheckBoxASNames added in v0.4.1

func CalcCheckBoxASNames(ctx *model.Context, d types.Dict) (types.Name, types.Name, error)

CalcCheckBoxASNames calculates check box as names.

func EnsureComboBoxAP added in v0.4.1

func EnsureComboBoxAP(c context.Context, ctx *model.Context, d types.Dict, v string, da *string, fonts map[string]types.IndirectRef) error

EnsureComboBoxAP ensures a combo box appearance and supports cancellation.

func EnsureDateFieldAP added in v0.4.1

func EnsureDateFieldAP(c context.Context, ctx *model.Context, d types.Dict, v string, da *string, fonts map[string]types.IndirectRef) error

EnsureDateFieldAP ensures a date field appearance and supports cancellation.

func EnsureListBoxAP added in v0.4.1

func EnsureListBoxAP(c context.Context, ctx *model.Context, d types.Dict, opts []string, ind types.Array, da *string, fonts map[string]types.IndirectRef) error

EnsureListBoxAP ensures a list box appearance and supports cancellation.

func EnsureTextFieldAP added in v0.4.1

func EnsureTextFieldAP(c context.Context, ctx *model.Context, d types.Dict, text string, multiLine, comb bool, maxLen int, da *string, fonts map[string]types.IndirectRef) error

EnsureTextFieldAP ensures a text field appearance and supports cancellation.

func FontIndRef added in v0.4.1

func FontIndRef(fName string, ctx *model.Context, fonts map[string]types.IndirectRef) (*types.IndirectRef, error)

FontIndRef font ind ref.

func FormFontDetails added in v0.11.0

func FormFontDetails(c context.Context, xRefTable *model.XRefTable, indRef types.IndirectRef) (string, string, string, error)

FormFontDetails returns form font details and supports cancellation.

func FormFontResDict added in v0.6.0

func FormFontResDict(xRefTable *model.XRefTable) (types.Dict, error)

FormFontResDict returns form dict's font resource dict.

func NewForm added in v0.4.1

func NewForm(xRefTable *model.XRefTable, bb []byte, fontID string, fontIndRef *types.IndirectRef, boundingBox *types.Rectangle) (*types.IndirectRef, error)

NewForm returns a new form.

Types

type AP

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

AP caches the appearance streams shared by checkboxes or radio buttons.

type Bar

type Bar struct {
	X, Y  float64 // either or determines orientation.
	Width int
	Color string `json:"col"`

	Style string

	Hide bool
	// contains filtered or unexported fields
}

Bar represents a horizontal or vertical bar used by content.

type Border

type Border struct {
	Name  string
	Width int
	Color string `json:"col"`

	Style string
	// contains filtered or unexported fields
}

Border defines the width, color, and line-join style of an element border.

type Buttons

type Buttons struct {
	Values []string
	Label  *TextFieldLabel
	Gap    int // horizontal space between radio button and its value
	// contains filtered or unexported fields
}

Buttons defines the choices and label layout of a radio-button group.

func (*Buttons) Rtl added in v0.4.0

func (b *Buttons) Rtl() bool

Rtl returns true if label is right to left.

type CheckBox

type CheckBox struct {
	Label    *TextFieldLabel
	ID       string
	Tip      string
	Value    bool // checked state
	Default  bool
	Position [2]float64 `json:"pos"` // x,y

	Width  float64
	Dx, Dy float64

	Margin          *Margin // applied to content box
	BackgroundColor string  `json:"bgCol"`

	Tab    int
	Locked bool
	Debug  bool
	Hide   bool
	// contains filtered or unexported fields
}

CheckBox represents a form checkbox including a positioned label.

type ComboBox added in v0.4.0

type ComboBox struct {
	Label    *TextFieldLabel
	ID       string
	Tip      string
	Default  string
	Value    string
	Options  []string
	Position [2]float64 `json:"pos"`

	Width       float64
	Dx, Dy      float64
	BoundingBox *types.Rectangle `json:"-"`
	Edit        bool
	Font        *FormFont

	Margin          *Margin
	Border          *Border
	BackgroundColor string             `json:"bgCol"`
	BgCol           *color.SimpleColor `json:"-"`
	Alignment       string             `json:"align"` // "Left", "Center", "Right"
	HorAlign        types.HAlignment   `json:"-"`
	RTL             bool
	Tab             int
	Locked          bool
	Debug           bool
	Hide            bool
	// contains filtered or unexported fields
}

ComboBox represents a specific choice form field including a positioned label.

func NewComboBox added in v0.4.0

func NewComboBox(c context.Context, ctx *model.Context, d types.Dict, v string, da *string, fonts map[string]types.IndirectRef) (*ComboBox, *types.IndirectRef, error)

NewComboBox creates a new combo box and supports cancellation.

func (*ComboBox) SetFontID added in v0.4.0

func (cb *ComboBox) SetFontID(s string)

SetFontID sets font ID.

type Content

type Content struct {
	BackgroundColor string `json:"bgCol"`

	Fonts    map[string]*FormFont // named fonts
	Margins  map[string]*Margin   // named margins
	Borders  map[string]*Border   // named borders
	Paddings map[string]*Padding  // named paddings
	Margin   *Margin              // content margin
	Border   *Border              // content border
	Padding  *Padding             // content padding
	Regions  *Regions

	Guides        []*Guide              // hor/vert guidelines for layout
	Bars          []*Bar                `json:"bar"`
	SimpleBoxes   []*SimpleBox          `json:"box"`
	SimpleBoxPool map[string]*SimpleBox `json:"boxes"`
	TextBoxes     []*TextBox            `json:"text"`
	TextBoxPool   map[string]*TextBox   `json:"texts"`
	ImageBoxes    []*ImageBox           `json:"image"`
	ImageBoxPool  map[string]*ImageBox  `json:"images"`
	Tables        []*Table              `json:"table"`
	TablePool     map[string]*Table     `json:"tables"`
	// Form elements
	TextFields        []*TextField           `json:"textfield"`        // input text fields with optional label
	DateFields        []*DateField           `json:"datefield"`        // input date fields with optional label
	CheckBoxes        []*CheckBox            `json:"checkbox"`         // input checkboxes with optional label
	RadioButtonGroups []*RadioButtonGroup    `json:"radiobuttongroup"` // input radiobutton groups with optional label
	ComboBoxes        []*ComboBox            `json:"combobox"`
	ListBoxes         []*ListBox             `json:"listbox"`
	FieldGroups       []*FieldGroup          `json:"fieldgroup"` // rectangular container holding form elements
	FieldGroupPool    map[string]*FieldGroup `json:"fieldgroups"`
	// contains filtered or unexported fields
}

Content represents page content.

func (*Content) BorderRect

func (c *Content) BorderRect() *types.Rectangle

BorderRect returns the border rect for c.

func (*Content) Box

func (c *Content) Box() *types.Rectangle

Box retunrs a rectangle for c.

type DateField added in v0.4.0

type DateField struct {
	Label      *TextFieldLabel
	ID         string
	Tip        string
	Value      string
	Default    string
	DateFormat string `json:"format"`

	Position [2]float64 `json:"pos"` // x,y

	Width       float64
	Dx, Dy      float64
	BoundingBox *types.Rectangle `json:"-"`
	Font        *FormFont

	Margin          *Margin // applied to content box
	Border          *Border
	BackgroundColor string             `json:"bgCol"`
	BgCol           *color.SimpleColor `json:"-"`
	Alignment       string             `json:"align"` // "Left", "Center", "Right"
	HorAlign        types.HAlignment   `json:"-"`
	Tab             int
	Locked          bool
	Debug           bool
	Hide            bool
	// contains filtered or unexported fields
}

DateField is a form field accepting date strings according to DateFormat including a positioned label.

func NewDateField added in v0.4.0

func NewDateField(c context.Context, ctx *model.Context, d types.Dict, v string, da *string, fontIndRef *types.IndirectRef, fonts map[string]types.IndirectRef) (*DateField, *types.IndirectRef, error)

NewDateField returns a new date field and supports cancellation.

func (*DateField) RefreshN added in v0.4.0

func (df *DateField) RefreshN(c context.Context, xRefTable *model.XRefTable, indRef *types.IndirectRef) error

RefreshN updates the normal appearance referred to by indRef according to df. RefreshN updates the normal appearance referred to by indRef and supports cancellation.

func (*DateField) SetFontID added in v0.4.0

func (df *DateField) SetFontID(s string)

SetFontID sets font ID.

type DateFormat added in v0.4.0

type DateFormat struct {
	Int string
	Ext string
}

DateFormat represents a supported date format. It consists of an internal and an external form.

func DateFormatForDate added in v0.4.0

func DateFormatForDate(date string) (*DateFormat, error)

DateFormatForDate returns the date format for given date string.

func DateFormatForFmtExt added in v0.4.0

func DateFormatForFmtExt(fmtExt string) (*DateFormat, error)

DateFormatForFmtExt returns the date format for an external format string.

func DateFormatForFmtInt added in v0.4.0

func DateFormatForFmtInt(fmtInt string) (*DateFormat, error)

DateFormatForFmtInt returns the date format for an internal format string.

type Divider

type Divider struct {
	Pos float64 `json:"at"` // fraction 0..1

	Width int    // 1..10
	Color string `json:"col"`
	// contains filtered or unexported fields
}

Divider is a positioned separator between two regions from p to q.

type FieldFlags

type FieldFlags int

FieldFlags represents the PDF form field flags. See table 221 et.al.

const (
	FieldReadOnly FieldFlags = 1 << iota
	FieldRequired
	FieldNoExport
	UnusedFlag4
	UnusedFlag5
	UnusedFlag6
	UnusedFlag7
	UnusedFlag8
	UnusedFlag9
	UnusedFlag10
	UnusedFlag11
	UnusedFlag12
	FieldMultiline
	FieldPassword
	FieldNoToggleToOff
	FieldRadio
	FieldPushbutton
	FieldCombo
	FieldEdit
	FieldSort
	FieldFileSelect
	FieldMultiselect
	FieldDoNotSpellCheck
	FieldDoNotScroll
	FieldComb
	FieldRichTextAndRadiosInUnison
	FieldCommitOnSelChange
)

PDF form field flag bits defined by PDF 32000 table 221 and related field-specific tables.

type FieldGroup added in v0.4.0

type FieldGroup struct {
	Name            string
	Value           string
	Border          *Border
	Padding         *Padding
	BackgroundColor string `json:"bgCol"`

	TextFields        []*TextField        `json:"textfield"`        // text fields with optional label
	DateFields        []*DateField        `json:"datefield"`        // date fields with optional label
	CheckBoxes        []*CheckBox         `json:"checkbox"`         // checkboxes with optional label
	RadioButtonGroups []*RadioButtonGroup `json:"radiobuttongroup"` // radiobutton groups with optional label
	ComboBoxes        []*ComboBox         `json:"combobox"`         // comboboxes with optional label
	ListBoxes         []*ListBox          `json:"listbox"`          // listboxes with optional label
	Hide              bool
	// contains filtered or unexported fields
}

FieldGroup is a container for fields.

type FormFont

type FormFont struct {
	Name   string
	Lang   string // ISO-639
	Script string // ISO-15924
	Size   float64
	Color  string `json:"col"`

	FillFont bool
	// contains filtered or unexported fields
}

FormFont defines a font used to render form fields.

func (FormFont) RTL added in v0.4.0

func (f FormFont) RTL() bool

RTL returns true if f is right-to-left.

func (*FormFont) SetCol added in v0.4.0

func (f *FormFont) SetCol(c color.SimpleColor)

SetCol sets col.

type Guide

type Guide struct {
	Position [2]float64 `json:"pos"` // x,y
	// contains filtered or unexported fields
}

Guide represents horizontal and vertical lines at (x,y) for layout purposes.

type HorizontalBand

type HorizontalBand struct {
	Left   string
	Center string
	Right  string

	Height          float64
	Dx, Dy          int
	BackgroundColor string `json:"bgCol"`

	Font   *FormFont
	From   int
	Thru   int
	Border bool
	RTL    bool
	// contains filtered or unexported fields
}

HorizontalBand is a horizontal region used for header and footer.

type ImageBox

type ImageBox struct {
	Name     string
	Src      string     `json:"src"` // path of image file name
	Data     *ImageData // TODO Implement
	Position [2]float64 `json:"pos"` // x,y

	Dx, Dy float64

	Anchor string

	Width           float64
	Height          float64
	Margin          *Margin
	Border          *Border
	Padding         *Padding
	BackgroundColor string `json:"bgCol"`

	Rotation float64 `json:"rot"`
	Url      string
	Hide     bool
	PageNr   string `json:"-"`
	// contains filtered or unexported fields
}

ImageBox is a rectangular region within content containing an image.

func (*ImageBox) RenderForFill added in v0.4.0

func (ib *ImageBox) RenderForFill(pdf *PDF, p *model.Page, pageNr int, imageMap model.ImageMap) error

RenderForFill renders ib during form filling.

type ImageData

type ImageData struct {
	Payload       string // base64 encoded image data
	Format        string // jpeg, png, webp, tiff, ccitt
	Width, Height int
}

ImageData represents a more direct way for providing image data for form filling scenarios.

type ListBox added in v0.4.0

type ListBox struct {
	Label    *TextFieldLabel
	ID       string
	Tip      string
	Default  string
	Defaults []string
	Value    string
	Values   []string
	Ind      types.Array `json:"-"`
	Options  []string
	Position [2]float64 `json:"pos"`

	Width       float64
	Height      float64
	Dx, Dy      float64
	BoundingBox *types.Rectangle `json:"-"`
	Multi       bool             `json:"multi"`
	Font        *FormFont

	Margin          *Margin
	Border          *Border
	BackgroundColor string             `json:"bgCol"`
	BgCol           *color.SimpleColor `json:"-"`
	Alignment       string             `json:"align"` // "Left", "Center", "Right"
	HorAlign        types.HAlignment   `json:"-"`
	RTL             bool
	Tab             int
	Locked          bool
	Debug           bool
	Hide            bool
	// contains filtered or unexported fields
}

ListBox represents a specific choice form field including a positioned label.

func NewListBox added in v0.4.0

func NewListBox(c context.Context, ctx *model.Context, d types.Dict, opts []string, ind types.Array, da *string, fonts map[string]types.IndirectRef) (*ListBox, *types.IndirectRef, error)

NewListBox creates a new list box and supports cancellation.

func (*ListBox) SetFontID added in v0.4.0

func (lb *ListBox) SetFontID(s string)

SetFontID sets font ID.

type Margin

type Margin struct {
	Name                     string
	Width                    float64
	Top, Right, Bottom, Left float64
}

Margin defines uniform or per-edge spacing around an element.

type PDF

type PDF struct {
	Paper string // default paper size

	Crop string // default crop box

	Origin string // origin of the coordinate system

	Guides          bool   // render guides for layouting
	ContentBox      bool   // render contentBox = cropBox - header - footer
	Debug           bool   // highlight element positions
	BackgroundColor string `json:"bgCol"`

	Fonts       map[string]*FormFont // global fonts
	FormFonts   map[string]*FormFont
	FieldIDs    types.StringSet
	Fields      types.Array
	InheritedDA string
	Header      *HorizontalBand
	Footer      *HorizontalBand
	Pages       map[string]*PDFPage

	Margin         *Margin                // the global margin named "margin"
	Border         *Border                // the global border named "border"
	Padding        *Padding               // the global padding named "padding"
	Margins        map[string]*Margin     // global named margins
	Borders        map[string]*Border     // global named borders
	Paddings       map[string]*Padding    // global named paddings
	SimpleBoxPool  map[string]*SimpleBox  `json:"boxes"`
	TextBoxPool    map[string]*TextBox    `json:"texts"`
	ImageBoxPool   map[string]*ImageBox   `json:"images"`
	TablePool      map[string]*Table      `json:"tables"`
	FieldGroupPool map[string]*FieldGroup `json:"fieldgroups"`
	Colors         map[string]string

	DirNames        map[string]string          `json:"dirs"`
	FileNames       map[string]string          `json:"files"`
	TimestampFormat string                     `json:"timestamp"`
	DateFormat      string                     `json:"dateFormat"`
	Conf            *model.Configuration       `json:"-"`
	XRefTable       *model.XRefTable           `json:"-"`
	Optimize        *model.OptimizationContext `json:"-"`
	FontResIDs      map[int]types.Dict         `json:"-"`
	XObjectResIDs   map[int]types.Dict         `json:"-"`
	CheckBoxAPs     map[float64]*AP            `json:"-"`
	RadioBtnAPs     map[float64]*AP            `json:"-"`
	HasForm         bool                       `json:"-"`
	OldFieldIDs     types.StringSet            `json:"-"`
	Offline         bool                       `json:"-"`
	Timeout         int                        `json:"-"`
	// contains filtered or unexported fields
}

PDF is the central structure for PDF generation.

func (*PDF) DuplicateField added in v0.4.0

func (pdf *PDF) DuplicateField(ID string) bool

DuplicateField returns true if field with ID is a duplicate field.

func (*PDF) RenderPages

func (pdf *PDF) RenderPages(c context.Context) ([]*model.Page, model.FontMap, error)

RenderPages renders page content into model.Pages and supports cancellation.

func (*PDF) Update added in v0.4.0

func (pdf *PDF) Update() bool

Update returns true if this is a PDF update.

func (*PDF) Validate

func (pdf *PDF) Validate(c context.Context) error

Validate validates pdf and supports cancellation.

type PDFPage

type PDFPage struct {
	Paper string // page size

	Crop string // page crop box

	BackgroundColor string `json:"bgCol"`

	Fonts          map[string]*FormFont // default fonts
	DA             types.Object
	Guides         []*Guide               // hor/vert guidelines for layout
	Margin         *Margin                // page margin
	Border         *Border                // page border
	Padding        *Padding               // page padding
	Margins        map[string]*Margin     // page scoped named margins
	Borders        map[string]*Border     // page scoped named borders
	Paddings       map[string]*Padding    // page scoped named paddings
	SimpleBoxPool  map[string]*SimpleBox  `json:"boxes"`
	TextBoxPool    map[string]*TextBox    `json:"texts"`
	ImageBoxPool   map[string]*ImageBox   `json:"images"`
	TablePool      map[string]*Table      `json:"tables"`
	FieldGroupPool map[string]*FieldGroup `json:"fieldgroups"`
	FileNames      map[string]string      `json:"files"`
	Tabs           types.IntSet           `json:"-"`
	Content        *Content
	// contains filtered or unexported fields
}

PDFPage represents a PDF page with content for generation.

type Padding

type Padding struct {
	Name                     string
	Width                    float64
	Top, Right, Bottom, Left float64
}

Padding defines uniform or per-edge spacing within an element.

type RadioButtonGroup

type RadioButtonGroup struct {
	Label    *TextFieldLabel
	ID       string
	Tip      string
	Value    string // checked button
	Default  string
	Position [2]float64 `json:"pos"` // x,y

	Width float64

	Orientation string

	Dx, Dy          float64
	Margin          *Margin // applied to content box
	BackgroundColor string  `json:"bgCol"`

	Buttons *Buttons
	RTL     bool
	Tab     int
	Locked  bool
	Debug   bool
	Hide    bool
	// contains filtered or unexported fields
}

RadioButtonGroup represents a set of radio buttons including positioned labels.

func (*RadioButtonGroup) Rtl added in v0.4.0

func (rbg *RadioButtonGroup) Rtl() bool

Rtl returns true if rbg is right-to-left.

type Regions

type Regions struct {
	Name        string // unique
	Orientation string `json:"orient"`

	Divider     *Divider `json:"div"`
	Left, Right *Content // 2 horizontal regions or
	Top, Bottom *Content // 2 vertical regions
	// contains filtered or unexported fields
}

Regions divides page content into two horizontal or vertical regions.

type SimpleBox

type SimpleBox struct {
	Name     string
	Position [2]float64 `json:"pos"` // x,y

	Dx, Dy float64
	Anchor string

	Width     float64
	Height    float64
	Margin    *Margin
	Border    *Border
	FillColor string `json:"fillCol"`

	Rotation float64 `json:"rot"`
	Hide     bool
	// contains filtered or unexported fields
}

SimpleBox is a positioned rectangular region within content.

type Table

type Table struct {
	Name     string
	Values   [][]string
	Position [2]float64 `json:"pos"` // x,y

	Dx, Dy float64
	Anchor string

	Width      float64 // if < 1 then fraction of content width
	Rows, Cols int
	ColWidths  []int // optional column width percentages
	ColAnchors []string

	ColPaddings     []*Padding
	LineHeight      int `json:"lheight"`
	Font            *FormFont
	Margin          *Margin
	Border          *Border
	Padding         *Padding
	BackgroundColor string `json:"bgCol"`
	OddColor        string `json:"oddCol"`
	EvenColor       string `json:"evenCol"`

	RTL      bool
	Rotation float64 `json:"rot"`
	Grid     bool
	Hide     bool
	Header   *TableHeader
	// contains filtered or unexported fields
}

Table represents a positioned fillable data grid including a header row.

func (*Table) Height

func (t *Table) Height() float64

Height returns the height of t.

type TableHeader

type TableHeader struct {
	Values     []string
	ColAnchors []string

	ColPaddings     []*Padding
	LineHeight      int    `json:"lheight"` // defaults to table.LineHeight
	BackgroundColor string `json:"bgCol"`

	Font *FormFont // defaults to table font
	RTL  bool
	// contains filtered or unexported fields
}

TableHeader defines table header values and their layout.

type TextBox

type TextBox struct {
	Name     string
	Value    string     // text, content
	Position [2]float64 `json:"pos"` // x,y

	Dx, Dy float64
	Anchor string

	Width float64

	Font    *FormFont
	Margin  *Margin // applied to content box
	Border  *Border
	Padding *Padding // applied to TextDescriptor marginx

	BackgroundColor string `json:"bgCol"`

	Alignment string `json:"align"` // "Left", "Center", "Right"

	RTL      bool
	Rotation float64 `json:"rot"`
	Hide     bool
	// contains filtered or unexported fields
}

TextBox represents a form text input field including a positioned label.

type TextField

type TextField struct {
	Label    *TextFieldLabel
	ID       string
	Tip      string
	Value    string
	Default  string
	Position [2]float64 `json:"pos"` // x,y

	Width       float64
	Height      float64
	Dx, Dy      float64
	BoundingBox *types.Rectangle `json:"-"`
	Multiline   bool
	Font        *FormFont

	Margin          *Margin // applied to content box
	Border          *Border
	BackgroundColor string             `json:"bgCol"`
	BgCol           *color.SimpleColor `json:"-"`
	Alignment       string             `json:"align"` // "Left", "Center", "Right"
	HorAlign        types.HAlignment   `json:"-"`
	MaxLen          int                `json:"maxlen"`
	Comb            bool               `json:"comb"`
	RTL             bool
	Tab             int
	Locked          bool
	Debug           bool
	Hide            bool
	// contains filtered or unexported fields
}

TextField defines a text form field and its visual appearance.

func NewTextField added in v0.4.0

func NewTextField(c context.Context, ctx *model.Context, d types.Dict, v string, multiLine, comb bool, maxLen int, da *string, fontIndRef *types.IndirectRef, fonts map[string]types.IndirectRef) (*TextField, *types.IndirectRef, error)

NewTextField returns a new text field and supports cancellation.

func (*TextField) RefreshN added in v0.4.0

func (tf *TextField) RefreshN(c context.Context, xRefTable *model.XRefTable, indRef *types.IndirectRef) error

RefreshN regenerates and stores the field's normal appearance stream and supports cancellation.

func (*TextField) SetFontID added in v0.4.0

func (tf *TextField) SetFontID(s string)

SetFontID sets font ID.

type TextFieldLabel

type TextFieldLabel struct {
	TextField
	Width int

	Gap      int    // horizontal space between textfield and label
	Position string `json:"pos"` // relative to textfield
	// contains filtered or unexported fields
}

TextFieldLabel represents a label for an input field.

Jump to

Keyboard shortcuts

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