xml2pdf Playground Source

xml2pdf

Describe a document in XML (pages, text, images, tables, watermarks, headers and footers) and get a PDF. It ships as a single static binary with no runtime dependencies and renders in milliseconds.

<?xml version="1.0" encoding="UTF-8"?>
<document title="Hello" page-size="A5" margin="15mm">
  <constants>
    <const name="name" value="World"/>
  </constants>

  <resources>
    <style id="title" size="24" bold="true" color="#1f4e9c" margin-bottom="8"/>
  </resources>

  <footer><text align="center" size="8" color="gray">Page {page} of {pages}</text></footer>

  <page>
    <text style="title">Hello, ${name}!</text>
    <text margin-bottom="10">This PDF was generated from XML. Text wraps automatically,
      and you can mix <b>bold</b>, <i>italic</i> and <span color="red">colored</span> runs.</text>
    <table widths="2*,1*" header-bg="#eef2f9">
      <row header="true"><cell>Feature</cell><cell>Status</cell></row>
      <row><cell>Text, images, tables</cell><cell>Ready</cell></row>
      <row><cell>Watermarks, headers, footers</cell><cell>Ready</cell></row>
    </table>
  </page>
</document>
The rendered hello.xml: a title, a paragraph with bold, italic and red text, a small table and a page footer.

hello.pdf rendered from the XML on the left

Try it without installing anything: the playground runs xml2pdf in your browser. Edit the XML and JSON and the PDF updates as you type.

Features

Quick start

Install on Linux or macOS with one command:

curl -fsSL https://raw.githubusercontent.com/sandeepkumarmishra354/xml-to-pdf/main/install.sh | sh

On Windows, download the zip from the latest release (see Install for all the options). To build from source instead, you need Go 1.24 or newer:

git clone https://github.com/sandeepkumarmishra354/xml-to-pdf
cd xml-to-pdf
make build                      # produces bin/xml2pdf

Render a document. The examples are in the repository and inside every release archive; if you built from source, use bin/xml2pdf:

xml2pdf examples/hello.xml                           # writes examples/hello.pdf
xml2pdf examples/hello.xml --set name=Alice          # override a variable
xml2pdf examples/invoice.xml --data examples/invoice.json -o invoice.pdf

Every document has a <document> root with one or more <page> elements. Everything else is optional. The guide explains how it all fits together, and the element reference lists every tag and attribute.

Where to next