render

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckChromeAvailable

func CheckChromeAvailable() error

func RenderToPDF

func RenderToPDF(htmlContent string, outputPath string, opts Options) error

RenderToPDF composes htmlContent into a PDF at outputPath. It never returns audit findings — use RenderToPDFWithAudit for that — but always keeps this signature exactly as-is for API stability.

Types

type AuditReport added in v0.8.0

type AuditReport struct {
	Issues []Issue
}

AuditReport collects every Issue found while rendering a single document. A nil report or one with no Issues means the audit found nothing to flag — it does not guarantee the PDF is perfect, only that none of the checks it runs caught a problem.

func RenderToPDFWithAudit added in v0.8.0

func RenderToPDFWithAudit(htmlContent string, outputPath string, opts Options) (*AuditReport, error)

RenderToPDFWithAudit does exactly what RenderToPDF does, and additionally runs a best-effort visual/structural audit (see audit.go) of the composed document, returning its findings alongside any render error. The audit never turns a successful render into a failure: an audit finding is a warning about the *output*, not a reason to reject it.

Keeps this signature exactly as-is for API stability — it roots the browser in context.Background() internally, so a caller that needs to cancel an in-flight render (e.g. on client disconnect or SIGINT) should use RenderToPDFWithAuditContext instead.

func RenderToPDFWithAuditContext added in v0.8.0

func RenderToPDFWithAuditContext(ctx context.Context, htmlContent string, outputPath string, opts Options) (*AuditReport, error)

RenderToPDFWithAuditContext is RenderToPDFWithAudit with the browser rooted in ctx instead of context.Background(): canceling ctx (client disconnect, SIGINT wired to context cancellation, etc.) now actually tears down the in-flight Chrome allocator/render instead of running to completion or to opts.Timeout regardless. opts.Timeout still applies as an upper bound layered on top of ctx via context.WithTimeout.

func (*AuditReport) HasIssues added in v0.8.0

func (r *AuditReport) HasIssues() bool

HasIssues reports whether the audit found anything worth surfacing to the caller. Safe to call on a nil report.

type Issue added in v0.8.0

type Issue struct {
	// Check is a short, stable, machine-readable identifier for the rule
	// that produced this issue (e.g. "overflow-x", "low-contrast",
	// "heading-clip-risk"), suitable for filtering or documentation links.
	Check    string
	Severity Severity
	Message  string
}

Issue is one finding from a post-compose/pre-print visual/structural audit of the document: something that renders but is likely wrong — clipped, overlapping, unreadable, or missing — rather than a hard error.

type Options

type Options struct {
	Timeout       time.Duration
	HeaderTitle   string
	MarginTop     float64
	MarginBottom  float64
	MarginLeft    float64
	MarginRight   float64
	PaperWidth    float64
	PaperHeight   float64
	NetworkAccess bool
	PageNumbers   bool
	ShowHeader    bool
	// CoverImagePath, when non-empty, prepends a full-bleed cover page
	// built from this image (.png/.jpg/.jpeg) before the rest of the
	// document. That cover page's dimensions match the image's own pixel
	// dimensions exactly (see coverImageDimensionsIn) rather than
	// PaperWidth/PaperHeight — a square image gets a square cover page —
	// while every other page keeps the configured paper size untouched.
	CoverImagePath string
	// ChromeExecPath, when non-empty, pins chromedp to this specific
	// Chrome/Chromium/chrome-headless-shell binary instead of letting it
	// search the system's default install locations. Callers resolving a
	// browser via chromemgr.EnsureChrome pass its result straight through
	// here; leaving it empty preserves the previous default-discovery
	// behavior exactly.
	ChromeExecPath string
}

func DefaultOptions

func DefaultOptions() Options

type Severity added in v0.8.0

type Severity string

Severity classifies an audit Issue. Only SeverityWarning exists today — the audit is advisory and never fails a build — but the type leaves room for a future SeverityError without an API break.

const SeverityWarning Severity = "warning"

Jump to

Keyboard shortcuts

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