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 [, opts]) |
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.opts(optional) — either a string (treated asbase_dir) or an options table:Key Type Description base_dirstring Directory to resolve relative CSS paths against (default .).formatstring PDF conformance level: PDF(default),PDF/A-3b,PDF/X-3,PDF/X-4,PDF/UA/PDF/UA-1(ISO 14289-1),PDF/UA-2(ISO 14289-2 on PDF 2.0).langstring BCP 47 language tag written to PDF /Langand used as the default hyphenation language. Required for anyPDF/UA*format.titlestring PDF /Titleand XMPdc:title. Required for anyPDF/UA*format (readers show it instead of the filename).
The function uses the same pipeline as glu file.html — installed
callbacks, the auxiliary file mechanism for cross-references, and
PDF/UA tagging if format is set to one of the UA values. 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