Skip to content

The backend library#

The backend layer is right above the PDF layer and contains low-level stuff like node lists, font and image loading and putting objects into a PDF file. With this library, you have complete control over the output you need but also have a few helper functions like a line breaking algorithm, hyphenation and color management.

Installation#

The installation is very simple by importing the package into your code. First initialize a module and get the library:

go mod init mymodule
go get github.com/boxesandglue/boxesandglue@latest

and use the library:

package main

import (
    "os"

    "github.com/boxesandglue/boxesandglue/backend/document"
)

func main() {
    w, _ := os.Create("out.pdf")
    doc := document.NewDocument(w)
    ...
}

Getting started#

The starting point is the PDFDocument:

func NewDocument(w io.Writer) *PDFDocument

With this document, you can load fonts and images, create pages and shipout pages, define colors and much more. Since the API is a bit extensive, it is covered in different chapters:

Core units
The basic definition of units and conversion between basic unit “scaled point” and other units.
Document level methods and settings
All building blocks around document structure, pages and output debugging.
Color spaces
Color spaces such as RGB, CMYK, spot colors and the PDF accessors.
Font handling
Loading fonts and turning text into font specific code points.
Image loading
Image loading.
Languages and hyphenation
Loading languages and hyphenation handling.
Nodes and node list manipulation
Nodes are the basic building blocks of all pages.
Interactive features
PDF has lots of interactive features such as hyperlinks and bookmarks.

Logging

Breaking paragraphs into lines