pdf

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pdf implements a minimal PDF 1.7 writer, just functional enough to create a PDF file containing a QR code encoded as rectangles.

It follows the standard “PDF 32000-1:2008 PDF 1.7”: https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog struct {
	Common
	Pages Object // Pages
}

Catalog represents a PDF catalog object.

func (*Catalog) Encode

func (r *Catalog) Encode(w io.Writer, ids map[string]ObjectID) error

Encode implements Object.

func (*Catalog) Objects

func (r *Catalog) Objects() []Object

Objects implements Object.

type Common

type Common struct {
	ObjectName string
	ID         ObjectID
	Stream     []byte
}

Common represents a PDF object.

func (*Common) Encode

func (c *Common) Encode(w io.Writer, ids map[string]ObjectID) error

Encode implements Object.

func (*Common) Name

func (c *Common) Name() string

Name implements Object.

func (*Common) Objects

func (c *Common) Objects() []Object

Objects implements Object.

func (*Common) SetID

func (c *Common) SetID(id ObjectID)

SetID implements Object.

func (*Common) String

func (c *Common) String() string

String implements fmt.Stringer.

type DocumentInfo

type DocumentInfo struct {
	Common

	CreationDate time.Time
	Producer     string
	Title        string
}

DocumentInfo represents a PDF document information object.

func (*DocumentInfo) Encode

func (d *DocumentInfo) Encode(w io.Writer, ids map[string]ObjectID) error

Encode implements Object.

func (*DocumentInfo) Objects

func (d *DocumentInfo) Objects() []Object

Objects implements Object.

type Encoder

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

Encoder is a PDF writer.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a ready-to-use Encoder writing to w.

func (*Encoder) Encode

func (e *Encoder) Encode(r *Catalog, info *DocumentInfo) error

Encode writes the PDF file represented by the specified catalog.

type Object

type Object interface {
	// Objects returns all Objects which should be encoded into the
	// PDF file.
	Objects() []Object

	// Encode encodes the object into the PDF file w.
	Encode(w io.Writer, ids map[string]ObjectID) error

	// SetID updates the object id.
	SetID(id ObjectID)

	// Name returns the human-readable object name.
	Name() string

	fmt.Stringer
}

Object is implemented by all PDF objects.

type ObjectID

type ObjectID int

ObjectID is a PDF object id.

func (ObjectID) String

func (o ObjectID) String() string

String implements fmt.Stringer.

type Page

type Page struct {
	Common

	Resources []Object // Image
	Contents  []Object // Common (streams)

	// Parent contains the human-readable name of the parent object,
	// which will be translated into an object ID when encoding.
	Parent string
}

Page represents a PDF page object with size DIN A4

func (*Page) Encode

func (p *Page) Encode(w io.Writer, ids map[string]ObjectID) error

Encode implements Object.

func (*Page) Objects

func (p *Page) Objects() []Object

Objects implements Object.

type Pages

type Pages struct {
	Common
	Kids []Object // Page
}

Pages represents a PDF pages object

func (*Pages) Encode

func (p *Pages) Encode(w io.Writer, ids map[string]ObjectID) error

Encode implements Object.

func (*Pages) Objects

func (p *Pages) Objects() []Object

Objects implements Object.

Jump to

Keyboard shortcuts

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