primitives

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ISO-639 country codes See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Functions

func CalcCheckBoxASNames

func CalcCheckBoxASNames(d types.Dict) (types.Name, types.Name)

func EnsureComboBoxAP

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

func EnsureDateFieldAP

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

func EnsureListBoxAP

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

func EnsureTextFieldAP

func EnsureTextFieldAP(ctx *model.Context, d types.Dict, v string, multiLine bool, fonts map[string]types.IndirectRef) error

func FontIndRef

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

func FormFontNameAndLangForID

func FormFontNameAndLangForID(xRefTable *model.XRefTable, indRef types.IndirectRef) (string, string, error)

func FormFontResDict

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

FormFontResDict returns form dict's font resource dict.

func NewForm

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

Types

type AP

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

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
}

type Buttons

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

func (*Buttons) Rtl

func (b *Buttons) Rtl() bool

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

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

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

NewComboBox creates a new combobox for d.

func (*ComboBox) SetFontID

func (cb *ComboBox) SetFontID(s string)

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

type DateField

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

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

NewDateField returns a new date field for d.

func (*DateField) RefreshN

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

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

func (*DateField) SetFontID

func (df *DateField) SetFontID(s string)

type DateFormat

type DateFormat struct {
	Int string
	Ext string
}

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

func DateFormatForDate

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

DateFormatForDate returns the date format for given date string.

func DateFormatForFmtExt

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

DateFormatForFmtInt returns the date format for an external format string.

func DateFormatForFmtInt

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
)

type FieldGroup

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   int
	Color  string `json:"col"`
	// contains filtered or unexported fields
}

func (FormFont) RTL

func (f FormFont) RTL() bool

func (*FormFont) SetCol

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

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

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

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

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

NewListBox creates a new listbox for d.

func (*ListBox) SetFontID

func (lb *ListBox) SetFontID(s string)

type Margin

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

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:"-"`
	// contains filtered or unexported fields
}

PDF is the central structure for PDF generation.

func (*PDF) DuplicateField

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

func (*PDF) RenderPages

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

RenderPages renders page content into model.Pages

func (*PDF) Update

func (pdf *PDF) Update() bool

func (*PDF) Validate

func (pdf *PDF) Validate() error

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
}

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

func (rbg *RadioButtonGroup) Rtl() bool

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
}

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

type TableHeader

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

	ColPaddings     []*Padding
	BackgroundColor string `json:"bgCol"`

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

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:"-"`
	RTL             bool
	Tab             int
	Locked          bool
	Debug           bool
	Hide            bool
	// contains filtered or unexported fields
}

func NewTextField

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

func (*TextField) RefreshN

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

func (*TextField) SetFontID

func (tf *TextField) SetFontID(s string)

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