pdf

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 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 renders structured text lines into a minimal, valid PDF 1.4 document using only the standard library. It uses the standard 14 fonts (Helvetica, Helvetica-Bold, Courier) with WinAnsiEncoding, performs simple word wrapping and pagination, and emits an uncompressed cross-reference table so that any conforming reader accepts the output.

It is intentionally small: there is no layout engine, no images and no compression. The goal is to give a browser engine a Page.pdf-like capability from an already extracted text outline of a page.

Index

Constants

View Source
const (
	DefaultPageWidthPt  = 595.28
	DefaultPageHeightPt = 841.89
	DefaultMarginPt     = 48
	DefaultBaseFontPt   = 10.5
)

Default geometry (A4 portrait).

Variables

This section is empty.

Functions

func Render

func Render(lines []Line, o Options) ([]byte, error)

Render lays out lines and returns the bytes of a PDF 1.4 document.

Types

type Line

type Line struct {
	Text   string
	Kind   string
	Indent int
	Href   string
}

Line is one logical block of text to render.

Kind selects the style. Recognised kinds are "h1", "h2", "h3", "p", "li", "link", "input", "button", "pre", "hr" and "" (treated like "p"). Indent is a nesting depth that shifts the block to the right. Href is used for "link" lines; an absolute http(s) URL produces a clickable /Link annotation.

type Options

type Options struct {
	Title        string
	URL          string
	PageWidthPt  float64
	PageHeightPt float64
	MarginPt     float64
	BaseFontPt   float64
	Landscape    bool
	HeaderFooter bool
}

Options controls page geometry and decoration.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the recommended options: A4, 48 pt margins, 10.5 pt Helvetica, header and footer enabled. Render fills in zero numeric fields with these defaults; HeaderFooter is a plain bool, so a zero Options renders without the running header and footer.

Jump to

Keyboard shortcuts

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