pdf

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pdf writes simple text documents, using only the standard library.

Mirth's Document Writer renders HTML to PDF, which needs a layout engine. That is not what this is. This produces a plain, paginated text document with a monospaced font, and it exists because the actual requirement at almost every site that uses that connector is "put this report on a share so somebody can print it" - a discharge summary, a result report, a daily reconciliation. Those are text.

Refusing the feature entirely would leave a Tier 2 migration blocker in place. Pulling in an HTML rendering engine would cost more than the whole rest of the binary and bring a CVE stream with it, which would undo the argument the bill of materials makes. So: text, honestly described as text, and a site that genuinely needs typeset output is better served by a file destination and a tool built for it.

Why write a PDF at all rather than a text file

Because the receiving end is usually a person with a printer and a Windows share, and a .txt file printed from a share loses its pagination, its margins and often its line endings. A PDF prints the same everywhere, which is the entire reason anybody asked for one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(text string, opts Options) ([]byte, error)

Render writes text as a paginated PDF.

Types

type Document

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

Document accumulates content and writes it as a PDF.

func New

func New(title string) *Document

New starts a document with one page.

func (*Document) Bytes

func (d *Document) Bytes() []byte

Bytes writes the finished PDF.

Offsets are recorded as each object is written. Calculating them afterwards means computing the length of everything already written, and one arithmetic slip produces a file that every reader rejects with no clue as to which object is wrong.

func (*Document) Heading

func (d *Document) Heading(text string, level int)

Heading writes a section heading with the space above it that makes it read as a break.

func (*Document) KeyValue

func (d *Document) KeyValue(label, value string, size float64)

KeyValue writes a label and value on one line, for header facts.

func (*Document) Note

func (d *Document) Note(text string)

Note writes small print, for the provenance a rendered clinical document must carry.

func (*Document) Paragraph

func (d *Document) Paragraph(text string, font Font, size float64, indent float64)

Paragraph writes wrapped body text.

func (*Document) Rule

func (d *Document) Rule()

Rule draws a horizontal line.

func (*Document) SetMeta

func (d *Document) SetMeta(author, subject, keywords string)

SetMeta records the document information a reader displays and an archive indexes.

func (*Document) Table

func (d *Document) Table(header []string, rows [][]string, size float64)

Table writes a simple table with a bold header row.

Columns are sized by their widest cell rather than evenly, because clinical tables have one wide column of drug or problem names and several narrow ones, and even columns waste most of the page on dates.

type Font

type Font int

Font identifies one of the standard fonts a reader must provide.

const (
	Regular Font = iota
	Bold
	Italic
	Mono
)

type Options

type Options struct {
	// Title appears in the document metadata, not on the page.
	Title string

	// FontSize in points. Defaults to 10, which fits 80 characters across A4 in a monospaced font.
	FontSize float64

	// Landscape rotates the page. Useful for a wide report, which is most reconciliation output.
	Landscape bool

	// Created overrides the timestamp, for reproducible output. Zero means now.
	//
	// Exists because a PDF containing the current time cannot be compared byte for byte, and a test that cannot
	// compare its output can only check that something was produced.
	Created time.Time
}

Options control the document.

Jump to

Keyboard shortcuts

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