SferaDoc

An extensible Elixir library for generating PDFs from versioned Liquid templates, backed by pluggable storage adapters, template engines, and PDF renderers.

Features

Pluggable Storage

Store templates in PostgreSQL/SQLite via Ecto, in-process ETS, or Redis. Switch adapters without changing application code.

Template Versioning

Every update creates a new version. Roll back to any previous version with a single function call.

PDF Generation

Render Liquid templates to HTML, then to PDF via ChromicPDF (Chrome headless). Fully pluggable PDF engine.

Two-Tier PDF Cache

Optional hot cache (Redis/ETS) for fast reads and durable object store (S3/Azure/FileSystem) for persistence.

Variable Validation

Declare required and optional variables per template. SferaDoc validates them before rendering and returns clear errors.

Pluggable Adapters

Swap out the Liquid engine or PDF renderer by implementing a simple behaviour. No lock-in.

Installation

Add to mix.exs:

{:sfera_doc, "~> 0.1"}

Quick Start

# 1. Configure a storage backend
config :sfera_doc, :store,
  adapter: SferaDoc.Store.Ecto,
  repo: MyApp.Repo

# 2. Create a template
{:ok, _} = SferaDoc.create_template(
  "invoice",
  "<h1>Invoice for </h1>",
  variables_schema: %{"required" => ["customer_name"]}
)

# 3. Render to PDF
{:ok, pdf} = SferaDoc.render("invoice", %{"customer_name" => "Acme Corp"})
File.write!("invoice.pdf", pdf)

Documentation