pdf

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: BSD-3-Clause Imports: 31 Imported by: 0

README

PDF rendering

This package adapts the PDF rendering code from https://github.com/tdewolff/canvas (Copyright (c) 2015 Taco de Wolff, under an MIT License.) to the Cogent Core rendering framework. It is used for rendering PDFs of content documentation, producing publication-ready output from markdown input. It is also used by the Cogent Canvas SVG drawing app to render PDFs of SVGs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RestorePreviousFonts

func RestorePreviousFonts(s rich.SettingsData)

RestorePreviousFonts sets the rich.Settings default fonts to those returned from UseStandardFonts

func UseStandardFonts

func UseStandardFonts() rich.SettingsData

UseStandardFonts sets the rich.Settings default fonts to the corresponding PDF defaults, so that text layout works correctly for the PDF rendering. The current settings are returned, and should be passed to RestorePreviousFonts when done.

Types

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 float32, un *units.Context) *PDF

New returns a portable document format (PDF) renderer. The size is in points.

func (*PDF) AddAnchor

func (r *PDF) AddAnchor(name string, pos math32.Vector2)

AddAnchor adds a uniquely-named link anchor location, which can then be a target for links.

func (*PDF) AddLayer

func (r *PDF) AddLayer(name string, visible bool) (layerID int)

AddLayer defines a layer that can be shown or hidden when the document is displayed. name specifies the layer name that the document reader will display in the layer list. visible specifies whether the layer will be initially visible. The return value is an integer ID that is used in a call to BeginLayer().

func (r *PDF) AddLink(uri string, rect math32.Box2)

AddLink adds a link to the PDF document.

func (*PDF) BeginLayer

func (r *PDF) BeginLayer(id int)

BeginLayer is called to begin adding content to the specified layer. All content added to the page between a call to BeginLayer and a call to EndLayer is added to the layer specified by id. See AddLayer for more details.

func (*PDF) Close

func (r *PDF) Close() error

Close finished and closes the PDF.

func (*PDF) Cumulative

func (r *PDF) Cumulative() math32.Matrix2

Cumulative returns the current cumulative transform.

func (*PDF) EndLayer

func (r *PDF) EndLayer()

EndLayer is called to stop adding content to the currently active layer. See BeginLayer for more details.

func (*PDF) FillBox

func (r *PDF) FillBox(m math32.Matrix2, bb math32.Box2, clr image.Image)

FillBox fills a box in the given color.

func (*PDF) Image

func (r *PDF) Image(img image.Image, m math32.Matrix2)

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

func (*PDF) NewPage

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

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

func (*PDF) Path

func (r *PDF) Path(path ppath.Path, style *styles.Paint, tr math32.Matrix2)

Path renders a path to the canvas using a style and an individual matrix (needed for fill)

func (*PDF) PopStack

func (r *PDF) PopStack()

PopStack adds a graphics stack pop which must be paired with a corresponding Push.

func (*PDF) PushStack

func (r *PDF) PushStack()

PushStack adds a graphics stack push, which must be paired with a corresponding Pop.

func (*PDF) PushTransform

func (r *PDF) PushTransform(m math32.Matrix2)

PushTransform adds a graphics stack push (q) and then cm to set the current matrix transform (CMT).

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) SetTransform

func (r *PDF) SetTransform(m math32.Matrix2)

SetTransform adds a cm to set the current matrix transform (CMT).

func (*PDF) Size

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

Size returns the size of the canvas in millimeters.

func (*PDF) Text

func (r *PDF) Text(style *styles.Paint, m math32.Matrix2, pos math32.Vector2, lns *shaped.Lines)

Text renders text to the canvas using a transformation matrix, (the translation component specifies the starting offset)

Jump to

Keyboard shortcuts

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