Documentation
¶
Overview ¶
Package pdf writes simple PDF 1.4 documents in pure Go: flowing text with word wrap, headings, rules, tables that break across pages, page numbers, and document metadata. It is meant for invoices, receipts and certificates of analysis, not for typesetting. Text uses the built-in Helvetica and Helvetica-Bold fonts with WinAnsi encoding, so Western European characters work and others print as "?". It depends only on the standard library.
Index ¶
- Variables
- type Align
- type Color
- type Column
- type Document
- func (d *Document) Bytes() ([]byte, error)
- func (d *Document) Heading(level int, s string)
- func (d *Document) PageBreak()
- func (d *Document) Pages() int
- func (d *Document) Rule()
- func (d *Document) Space(pts float64)
- func (d *Document) Table(t Table) error
- func (d *Document) Text(s string, style ...Style)
- func (d *Document) WriteTo(w io.Writer) (int64, error)
- type Metadata
- type Option
- type Size
- type Style
- type Table
Constants ¶
This section is empty.
Variables ¶
var ( A4 = Size{595.28, 841.89} Letter = Size{612, 792} )
Page sizes in points (1/72 inch).
var ErrRowTooTall = errors.New("pdf: table row is taller than a page")
ErrRowTooTall is returned for a table row that cannot fit on one page.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct{ R, G, B float64 }
Color is an RGB color with channels from 0 to 1. The zero value is black.
type Column ¶
type Column struct {
Header string
// Width is the column's share of the table width; zero counts as 1.
Width float64
Align Align
}
Column describes one table column.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is a PDF under construction. Content flows from the top of the first page and continues on new pages as needed. A Document is not safe for concurrent use.
func (*Document) Bytes ¶
Bytes returns the finished PDF. It can be called more than once; the document is not changed.
func (*Document) Heading ¶
Heading adds a bold heading. Level 1 is 20 pt, 2 is 15 pt, 3 and above 12 pt. A heading is kept with the line that follows it when it fits.
func (*Document) Rule ¶
func (d *Document) Rule()
Rule draws a thin horizontal line across the text width.
func (*Document) Table ¶
Table draws t. A row never splits across pages; the header repeats on each new page. A row that cannot fit on a page of its own returns ErrRowTooTall.
type Metadata ¶
type Metadata struct {
Title string
Author string
Subject string
Keywords string
Creator string
// Created defaults to the time of Bytes.
Created time.Time
}
Metadata is the document information dictionary.
type Option ¶
type Option func(*Document)
Option configures New.
func PageNumbers ¶
func PageNumbers() Option
PageNumbers prints "Page i of n" at the bottom of every page.