MCPcopy Index your code
hub / github.com/boxesandglue/bagme

github.com/boxesandglue/bagme @v0.0.10

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.10 ↗ · + Follow
53 symbols 249 edges 2 files 26 documented · 49%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Explore in Constellation

bagme - boxes and glue made easy

bagme is a Go library that renders HTML/CSS to PDF using the boxes and glue typesetting engine. It implements TeX's line-breaking and page-breaking algorithms, so you get high-quality typesetting with almost no effort.

Multi-page HTML rendered to PDF by bagme

Ready-to-run examples (HTML → PDF, accessible PDF/UA, tables, positioned snippets, multi-page documents) live in the boxesandglue-examples repository.

Installation

go get github.com/boxesandglue/bagme

Render a complete HTML document

Use RenderPages for automatic page breaks, @page margins, and multi-page output:

package main

import (
    "log"

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

func main() {
    d, err := document.New("output.pdf")
    if err != nil {
        log.Fatal(err)
    }
    d.AddCSS(`
        @page { size: A4; margin: 2cm; }
        body { font-family: serif; font-size: 11pt; line-height: 1.4; }
        h1 { page-break-before: always; }
    `)
    if err := d.RenderPages(`
        <h1>Chapter 1</h1>


In olden times when wishing still helped one, there lived a king
        whose daughters were all beautiful...



        <h1>Chapter 2</h1>


Close by the king's castle lay a great dark forest, and under an
        old lime-tree in the forest was a well...


    `); err != nil {
        log.Fatal(err)
    }
    if err := d.Finish(); err != nil {
        log.Fatal(err)
    }
}

Place HTML snippets at exact positions

Use OutputAt for precise placement on a page (labels, forms, letterheads):

package main

import (
    "log"

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

func main() {
    d, err := document.New("out.pdf")
    if err != nil {
        log.Fatal(err)
    }
    d.AddCSS(`body { font-family: serif; font-size: 12pt; }`)

    ps, _ := d.PageSize()
    w := ps.ContentWidth
    x := ps.MarginLeft
    y := ps.Height - ps.MarginTop

    d.OutputAt("<h1>Hello, World!</h1>

Placed at exact coordinates.

", w, x, y)
    d.Finish()
}

Features

  • Automatic page breaks with CSS @page rules
  • page-break-before / page-break-after (always, avoid)
  • Page margin boxes (@top-center, @bottom-right, etc.) for headers/footers
  • CSS styling: fonts, colors, margins, padding, borders (rounded), backgrounds
  • Tables with colspan/rowspan, borders, and cell backgrounds
  • Ordered and unordered lists
  • Images (PDF, PNG) and inline SVG
  • OpenType features and variable fonts via font-feature-settings / font-variation-settings
  • TeX-quality line breaking (Knuth-Plass algorithm)
  • Heading extraction for table of contents generation
  • Pure Go — no C dependencies, no browser, single binary

Limitations

  • Limited CSS support compared to a full browser engine
  • No floats or flexbox/grid layout

Examples

Source + rendered PDF + preview PNG for every entry in boxesandglue-examples/bagme:

Example What it shows
Simple Basic HTML rendering with CSS styling, lists and code blocks
Border Borders, border-radius and background colors on elements
Accessible PDF PDF/UA output with automatic structure tagging for screen readers
Multipage Automatic page breaks, forced breaks with page-break-before
Positioned Manual placement with OutputAt using absolute coordinates
Table Tables with repeating headers across page breaks

Ecosystem

bagme is part of a broader ecosystem of PDF, typesetting and publishing technologies.

Explore the constellation →

Contact

Contact: gundlach@speedata.de

License: New BSD License

Status: Beta — API may change.

Mastodon: boxesandglue@typo.social

Extension points exported contracts — how you extend this code

Option (FuncType)
Option configures document creation. Use the With* functions to create options.
document/document.go

Core symbols most depended-on inside this repo

New
called by 22
document/document.go
Finish
called by 18
document/document.go
RenderPages
called by 16
document/document.go
WithZUGFeRD
called by 4
document/document.go
WithAttachment
called by 3
document/document.go
AddCSS
called by 3
document/document.go
OutputAt
called by 3
document/document.go
WithPDFUA
called by 2
document/document.go

Shape

Function 39
Method 11
Struct 2
FuncType 1

Languages

Go100%

Modules by API surface

document/document_test.go27 symbols
document/document.go26 symbols

For agents

$ claude mcp add bagme \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact