core

package
v0.0.0-...-83b8ea0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package core is part of the go-fastreport library, a pure Go port of FastReport .NET.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

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

Array is a PDF array object that holds an ordered list of PDF Objects.

PDF representation:

[ val1 val2 val3 ]

func NewArray

func NewArray(items ...Object) *Array

NewArray returns an Array pre-populated with the supplied items.

func (*Array) Add

func (a *Array) Add(item Object) *Array

Add appends item to the array and returns the receiver for chaining.

func (*Array) Len

func (a *Array) Len() int

Len returns the number of items in the array.

func (*Array) Type

func (a *Array) Type() ObjectType

Type implements Object.

func (*Array) WriteTo

func (a *Array) WriteTo(w io.Writer) (int64, error)

WriteTo writes the PDF array representation to w.

type Boolean

type Boolean struct {
	// Value is the Go boolean value.
	Value bool
}

Boolean is a PDF boolean object.

PDF representation: true or false

func NewBoolean

func NewBoolean(v bool) *Boolean

NewBoolean returns a Boolean with the given value.

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

Type implements Object.

func (*Boolean) WriteTo

func (b *Boolean) WriteTo(w io.Writer) (int64, error)

WriteTo writes "true" or "false" to w.

type Dictionary

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

Dictionary is a PDF dictionary object. Keys are PDF Name values (without the leading slash) and values are any PDF Object. Entries are iterated in insertion order, which ensures deterministic output.

PDF representation:

<< /Key1 Value1 /Key2 Value2 >>

func NewDictionary

func NewDictionary() *Dictionary

NewDictionary returns an empty, ready-to-use Dictionary.

func (*Dictionary) Add

func (d *Dictionary) Add(key string, value Object) *Dictionary

Add inserts or replaces the entry with the given key. The key must be supplied without a leading slash (e.g. "Type", not "/Type"). Add returns the receiver so calls can be chained.

func (*Dictionary) Get

func (d *Dictionary) Get(key string) Object

Get returns the value for key, or nil if the key is not present.

func (*Dictionary) Len

func (d *Dictionary) Len() int

Len returns the number of entries in the dictionary.

func (*Dictionary) Type

func (d *Dictionary) Type() ObjectType

Type implements Object.

func (*Dictionary) WriteTo

func (d *Dictionary) WriteTo(w io.Writer) (int64, error)

WriteTo writes the PDF dictionary representation to w.

type IndirectObject

type IndirectObject struct {
	// Number is the 1-based object number assigned by the PDF writer.
	Number int
	// Generation is almost always 0 for newly created objects.
	Generation int
	// Value is the PDF object contained in this indirect wrapper.
	Value Object
}

IndirectObject wraps an Object with a PDF object number and generation number, producing the "N G obj … endobj" block used in PDF cross-reference tables.

Example output for Number=3, Generation=0:

3 0 obj
…value…
endobj

func (*IndirectObject) Reference

func (o *IndirectObject) Reference() string

Reference writes the indirect reference token "N G R" for this object. This is a convenience helper for callers that need to refer to the object from elsewhere in the PDF without embedding the full indirect-object block.

func (*IndirectObject) Type

func (o *IndirectObject) Type() ObjectType

Type implements Object.

func (*IndirectObject) WriteTo

func (o *IndirectObject) WriteTo(w io.Writer) (int64, error)

WriteTo writes the complete indirect-object block to w. It satisfies io.WriterTo so that IndirectObject can be used wherever an Object is expected.

type Name

type Name struct {
	// Value is the name without the leading slash.
	Value string
}

Name is a PDF name object. In PDF syntax a name is prefixed with a forward slash and non-alphanumeric characters are encoded as "#XX" where XX is the uppercase hexadecimal byte value.

PDF representation: /FlateDecode or /my#20name

func NewName

func NewName(v string) *Name

NewName returns a Name for the given string (without the leading slash).

func (*Name) Type

func (n *Name) Type() ObjectType

Type implements Object.

func (*Name) WriteTo

func (n *Name) WriteTo(w io.Writer) (int64, error)

WriteTo writes the PDF name representation to w. An empty name produces no output (matching the original C# behaviour).

type Null

type Null struct{}

Null is the PDF null object.

PDF representation: null

func (*Null) Type

func (n *Null) Type() ObjectType

Type implements Object.

func (*Null) WriteTo

func (n *Null) WriteTo(w io.Writer) (int64, error)

WriteTo writes the literal token "null" to w.

type Numeric

type Numeric struct {
	// Value holds the numeric value for both integer and real cases.
	Value float64
	// IsInt selects integer output (no decimal point) when true.
	IsInt bool
}

Numeric is a PDF numeric object. It can represent either an integer or a real (floating-point) number.

PDF representation:

42        (integer)
3.1400    (real, 4 decimal places)

func NewFloat

func NewFloat(v float64) *Numeric

NewFloat returns a Numeric that renders as a PDF real number with 4 decimal places of precision.

func NewInt

func NewInt(v int) *Numeric

NewInt returns a Numeric that renders as a PDF integer.

func (*Numeric) Type

func (n *Numeric) Type() ObjectType

Type implements Object.

func (*Numeric) WriteTo

func (n *Numeric) WriteTo(w io.Writer) (int64, error)

WriteTo writes the PDF numeric representation to w.

type Object

type Object interface {
	io.WriterTo

	// Type returns a string tag for the concrete type, useful for debugging.
	Type() ObjectType
}

Object is the base interface implemented by every PDF primitive. WriteTo writes the PDF textual representation of the object to w and returns the number of bytes written together with any write error.

type ObjectType

type ObjectType string

ObjectType is a string tag identifying the kind of PDF object.

const (
	TypeIndirect   ObjectType = "indirect"
	TypeDictionary ObjectType = "dictionary"
	TypeArray      ObjectType = "array"
	TypeStream     ObjectType = "stream"
	TypeString     ObjectType = "string"
	TypeName       ObjectType = "name"
	TypeNumeric    ObjectType = "numeric"
	TypeBoolean    ObjectType = "boolean"
	TypeNull       ObjectType = "null"
)

PDF object type constants used for debugging and type assertions.

const TypeRef ObjectType = "ref"

TypeRef is the ObjectType tag for an indirect-reference object.

type Ref

type Ref struct {
	// Value is the complete reference string, e.g. "5 0 R".
	Value string
}

Ref is a PDF indirect-reference token, e.g. "5 0 R". Use NewRef(obj) to create one from an IndirectObject.

func NewRef

func NewRef(obj *IndirectObject) *Ref

NewRef creates a Ref pointing at the given indirect object.

func (*Ref) Type

func (r *Ref) Type() ObjectType

Type implements Object.

func (*Ref) WriteTo

func (r *Ref) WriteTo(w io.Writer) (int64, error)

WriteTo writes the raw reference string (e.g. "5 0 R") to w.

type Stream

type Stream struct {
	// Dict holds auxiliary dictionary entries (e.g. /Type, /Subtype).
	// /Length and, when Compressed is true, /Filter are managed automatically.
	Dict *Dictionary
	// Data is the raw (uncompressed) stream content.
	Data []byte
	// Compressed controls whether the data is zlib-compressed on output.
	Compressed bool
}

Stream is a PDF stream object: a Dictionary followed by a block of binary data delimited by "stream" and "endstream" keywords.

When Compressed is true the Data payload is deflated with zlib before writing and the /Filter /FlateDecode and /Length entries are set automatically. When Compressed is false the raw Data bytes are written and only /Length is set.

PDF representation (compressed):

<< /Filter /FlateDecode /Length N >>
stream
…compressed bytes…
endstream

func NewStream

func NewStream() *Stream

NewStream returns a Stream with an empty Dictionary and Compressed set to true, matching the default behaviour of the original C# implementation.

func (*Stream) Type

func (s *Stream) Type() ObjectType

Type implements Object.

func (*Stream) WriteTo

func (s *Stream) WriteTo(w io.Writer) (int64, error)

WriteTo writes the complete stream object (dictionary + data) to w.

type String

type String struct {
	// Value is the Go string to be encoded.
	Value string
	// IsHex selects the hex representation when true; parenthesised otherwise.
	IsHex bool
}

String is a PDF string object. It can be rendered either as a parenthesised literal string or as an angle-bracket hex string.

Literal representation: (Hello\nWorld) Hex representation: <FEFF00480065006C006C006F>

In both cases the string value is first converted to a big-endian UTF-16 sequence with a BOM (0xFEFF), matching the behaviour of the original C# implementation.

func NewHexString

func NewHexString(v string) *String

NewHexString returns a hex PDF string.

func NewString

func NewString(v string) *String

NewString returns a literal (parenthesised) PDF string.

func (*String) Type

func (s *String) Type() ObjectType

Type implements Object.

func (*String) WriteTo

func (s *String) WriteTo(w io.Writer) (int64, error)

WriteTo writes the PDF string representation to w.

Jump to

Keyboard shortcuts

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