pdf

package
v0.0.0-...-c97636a Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 20 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Compress:      true,
	SubsetFonts:   true,
	ImageEncoding: canvas.Lossless,
}

Functions

This section is empty.

Types

type Options

type Options struct {
	Compress    bool
	SubsetFonts bool
	canvas.ImageEncoding
}

type PDF

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

PDF is a portable document format renderer.

func New

func New(w io.Writer, width, height float64, opts *Options) *PDF

New returns a portable document format (PDF) renderer.

func (*PDF) AddAnchor

func (r *PDF) AddAnchor(name string, rect canvas.Rect)

AddAnchor adds an anchor that can be referenced by a link (see AddLink). The rectangle is the area to be referenced. If the width and height are zero and the X and Y positions are zero, it will fit the entire page. If either width/height and X/Y are zero then it will fit the page's height/width and scroll to the X/Y position. Otherwise, if the width and height are zero and X and Y are not zero, it will scroll to the position but not change it's zoom.

func (r *PDF) AddLink(uri string, rect canvas.Rect)

AddLink adds a link at the given rectangle. If the URI starts with # this will link to an anchor (set with AddAnchor).

func (*PDF) AddOutline

func (r *PDF) AddOutline(name string, level int, y float64)

AddOutline adds an outline element at the given y position. The top-level element must have level zero. If any level is missing, then higher level elements are ignored.

func (*PDF) Close

func (r *PDF) Close() error

Close finished and closes the PDF.

func (*PDF) NewPage

func (r *PDF) NewPage(width, height float64)

NewPage starts adds a new page where further rendering will be written to.

func (*PDF) RenderImage

func (r *PDF) RenderImage(img image.Image, m canvas.Matrix)

RenderImage renders an image to the canvas using a transformation matrix.

func (*PDF) RenderPath

func (r *PDF) RenderPath(path *canvas.Path, style canvas.Style, m canvas.Matrix)

RenderPath renders a path to the canvas using a style and a transformation matrix.

func (*PDF) RenderText

func (r *PDF) RenderText(text *canvas.Text, m canvas.Matrix)

RenderText renders a text object to the canvas using a transformation matrix.

func (*PDF) SetImageEncoding

func (r *PDF) SetImageEncoding(enc canvas.ImageEncoding)

SetImageEncoding sets the image encoding to Loss or Lossless.

func (*PDF) SetInfo

func (r *PDF) SetInfo(title, subject, keywords, author, creator string)

SetInfo sets the document's title, subject, keywords, author and creator.

func (*PDF) SetLang

func (r *PDF) SetLang(lang string)

SetLang sets the document's language. It must adhere the RFC 3066 specification on Language-Tag, eg. es-CL.

func (*PDF) Size

func (r *PDF) Size() (float64, float64)

Size returns the size of the canvas in millimeters.