tmpl

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tmpl renders Go html/templates through Paper's HTML-to-PDF pipeline.

It provides a template input mode alongside Paper's component API and raw HTML conversion: html/template -> pkg/html rows -> generated PDF.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(ctx context.Context, templateStr string, data any, opts *Options) ([]core.Row, error)

Render executes templateStr with data and converts the resulting HTML into Paper rows.

func RenderDocument

func RenderDocument(ctx context.Context, templateStr string, data any, opts *Options) (*core.Pdf, error)

RenderDocument executes templateStr with data and returns a generated PDF.

func RenderFile

func RenderFile(ctx context.Context, templatePath string, data any, opts *Options, outPath string) error

RenderFile reads a template from disk, executes it, and writes the PDF to outPath. Relative image and stylesheet references resolve against the template's directory unless HTMLOptions overrides those base directories.

func RenderFileTo

func RenderFileTo(ctx context.Context, w io.Writer, templatePath string, data any, opts *Options) error

RenderFileTo reads a template from disk, executes it, and writes the PDF to w. It is useful for HTTP handlers that stream generated PDFs directly.

func RenderTo

func RenderTo(ctx context.Context, w io.Writer, templateStr string, data any, opts *Options) error

RenderTo executes templateStr with data and writes the generated PDF to w.

Types

type Options

type Options struct {
	// Funcs registers custom helpers for html/template. Custom helpers
	// override built-in helpers with the same name.
	Funcs htmltpl.FuncMap

	// BaseTemplate is an optional pre-parsed template tree. Template strings
	// are parsed into a clone of this tree so shared definitions are available
	// without mutating the caller's template.
	BaseTemplate *htmltpl.Template

	// HTMLOptions are passed to pkg/html after template execution.
	HTMLOptions []paperhtml.Option

	// Config is the Paper document configuration used by RenderDocument,
	// RenderTo, RenderFile, and RenderFileTo.
	Config *entity.Config
}

Options configures template rendering. All fields are optional.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL