Documentation
¶
Overview ¶
Package docpdf renders an evaluated document to PDF by driving external converters as subprocesses; no PDF renderer is linked into the binary. An engine reading HTML is handed the HTML backend's markup with the print stylesheet; one reading Markdown is handed the Markdown backend's text.
Index ¶
Constants ¶
const ( PandocEnv = "OPENSYSML_PANDOC" WeasyPrintEnv = "OPENSYSML_WEASYPRINT" PrinceEnv = "OPENSYSML_PRINCE" MermaidEnv = "OPENSYSML_MMDC" // MermaidPuppeteerEnv names an optional puppeteer configuration file // passed to mmdc, for environments whose browser needs launch flags. MermaidPuppeteerEnv = "OPENSYSML_MMDC_PUPPETEER" KatexEnv = "OPENSYSML_KATEX" // KatexCSSEnv names KaTeX's stylesheet, with its fonts directory beside // it, when it is not in the dist directory of the katex executable. KatexCSSEnv = "OPENSYSML_KATEX_CSS" // DotEnv names the Graphviz dot executable that draws DOT blocks; absent, // they are kept as source. DotEnv = "OPENSYSML_DOT" // JavaEnv names the java that runs the PlantUML jar. JavaEnv = "OPENSYSML_JAVA" // PlantUMLJarEnv names the PlantUML jar that draws PlantUML blocks; absent, // they are kept as source. PlantUMLJarEnv = "OPENSYSML_PLANTUML_JAR" // D2Env names the d2 executable that draws D2 blocks; absent, they are // kept as source. D2Env = "OPENSYSML_D2" )
Environment variables that point each external tool's discovery at a specific executable, ahead of a PATH lookup by its default name.
const DefaultTableColumns = 12
DefaultTableColumns is the widest table one landscape page sets legibly at the print stylesheet's dense-table size before the column set is split.
const DefaultTableMeasure = 140
DefaultTableMeasure is the characters of bold dense-table type (8pt), the type every part of a split table is set in, across the text width of a landscape page at the print stylesheet's margins: 667pt on letter, 717pt on A4, at about 4.8pt a character of a camel-cased heading.
Variables ¶
var PrintStylesheet string
PrintStylesheet is the PDF backend's print stylesheet: page geometry, the page counter, print fonts and breaks, over the HTML backend's default sheet in a later cascade layer so a reader's unlayered stylesheet still wins. It declares the layer a theme's print companion fills after its own.
Functions ¶
func DrawSVG ¶ added in v0.9.2
DrawSVG draws every DOT diagram of a document through Graphviz and returns its SVG markup, in order, for the HTML and Markdown backends to write inline; a diagram in another form has an empty entry. Callers check Graphviz.Available first: a missing dot is an error here, not a fallback.
func Engines ¶
func Engines() []string
Engines names the converters, in the order they are offered. The first is the default.
func Render ¶
Render lays an evaluated document out as PDF with the named engine: its graph-shaped diagrams drawn and its formulas typeset ahead of conversion, then the HTML backend's markup with the print stylesheet for an engine reading HTML, or the Markdown backend's text for one reading Markdown.
Types ¶
type Capabilities ¶
Capabilities is what a converter states about itself: the form it reads, the executables it drives, and whether it applies the deliverable options natively rather than through the prepared HTML.
type Converter ¶
type Converter interface {
// Name is what -pdf-engine selects the converter by.
Name() string
// Capabilities states the converter's input form and tools.
Capabilities() Capabilities
// Available returns nil, or a typed error naming the missing tool.
Available() error
// Convert lays the prepared document out as PDF bytes.
Convert(doc *Prepared) ([]byte, error)
}
Converter is one external Markdown/HTML-to-PDF toolchain, run as a subprocess.
func EngineNamed ¶
EngineNamed returns the converter -pdf-engine named, the default for "", and a typed error for a name no converter answers to.
type Error ¶
type Error struct {
Kind ErrorKind
// Engine is the converter that was selected, where one was.
Engine string
// Tool is the external executable involved: its configured override or
// its default name for ErrorToolMissing, its path for ErrorToolFailed.
Tool string
// EnvVar is the environment variable that overrides where Tool is found.
EnvVar string
// Engines lists the converters an unknown -pdf-engine could have named.
Engines []string
// Detail carries what the tool said on stderr, trimmed.
Detail string
// Option names the command-line option a converter cannot apply.
Option string
// Columns is the table-column limit the options state, for ErrorTableColumns.
Columns int
}
Error is a typed PDF-rendering failure.
type ErrorKind ¶
type ErrorKind string
ErrorKind classifies a PDF-rendering failure.
const ( // ErrorUnknownEngine reports a -pdf-engine name no converter answers to. ErrorUnknownEngine ErrorKind = "unknown-engine" // ErrorToolMissing reports an external tool the selected converter needs // that could not be found. ErrorToolMissing ErrorKind = "tool-missing" // ErrorToolFailed reports an external tool that ran and failed. ErrorToolFailed ErrorKind = "tool-failed" // ErrorNoPDF reports a converter that succeeded without producing a PDF. ErrorNoPDF ErrorKind = "no-pdf" // ErrorUnsupportedOption reports a stylesheet option the selected // converter cannot apply, as it writes its own HTML. ErrorUnsupportedOption ErrorKind = "unsupported-option" // ErrorImageMissing reports an image block whose file cannot be found // where its location resolves. ErrorImageMissing ErrorKind = "missing-image" // ErrorTableColumns reports a table-column limit no continuation table // keeps: one leaves no room beside the repeated first column. ErrorTableColumns ErrorKind = "table-columns" )
type Graphviz ¶ added in v0.9.2
type Graphviz struct{}
Graphviz is the docrender.DiagramDrawer the HTML and Markdown backends draw the automatic choice's DOT diagrams with: the dot found on PATH or where OPENSYSML_DOT points.
type Options ¶
type Options struct {
// TitlePage puts the document title in a page of its own.
TitlePage bool
// TOC writes a table of contents ahead of the content.
TOC bool
// NumberSections numbers the section headings hierarchically.
NumberSections bool
// NumberFigures numbers the figures and tables in their captions, as
// docrender.HTMLOptions.NumberFigures.
NumberFigures bool
// Theme names the HTML backend's bundled theme laid under the print
// stylesheet, with the theme's print companion, when it carries one, laid
// over the print stylesheet; empty is the default sheet alone.
Theme string
// NoDefaultStylesheet leaves the HTML backend's default sheet out, and the
// print stylesheet layered over it, so Stylesheets alone style the page.
NoDefaultStylesheet bool
// Stylesheets are the reader's, attached after the bundled sheets and
// unlayered, so they override them as they override the HTML form.
Stylesheets []docrender.Stylesheet
// BaseDir is the directory a reader stylesheet's relative url() and
// @import references resolve against, the current directory when empty:
// the PDF's own, as an HTML page's sheets resolve against the page's; and
// an image block's relative location when its source is no file on disk.
BaseDir string
// Lang is the document language, "en" when empty.
Lang string
// DiagramForm is the source graph-shaped diagrams are drawn from. Empty
// picks per diagram: DOT drawn by Graphviz for a rendering a Layout or
// Route positions when Graphviz is installed, Mermaid otherwise, the
// document stating each fallback.
DiagramForm view.Form
// Unplaced is where a diagram some Layout positions puts the nodes none
// does: left undrawn when empty, or drawn too (a strip below a DOT drawing).
Unplaced view.Unplaced
// Style is the drawing style every DOT diagram is drawn in, the Pilot look
// when empty.
Style view.DrawingStyle
// LinkTemplate fills source links for diagram elements.
LinkTemplate string
// TableColumns is the most columns one table is set with on a page: a
// table projecting more is split into continuation tables, each repeating
// the first column ahead of its share of the rest. 0 is DefaultTableColumns;
// 1 is refused, as nothing would fit beside the repeated column.
TableColumns int
// TableMeasure is the characters of heading type one landscape table line
// holds: a table whose headings need more is split into continuation
// tables whose headings each set unbroken. 0 is DefaultTableMeasure.
TableMeasure int
}
Options are the deliverable choices of the PDF backend: the document options every engine applies, and the stylesheet choices the HTML-input engines take, meaning what they mean for -doc-form html.
type Prepared ¶
type Prepared struct {
// Dir is the working directory holding every input, diagram SVGs included.
Dir string
// MarkdownFile is the Markdown document's name within Dir, for a converter
// reading Markdown; empty for one reading HTML.
MarkdownFile string
// Filter is a pandoc Lua filter within Dir that swaps the drawn diagrams
// and typeset formulas into the Markdown; empty when there are none.
Filter string
// HTMLFile is the HTML document's name within Dir, for a converter reading
// HTML; empty for one reading Markdown.
HTMLFile string
// MathCSS is the KaTeX stylesheet's path within Dir, for converters that
// read the Markdown themselves; empty when the document has no formulas.
MathCSS string
// BaseDir is the absolute directory the document's relative references
// resolve against; Dir's own files are referenced by absolute file URL.
BaseDir string
// Options are the deliverable choices, for converters with native flags.
Options Options
}
Prepared is one document laid out in a working directory for a converter, in the form the converter reads, with its diagrams drawn and its formulas typeset beside it.