HTML mode

glu can convert HTML files directly to PDF. The same default stylesheet as in Markdown mode applies (serif, A4, 2cm margins); your own CSS layers on top and overrides it.

glu page.html    # → page.pdf

glu detects the mode by the file extension: .html or .htm for HTML mode.

Features

HTML mode supports:

  • Full HTML document structure (<!DOCTYPE html>, <html>, <head>, <body>)
  • <style> tags in <head> (including @page rules)
  • <link rel="stylesheet"> for external CSS files
  • CSS class and element selectors
  • The CSS properties of the htmlbag reference: fonts, borders, padding, backgrounds, page setup
  • Tables, lists, headings, paragraphs
  • Inline styles

Example

<!DOCTYPE html>
<html>
<head>
    <style>
        @page { size: a5; margin: 2cm; }
        body { font-family: serif; font-size: 10pt; }
        h1 { color: #336699; font-size: 20pt; }
        .highlight {
            border: 1pt solid #336699;
            padding: 6pt;
            border-radius: 3pt;
        }
    </style>
</head>
<body>
    <h1>Report</h1>
    <p>This PDF was generated from an HTML file.</p>
    <div class="highlight">
        <p>This section has a <strong>blue border</strong>.</p>
    </div>
</body>
</html>

Run with:

glu report.html    # → report.pdf

Barcodes

glu can generate barcodes directly as vector graphics in the PDF, with no external images needed. Use the <barcode> element in HTML or Markdown:

<barcode type="code128" value="ABC-123" width="4cm" height="1cm"/>

Supported types

Type Attribute value Description
EAN-13 ean13 13-digit product barcode
Code 128 code128 Variable-length alphanumeric barcode
QR Code qr 2D matrix barcode

Attributes

Attribute Required Description
type yes Barcode type (ean13, code128, qr)
value yes The data to encode
width no Width (default: 3cm)
height no Height (default: same as width). For QR codes, height is always equal to width.
eclevel no QR error correction level: L, M (default), Q, or H

Examples

EAN-13 barcode:

<barcode type="ean13" value="4006381333931" width="4cm" height="2cm"/>

QR code with high error correction:

<barcode type="qr" value="https://www.example.com" width="3cm" eclevel="H"/>

In Markdown, where raw HTML is supported, the same element works directly:

# My Product

<barcode type="code128" value="PROD-42" width="5cm" height="1cm"/>

Scan the barcode above for product details.

Differences from Markdown mode

Feature Markdown mode HTML mode
Default stylesheet Built-in (serif, A4, margins) Same built-in stylesheet
PDF bookmarks h1 and h2 share the top level, h3+ collapsed Nested 1:1 by heading level
Metadata YAML frontmatter <title>, <meta> and lang, see Standards
Attachments attachments: in the frontmatter Companion .lua, see Attachments
Lua blocks ```{lua} Not supported (use companion .lua)
Inline expressions {= expr =} Not supported
Go templates --template flag Not supported
@page rules Via frontmatter or CSS file Via <style> or <link>

HTML mode is ideal when you need full control over the document structure and styling, or when converting existing HTML content to PDF.

Beyond HTML

  • Styling with CSS: the default stylesheet, the order of stylesheets, margin boxes, counters, leaders and cross references.
  • Math: <math> elements with OpenType MATH fonts.
  • Standards: <meta name="pdf-format"> for tagged, archival and e-invoice PDFs.
  • Lua in documents: a companion file with callbacks.
  • Print-ready PDF: PDF/X, spot colors, overprint, bleed and crop marks.