pdf

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package pdf renders a chart to PDF using nothing but the standard library.

It is the second built-in emitter, and it exists for the same reason as backend/svg: PDF is a text format with a simple imaging model, and writing it directly costs a few hundred lines and no dependency at all. A report generator that wants a vector chart in a document links the same stdlib-only core it would have linked for SVG.

p := refract.New(refract.Title("Signal"))
p.Add(geom.Line(src, geom.X("t"), geom.Y("y")))
err := p.Render(pdf.File("signal.pdf"))

Coordinates

PDF puts the origin at the bottom left with Y running up; refract's IR puts it at the top left with Y running down. The page's content stream opens with a flip, so every coordinate refract emits is written unchanged and the two backends' geometry agrees exactly. Text is placed with its own matrix, which undoes the flip for the glyphs alone so they read the right way up.

Text

The output uses the base-14 Helvetica, which every PDF reader has and no document has to embed. That is also the metric set internal/fontmetrics carries, so this backend measures with exactly the font it draws with — margins, tick spacing and collision decisions are not approximations here.

Text is encoded as WinAnsi, which covers Latin-1 plus the usual typographic punctuation. A rune outside it is written as "?" rather than silently dropped, because a missing label is harder to notice than a wrong one.

Not here

One page per document, no embedded fonts, no tagging or accessibility structure, no transparency groups. Alpha is expressed as a graphics-state constant, which is what a faded area fill needs and is not the same thing as a full transparency model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func File

func File(path string, opts ...Option) ir.Target

File returns a Target that writes a PDF document to the named file. The file is created on Open and closed on Close.

func Writer

func Writer(w io.Writer, opts ...Option) ir.Target

Writer returns a Target that writes a PDF document to w.

Types

type Option

type Option func(*options)

Option configures a PDF target.

func Author

func Author(s string) Option

Author sets the document author.

func Subject

func Subject(s string) Option

Subject sets the document subject.

func Title

func Title(s string) Option

Title sets the document title shown in a reader's properties panel. It is independent of the chart title.

func Uncompressed

func Uncompressed() Option

Uncompressed writes the content stream as plain text rather than deflating it. The file is several times larger and can be read in a text editor, which is what it is for: reading a diff of what the backend emitted.

Jump to

Keyboard shortcuts

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