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 ¶
- func Render(text string, opts Options) ([]byte, error)
- type Document
- func (d *Document) Bytes() []byte
- func (d *Document) Heading(text string, level int)
- func (d *Document) KeyValue(label, value string, size float64)
- func (d *Document) Note(text string)
- func (d *Document) Paragraph(text string, font Font, size float64, indent float64)
- func (d *Document) Rule()
- func (d *Document) SetMeta(author, subject, keywords string)
- func (d *Document) Table(header []string, rows [][]string, size float64)
- type Font
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document accumulates content and writes it as a PDF.
func (*Document) Bytes ¶
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 ¶
Heading writes a section heading with the space above it that makes it read as a break.
func (*Document) Note ¶
Note writes small print, for the provenance a rendered clinical document must carry.
func (*Document) SetMeta ¶
SetMeta records the document information a reader displays and an archive indexes.
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.