pdf

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pdf writes PDF documents in pure Go: pages of RGB raster images, Flate-compressed and streamed to an io.Writer as they are added. Output is deterministic (no timestamps or document IDs), so the same pages always produce the same bytes.

w := pdf.NewWriter(out, "Report")
a4 := pdf.Size{W: pdf.Millimetres(210), H: pdf.Millimetres(297)}
if err := w.AddPage(a4, page); err != nil { ... }
if err := w.Close(); err != nil { ... }

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPages = errors.New("pdf: a document needs at least one page")

ErrNoPages reports a Close before any AddPage; a PDF has at least one page.

Functions

This section is empty.

Types

type Points

type Points float64

Points is a length in PostScript points, 1/72 inch.

func Millimetres

func Millimetres(mm float64) Points

Millimetres converts mm to points.

type Size

type Size struct{ W, H Points }

Size is a page's width and height.

type Writer

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

Writer streams a PDF document. Pages are written as they are added; Close writes the page tree and cross-reference table. A write error sticks: every later call returns it.

func NewWriter

func NewWriter(out io.Writer, title string) *Writer

NewWriter starts a document on out titled title (empty for none).

func (*Writer) AddPage

func (w *Writer) AddPage(size Size, img image.Image) error

AddPage appends a page of size, covered by img stretched to fill it. Transparent pixels show white, as on paper.

func (*Writer) Close

func (w *Writer) Close() error

Close finishes the document. It does not close the underlying writer.

Jump to

Keyboard shortcuts

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