form

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportFormJSON

func ExportFormJSON(xRefTable *model.XRefTable, source string, w io.Writer) (bool, error)

ExportFormJSON extracts form data originating from source from xRefTable and writes a JSON representation to w.

func FieldMap

func FieldMap(fieldNames, formRecord []string) (map[string]CSVFieldAttributes, map[string]*Page, error)

FieldMap returns structures needed to fill a form via CSV.

func FillDetails

func FillDetails(form *Form, fieldMap map[string]CSVFieldAttributes) func(id, name string, fieldType FieldType, format DataFormat) ([]string, bool, bool)

FillDetails returns a closure that returns new form data provided by CSV or JSON.

func FillForm

func FillForm(
	ctx *model.Context,
	fillDetails func(id, name string, fieldType FieldType, format DataFormat) ([]string, bool, bool),
	imgs map[string]*Page,
	format DataFormat) (bool, []*model.Page, error)

FillForm populates form fields as provided by fillDetails and also supports virtual image fields.

func FormFields

func FormFields(ctx *model.Context) ([]Field, *FieldMeta, error)

FormFields returns all form fields present in ctx.

func ListFormFields

func ListFormFields(ctx *model.Context) ([]string, error)

ListFormFields returns a list of all form fields present in ctx.

func LockFormFields

func LockFormFields(ctx *model.Context, fieldIDsOrNames []string) (bool, error)

LockFormFields turns all form fields contained in fieldIDsOrNames into read-only.

func RemoveFormFields

func RemoveFormFields(ctx *model.Context, fieldIDsOrNames []string) (bool, error)

RemoveFormFields deletes all form fields with given ID or name from the form represented by xRefTable.

func ResetFormFields

func ResetFormFields(ctx *model.Context, fieldIDsOrNames []string) (bool, error)

ResetFormFields clears or resets all form fields contained in fieldIDsOrNames to its default.

func UnlockFormFields

func UnlockFormFields(ctx *model.Context, fieldIDsOrNames []string) (bool, error)

UnlockFields turns all form fields contained in fieldIDsOrNames writeable.

Types

type CSVFieldAttributes

type CSVFieldAttributes struct {
	Values []string
	Lock   bool
}

CSVFieldAttributes represent the value(s) and the lock state for a field.

type CheckBox

type CheckBox struct {
	Pages   []int  `json:"pages"`
	ID      string `json:"id"`
	Name    string `json:"name,omitempty"`
	Default bool   `json:"default"`
	Value   bool   `json:"value"`
	Locked  bool   `json:"locked"`
}

RadioButtonGroup represents a form checkbox.

type ComboBox

type ComboBox struct {
	Pages    []int    `json:"pages"`
	ID       string   `json:"id"`
	Name     string   `json:"name,omitempty"`
	Editable bool     `json:"editable"`
	Options  []string `json:"options"`
	Default  string   `json:"default,omitempty"`
	Value    string   `json:"value"`
	Locked   bool     `json:"locked"`
}

ComboBox represents a form combobox.

type DataFormat

type DataFormat int
const (
	CSV DataFormat = iota
	JSON
)

type DateField

type DateField struct {
	Pages   []int  `json:"pages"`
	ID      string `json:"id"`
	Name    string `json:"name,omitempty"`
	Format  string `json:"format"`
	Default string `json:"default,omitempty"`
	Value   string `json:"value"`
	Locked  bool   `json:"locked"`
}

DateField represents an Acroform date field.

type Field

type Field struct {
	Pages  []int
	Locked bool
	Typ    FieldType
	ID     string
	Name   string
	Dv     string
	V      string
	Opts   string
}

Field represents a form field for s particular page number.

type FieldMeta

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

type FieldType

type FieldType int

FieldType represents a form field type.

const (
	FTText FieldType = iota
	FTDate
	FTCheckBox
	FTComboBox
	FTListBox
	FTRadioButtonGroup
)

func (FieldType) String

func (ft FieldType) String() string

type Form

type Form struct {
	TextFields        []*TextField        `json:"textfield,omitempty"`
	DateFields        []*DateField        `json:"datefield,omitempty"`
	CheckBoxes        []*CheckBox         `json:"checkbox,omitempty"`
	RadioButtonGroups []*RadioButtonGroup `json:"radiobuttongroup,omitempty"`
	ComboBoxes        []*ComboBox         `json:"combobox,omitempty"`
	ListBoxes         []*ListBox          `json:"listbox,omitempty"`
	Pages             map[string]*Page    `json:"pages,omitempty"`
}

Form represents a PDF form (aka. Acroform).

type FormGroup

type FormGroup struct {
	Header Header `json:"header"`
	Forms  []Form `json:"forms"`
}

FormGroup represents a JSON struct containing a sequence of form instances.

func ExportForm

func ExportForm(xRefTable *model.XRefTable, source string) (*FormGroup, bool, error)

ExportForm extracts form data originating from source from xRefTable.

type Header struct {
	Source   string   `json:"source"`
	Version  string   `json:"version"`
	Creation string   `json:"creation"`
	ID       []string `json:"id,omitempty"`
	Title    string   `json:"title,omitempty"`
	Author   string   `json:"author,omitempty"`
	Creator  string   `json:"creator,omitempty"`
	Producer string   `json:"producer,omitempty"`
	Subject  string   `json:"subject,omitempty"`
	Keywords string   `json:"keywords,omitempty"`
}

Header represents form meta data.

type ListBox

type ListBox struct {
	Pages    []int    `json:"pages"`
	ID       string   `json:"id"`
	Name     string   `json:"name,omitempty"`
	Multi    bool     `json:"multi"`
	Options  []string `json:"options"`
	Defaults []string `json:"defaults,omitempty"`
	Values   []string `json:"values,omitempty"`
	Locked   bool     `json:"locked"`
}

ListBox represents a form listbox.

type Page

type Page struct {
	ImageBoxes []*primitives.ImageBox `json:"image,omitempty"`
}

Page is a container for page imageboxes.

type RadioButtonGroup

type RadioButtonGroup struct {
	Pages   []int    `json:"pages"`
	ID      string   `json:"id"`
	Name    string   `json:"name,omitempty"`
	Options []string `json:"options"`
	Default string   `json:"default,omitempty"`
	Value   string   `json:"value"`
	Locked  bool     `json:"locked"`
}

RadioButtonGroup represents a form radio button group.

type TextField

type TextField struct {
	Pages     []int  `json:"pages"`
	ID        string `json:"id"`
	Name      string `json:"name,omitempty"`
	Default   string `json:"default,omitempty"`
	Value     string `json:"value"`
	Multiline bool   `json:"multiline"`
	Locked    bool   `json:"locked"`
}

TextField represents a form text field.

Jump to

Keyboard shortcuts

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