The frontend library

The entry point for the frontend library is to create a new document instance:

func New(filename string) (*Document, error)

This creates a new PDF file with the given name and returns the “document” struct:

type Document struct {
	FontFamilies    map[string]*FontFamily
	Doc             *document.PDFDocument
	DefaultFeatures []harfbuzz.Feature
	FindFile        func(string) string
}

Fonts and font families

To use fonts you have to group them in font families. Each font family consist of one or more members, so called font sources. Fonts are loaded on demand, first you create font families with font sources and when chosen to be used in the PDF, boxes and glue tries to load the font.

Step 1: create a font source struct:

fontsource := &frontend.FontSource{Source: "myfont.ttf"}

Step 2: add fonts to the font families:

Now that you have one or more font sources, you can create a font family and add members:

func (fe *Document) NewFontFamily(name string) *FontFamily
func (ff *FontFamily) AddMember(fontsource *FontSource, weight FontWeight, style FontStyle)

Where FontStyle is one of FontStyleNormal, FontStyleItalic and FontStyleOblique and FontWeight is an int between 100 and 900 where 100 is a thin font and 900 is a heavy font.

Language settings and hyphenation

GetLanguage returns a language object for the language.

func GetLanguage(langname string) (*lang.Lang, error)

where the language name is one of bg, ca, cs, cy, da, de, el, en, en_gb, en_us, eo, es, et, eu, fi, fr, ga, gl, grc, gu, hi, hr, hu, hy, id, is, it, ku, kn, lt, ml, lv, nb, nl, nn, no, pl, pt, ro, ru, sk, sl, sc, sv, tr or uk.

You must set the document’s default language:

// error checking omitted
f, err := frontend.New(...)
l, err := frontend.GetLanguage("en")

f.Doc.DefaultLanguage = l

Paragraphs

Typesetting tables

See Tables