entity

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 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 entity contains all core entities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcroForm added in v0.2.2

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

AcroForm manages generated PDF interactive form fields.

func CloneAcroForm added in v0.2.2

func CloneAcroForm(form *AcroForm) *AcroForm

CloneAcroForm returns a deep copy of form.

func NewAcroForm added in v0.2.2

func NewAcroForm() *AcroForm

NewAcroForm creates an empty AcroForm.

func (*AcroForm) Add added in v0.2.2

func (af *AcroForm) Add(f *Field) *AcroForm

Add appends a field and returns the form for chaining.

func (*AcroForm) Fields added in v0.2.2

func (af *AcroForm) Fields() []*Field

Fields returns the top-level fields in insertion order.

type AnnotationType added in v0.2.2

type AnnotationType string

AnnotationType identifies a PDF annotation subtype supported by Paper.

const (
	AnnotationLink      AnnotationType = "Link"
	AnnotationText      AnnotationType = "Text"
	AnnotationHighlight AnnotationType = "Highlight"
	AnnotationUnderline AnnotationType = "Underline"
	AnnotationSquiggly  AnnotationType = "Squiggly"
	AnnotationStrikeOut AnnotationType = "StrikeOut"
)

The annotation subtypes Paper can emit.

type Cell

type Cell struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
}

Cell represents a cell inside the PDF.

func NewRootCell

func NewRootCell(pageWidth, pageHeight float64, margins Margins) Cell

NewRootCell creates the main Cell.

func (Cell) Copy

func (c Cell) Copy() Cell

Copy deep copy the cell data.

func (Cell) GetDimensions

func (c Cell) GetDimensions() *Dimensions

GetDimensions returns the dimensions of the Cell (width and height).

type Config

type Config struct {
	ProviderType                   consts.ProviderType
	Dimensions                     *Dimensions
	Margins                        *Margins
	DefaultFont                    *props.Font
	CustomFonts                    []CustomFont
	GenerationMode                 consts.GenerationMode
	ChunkWorkers                   int
	Debug                          bool
	MaxGridSize                    int
	PageNumber                     *props.PageNumber
	Protection                     *Protection
	Compression                    bool
	Metadata                       *Metadata
	BackgroundImage                *Image
	FirstPageBackgroundImage       *Image
	FirstPageForegroundImage       *Image
	FirstPageForegroundImages      []*Image
	FirstPageFinalForegroundImages []*Image
	DisableAutoPageBreak           bool
	HTMLLimits                     HTMLLimits
	OutlineFromHeadings            bool
	Watermark                      *props.Watermark
	Annotations                    []PageAnnotation
	PageGeometries                 []PageGeometry
	AcroForm                       *AcroForm
	PdfA                           *PdfAConfig
	TaggedPDF                      bool
	Language                       string
	ViewerPreferences              *ViewerPreferences
	PageLabels                     []PageLabelRange
	Attachments                    []FileAttachment
	NamedDestinations              []NamedDestination
	FileID                         []byte
	Deterministic                  bool
}

Config is the configuration of a paper instance.

func (*Config) HasDocumentCatalog added in v0.2.2

func (c *Config) HasDocumentCatalog() bool

HasDocumentCatalog reports whether any document-catalog feature is configured. These features are written once per document.

func (*Config) RequiresSingleDocumentGeneration added in v0.2.2

func (c *Config) RequiresSingleDocumentGeneration() bool

RequiresSingleDocumentGeneration reports whether the document carries a feature that page-chunked generation cannot reproduce, so it must be built in a single pass.

Deterministic output is deliberately excluded: it only affects the dates and /ID written once when the document is serialized, which page splicing preserves because it serializes exactly one document. Chunk-and-merge strategies do not, so callers relying on those must check Deterministic too.

func (*Config) ToMap

func (c *Config) ToMap() map[string]any

ToMap converts Config to a map[string]any .

type CustomFont

type CustomFont interface {
	GetFamily() string
	GetStyle() fontstyle.Type
	GetFile() string
	GetBytes() []byte
}

CustomFont is the representation of a font that can be added to the pdf.

type DestinationFitType added in v0.2.2

type DestinationFitType string

DestinationFitType is the PDF destination fit operator for a named destination.

const (
	// DestinationFit fits the full page in the viewer.
	DestinationFit DestinationFitType = "Fit"
	// DestinationFitH fits the page width at the provided top coordinate.
	DestinationFitH DestinationFitType = "FitH"
	// DestinationXYZ opens the page at the provided left/top/zoom values.
	DestinationXYZ DestinationFitType = "XYZ"
)

type Dimensions

type Dimensions struct {
	Width  float64
	Height float64
}

Dimensions is the representation of a width and height.

func (*Dimensions) AppendMap

func (d *Dimensions) AppendMap(label string, m map[string]any) map[string]any

AppendMap appends the dimensions to a map.

type Field added in v0.2.2

type Field struct {
	Name      string
	Type      FieldType
	Value     string
	Default   string
	Flags     FieldFlags
	Rect      [4]float64
	PageIndex int

	FontSize    float64
	FontName    string
	TextColor   [3]float64
	BGColor     *[3]float64
	BorderColor *[3]float64
	BorderWidth float64

	Options     []string
	ExportValue string
	// contains filtered or unexported fields
}

Field represents a generated PDF AcroForm field.

func CloneField added in v0.2.2

func CloneField(field *Field) *Field

CloneField returns a deep copy of field.

func NewCheckbox added in v0.2.2

func NewCheckbox(name string, rect [4]float64, pageIndex int, checked bool) *Field

NewCheckbox creates a checkbox field.

func NewDropdown added in v0.2.2

func NewDropdown(name string, rect [4]float64, pageIndex int, options []string) *Field

NewDropdown creates a combo-box choice field.

func NewListBox added in v0.2.2

func NewListBox(name string, rect [4]float64, pageIndex int, options []string) *Field

NewListBox creates a list-box choice field.

func NewMultilineTextField added in v0.2.2

func NewMultilineTextField(name string, rect [4]float64, pageIndex int) *Field

NewMultilineTextField creates a multi-line text area field.

func NewPasswordField added in v0.2.2

func NewPasswordField(name string, rect [4]float64, pageIndex int) *Field

NewPasswordField creates a password text field.

func NewRadioGroup added in v0.2.2

func NewRadioGroup(name string, options []RadioOption) *Field

NewRadioGroup creates a radio button group.

func NewSignatureField added in v0.2.2

func NewSignatureField(name string, rect [4]float64, pageIndex int) *Field

NewSignatureField creates an unsigned signature field.

func NewTextField added in v0.2.2

func NewTextField(name string, rect [4]float64, pageIndex int) *Field

NewTextField creates a single-line text input field.

func (*Field) Children added in v0.2.2

func (f *Field) Children() []*Field

Children returns radio widget children for a radio group field.

func (*Field) SetBackgroundColor added in v0.2.2

func (f *Field) SetBackgroundColor(r, g, b float64) *Field

SetBackgroundColor sets the field widget background color as RGB values in [0, 1].

func (*Field) SetBorderColor added in v0.2.2

func (f *Field) SetBorderColor(r, g, b float64) *Field

SetBorderColor sets the field widget border color as RGB values in [0, 1].

func (*Field) SetReadOnly added in v0.2.2

func (f *Field) SetReadOnly() *Field

SetReadOnly marks the field read-only.

func (*Field) SetRequired added in v0.2.2

func (f *Field) SetRequired() *Field

SetRequired marks the field required.

func (*Field) SetValue added in v0.2.2

func (f *Field) SetValue(v string) *Field

SetValue sets the field's current value.

type FieldFlags added in v0.2.2

type FieldFlags uint32

FieldFlags are AcroForm field flags from ISO 32000 section 12.7.3.

const (
	FlagReadOnly FieldFlags = 1 << 0
	FlagRequired FieldFlags = 1 << 1
	FlagNoExport FieldFlags = 1 << 2

	FlagMultiline       FieldFlags = 1 << 12
	FlagPassword        FieldFlags = 1 << 13
	FlagFileSelect      FieldFlags = 1 << 20
	FlagDoNotSpellCheck FieldFlags = 1 << 22
	FlagDoNotScroll     FieldFlags = 1 << 23
	FlagComb            FieldFlags = 1 << 24
	FlagRichText        FieldFlags = 1 << 25

	FlagCombo       FieldFlags = 1 << 17
	FlagEdit        FieldFlags = 1 << 18
	FlagSort        FieldFlags = 1 << 19
	FlagMultiSelect FieldFlags = 1 << 21

	FlagNoToggleToOff  FieldFlags = 1 << 14
	FlagRadioFlag      FieldFlags = 1 << 15
	FlagPushButtonFlag FieldFlags = 1 << 16
)

Field flags, grouped by the field kind they apply to: any field, text fields, choice fields, then button fields. Combine them with bitwise OR.

type FieldType added in v0.2.2

type FieldType int

FieldType identifies the kind of interactive AcroForm field.

const (
	FieldText FieldType = iota
	FieldCheckbox
	FieldRadio
	FieldDropdown
	FieldListBox
	FieldPushButton
	FieldSignature
)

The kinds of interactive form field.

type FileAttachment added in v0.2.2

type FileAttachment struct {
	// FileName is the name shown by PDF viewers and stored in the file
	// specification dictionary.
	FileName string
	// MIMEType is written as the embedded file stream subtype. It defaults to
	// application/octet-stream when empty.
	MIMEType string
	// Description is an optional human-readable file description.
	Description string
	// AFRelationship is the PDF associated-file relationship name. It defaults
	// to Unspecified when empty.
	AFRelationship string
	// Data is the raw file content to embed.
	Data []byte
	// CreationDate is written to the embedded file parameters. If zero, the
	// document creation date or generation time is used.
	CreationDate time.Time
}

FileAttachment describes a file embedded in the generated PDF.

func CloneAttachments added in v0.2.2

func CloneAttachments(attachments []FileAttachment) []FileAttachment

CloneAttachments returns an independent copy of attachments, including the embedded data bytes.

type HTMLLimits

type HTMLLimits = htmllimits.Limits

HTMLLimits caps resource use while translating untrusted HTML.

type Image

type Image struct {
	Bytes      []byte
	Extension  extension.Type
	Dimensions *Dimensions
	// PageCell optionally places the image in physical page coordinates,
	// measured from the page's top-left corner.
	PageCell *Cell
	// ObjectFit controls how a positioned page image is sized inside PageCell.
	ObjectFit string
}

Image is the representation of an image that can be added to the pdf.

func (*Image) AppendMap

func (i *Image) AppendMap(m map[string]any) map[string]any

AppendMap adds the Image fields to the map.

type LabelStyle added in v0.2.2

type LabelStyle string

LabelStyle is how a page label numbers its pages.

const (
	LabelDecimal    LabelStyle = "D"
	LabelRomanUpper LabelStyle = "R"
	LabelRomanLower LabelStyle = "r"
	LabelAlphaUpper LabelStyle = "A"
	LabelAlphaLower LabelStyle = "a"
	LabelNone       LabelStyle = ""
)

The page numbering styles: decimal, upper/lower roman, upper/lower letters, or no number at all.

type Margins

type Margins struct {
	Left   float64
	Right  float64
	Top    float64
	Bottom float64
}

Margins is the representation of a margin.

func (*Margins) AppendMap

func (m *Margins) AppendMap(mp map[string]any) map[string]any

AppendMap appends the margins to a map.

type MarkupType added in v0.2.2

type MarkupType int

MarkupType identifies the kind of text markup annotation.

const (
	MarkupHighlight MarkupType = iota
	MarkupUnderline
	MarkupSquiggly
	MarkupStrikeOut
)

The text markup styles a markup annotation can use.

type Metadata

type Metadata struct {
	Author       *Utf8Text
	Creator      *Utf8Text
	Subject      *Utf8Text
	Title        *Utf8Text
	CreationDate *time.Time
	KeywordsStr  *Utf8Text
}

Metadata is the representation of a PDF metadata.

func (*Metadata) AppendMap

func (m *Metadata) AppendMap(mp map[string]any) map[string]any

AppendMap appends the metadata to a map.

type NamedDest added in v0.2.2

type NamedDest = NamedDestination

NamedDest is a compatibility alias for Folio-style naming.

type NamedDestination added in v0.2.2

type NamedDestination struct {
	Name      string
	PageIndex int
	FitType   DestinationFitType
	Top       float64
	Left      float64
	Zoom      float64
}

NamedDestination defines a named location in the generated PDF.

type PageAnnotation added in v0.2.2

type PageAnnotation struct {
	PageIndex  int
	Type       AnnotationType
	Rect       [4]float64
	URI        string
	DestName   string
	DestPage   *int
	Contents   string
	Icon       string
	Open       bool
	Color      *[3]float64
	QuadPoints [][8]float64
}

PageAnnotation describes an annotation emitted on a generated PDF page.

func CloneAnnotations added in v0.2.2

func CloneAnnotations(annotations []PageAnnotation) []PageAnnotation

CloneAnnotations returns an independent copy of annotations.

type PageGeometry added in v0.2.2

type PageGeometry struct {
	PageIndex int
	Rotate    int
	CropBox   *[4]float64
	BleedBox  *[4]float64
	TrimBox   *[4]float64
	ArtBox    *[4]float64
}

PageGeometry configures generated PDF page dictionary geometry entries.

func ClonePageGeometries added in v0.2.2

func ClonePageGeometries(geometries []PageGeometry) []PageGeometry

ClonePageGeometries returns an independent copy of page geometries.

type PageLabelRange added in v0.2.2

type PageLabelRange struct {
	PageIndex int
	Style     LabelStyle
	Prefix    string
	Start     int
}

PageLabelRange labels the run of pages starting at PageIndex. Start is the number the run counts from, and Prefix is put in front of each number.

type PageLayout added in v0.2.2

type PageLayout string

PageLayout is how a reader should arrange pages on screen.

const (
	LayoutSinglePage     PageLayout = "SinglePage"
	LayoutOneColumn      PageLayout = "OneColumn"
	LayoutTwoColumnLeft  PageLayout = "TwoColumnLeft"
	LayoutTwoColumnRight PageLayout = "TwoColumnRight"
	LayoutTwoPageLeft    PageLayout = "TwoPageLeft"
	LayoutTwoPageRight   PageLayout = "TwoPageRight"
)

The page arrangements a reader can be asked to use.

type PageMode added in v0.2.2

type PageMode string

PageMode is what a reader should show alongside the page when the document opens, such as the bookmark or thumbnail panel.

const (
	ModeUseNone        PageMode = "UseNone"
	ModeUseOutlines    PageMode = "UseOutlines"
	ModeUseThumbs      PageMode = "UseThumbs"
	ModeFullScreen     PageMode = "FullScreen"
	ModeUseOC          PageMode = "UseOC"
	ModeUseAttachments PageMode = "UseAttachments"
)

The side panels (or full-screen mode) a reader can open the document with.

type PdfAConfig added in v0.2.2

type PdfAConfig struct {
	Level           PdfALevel
	ICCProfile      []byte
	OutputCondition string
	XMPSchemas      []XMPSchema
	XMPProperties   []XMPPropertyBlock
}

PdfAConfig configures generated PDF/A identification metadata.

func ClonePdfAConfig added in v0.2.2

func ClonePdfAConfig(config *PdfAConfig) *PdfAConfig

ClonePdfAConfig returns a deep copy of config.

type PdfALevel added in v0.2.2

type PdfALevel int

PdfALevel identifies the requested PDF/A part and conformance profile.

const (
	PdfA2B PdfALevel = iota
	PdfA2U
	PdfA2A
	PdfA3B
	PdfA1B
	PdfA1A
	PdfA3A
	PdfA4
	PdfA4F
	PdfA4E
)

The supported PDF/A parts and conformance profiles.

type Protection

type Protection struct {
	Type          protection.Type
	UserPassword  string
	OwnerPassword string
	Algorithm     protection.Encryption
}

Protection is the representation of a pdf protection.

func (*Protection) AppendMap

func (p *Protection) AppendMap(m map[string]any) map[string]any

AppendMap adds the Protection fields to the map.

type RadioOption added in v0.2.2

type RadioOption struct {
	Value     string
	Rect      [4]float64
	PageIndex int
}

RadioOption defines one button in a radio group.

type Utf8Text

type Utf8Text struct {
	Text string
	UTF8 bool
}

Utf8Text is the representation of a text with a flag to indicate if it's UTF8.

func (*Utf8Text) ToString

func (u *Utf8Text) ToString() string

ToString returns a string representation of the text.

type ViewerPreferences added in v0.2.2

type ViewerPreferences struct {
	PageLayout      PageLayout
	PageMode        PageMode
	HideToolbar     bool
	HideMenubar     bool
	HideWindowUI    bool
	FitWindow       bool
	CenterWindow    bool
	DisplayDocTitle bool
	OpenPage        int
	OpenZoom        string
}

ViewerPreferences asks the reader how to present the document when it opens. Every field is optional; a zero field leaves that choice to the reader.

func (*ViewerPreferences) AppendMap added in v0.2.2

func (v *ViewerPreferences) AppendMap(m map[string]any) map[string]any

AppendMap adds the preferences that are actually set into m and returns it. It is used to report the document's configuration.

type XMPProperty added in v0.2.2

type XMPProperty struct {
	Name  string
	Value string
}

XMPProperty is a single custom XMP property value.

type XMPPropertyBlock added in v0.2.2

type XMPPropertyBlock struct {
	Namespace  string
	Prefix     string
	Properties []XMPProperty
}

XMPPropertyBlock carries actual XMP property values for a namespace.

type XMPSchema added in v0.2.2

type XMPSchema struct {
	Schema       string
	NamespaceURI string
	Prefix       string
	Properties   []XMPSchemaProperty
}

XMPSchema describes one PDF/A extension schema declaration.

type XMPSchemaProperty added in v0.2.2

type XMPSchemaProperty struct {
	Name        string
	ValueType   string
	Category    string
	Description string
}

XMPSchemaProperty declares one property within an XMP extension schema.

Jump to

Keyboard shortcuts

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