htmlbag module
The glu.htmlbag module
The glu.htmlbag module hands an in-memory HTML payload directly to
glu’s HTML rendering pipeline, skipping the disk roundtrip of writing
the HTML to a file just so glu file.html can read it back.
The intended user is a Lua script that builds HTML on the fly — for
example, an XSL-FO walker (see
boxesandglue-examples/glu/xslfo/foproc.lua) — and wants to produce a
PDF in a single glu invocation.
local htmlbag = require("glu.htmlbag")Functions
| Function | Description |
|---|---|
render(html_string, output_pdf [, base_dir]) |
Render an HTML string to a PDF |
render
Render an HTML payload to a PDF file.
htmlbag.render("<html><body><p>Hello.</p></body></html>", "out.pdf")Parameters:
html_string— the full HTML document as a string. The same content model as glu’s HTML mode applies:<style>tags,<link>external stylesheets,@pagerules, inline styles. See HTML mode and htmlbag for the supported HTML/CSS subset.output_pdf— path to the PDF file to write.base_dir(optional, defaults to.) — directory to resolve relative CSS paths against (e.g.<link rel="stylesheet" href="…">inside the HTML payload).
The function uses the same pipeline as glu file.html — installed
callbacks, the auxiliary file mechanism for cross-references, and
PDF/UA tagging if the document is configured for it. It returns
nothing on success; it raises a Lua error on failure.
Example: a tiny FO-like walker
local htmlbag = require("glu.htmlbag")
local html = [[
<!DOCTYPE html>
<html>
<head>
<style>
@page { size: A5; margin: 2cm; }
body { font-family: serif; font-size: 11pt; }
</style>
</head>
<body>
<h1>Generated from Lua</h1>
<p>No intermediate HTML file on disk.</p>
</body>
</html>
]]
htmlbag.render(html, "generated.pdf")Run with:
glu walker.lua # writes generated.pdf