pdf

package module
v0.0.0-...-f436381 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 8 Imported by: 0

README

pdf

Go Reference

Composable PDF rendering primitives structured like the go-mx html package, but targeting the codeberg.org/go-pdf/fpdf renderer instead of an HTML markup writer.

import "github.com/ungerik/go-mx/pdf"

doc := pdf.NewDocument("Invoice",
    pdf.Font(pdf.Helvetica, pdf.StyleBold, 24),
    pdf.Paragraph("Hello, PDF!"),
    pdf.MoveDown(4),
    pdf.Save( // scoped style — restored after these children
        pdf.TextColor(pdf.Gray50),
        pdf.Font(pdf.Helvetica, pdf.StyleRegular, 10),
        pdf.Paragraph("Generated with go-mx/pdf."),
    ),
)
err := doc.OutputFile(ctx, "hello.pdf")

This module has its own go.mod so the fpdf dependency stays isolated from the rest of go-mx. It does not import the root mx package; it re-creates the same patterns against a different renderer.

Relationship to the html package

The mapping to html is deliberate, so the two packages feel the same:

html / mx pdf
Component (Render(ctx, Writer)) Component (Render(ctx, *Renderer))
markup Writer Renderer (embeds *fpdf.Fpdf)
Components, If, ForEach Components, If, ForEach
html.Document pdf.Document
elements (Div, P, …) primitives (Paragraph, Rect, …)
attributes (Class, Style, …) state components (Font, Color, …)

The crucial difference is that PDF has no element tree. HTML is a retained tree of nested elements with attributes; fpdf is an imperative, stateful drawing API where the current page, cursor, font and colors persist from call to call. So the pdf primitives are thin wrappers around that state machine, not a tree, and "attributes" become state components (Font, TextColor, …) that mutate the renderer until changed. Use Save to scope a state change to a group of children.

The Renderer

Renderer embeds *fpdf.Fpdf, so every fpdf method is available directly and any primitive can be expressed in raw fpdf when the typed helpers do not cover it:

r := pdf.NewRendererA4Portrait()
r.AddPage()
r.SetDrawColor(255, 0, 0) // raw fpdf
pdf.Line(10, 10, 100, 10).Render(ctx, r) // typed primitive

The renderer also adds in-memory asset helpers (LoadUTF8FontBytes, LoadUTF8FontReader) on top of fpdf — see In-memory assets.

Primitives

  • TextText, Textf, Cell, CellFormat, MultiCell, Paragraph, TextAt, Ln, NewLine. A bare string child becomes flowing Text.
  • VectorLine, Rect, RoundedRect, Circle, Ellipse, Polygon.
  • ImagesImage (file path), ImageReader / ImageBytes (in memory).
  • StateFont, FontSize, TextColor, FillColor, DrawColor, LineWidth, LineCap, LineJoin, X, Y, XY, MoveDown, MoveRight.
  • LayoutPage, PageFormat, Document.

The first drawing primitive (or the first Page) automatically opens page one, so a one-page document does not need an explicit Page.

Shortcuts and constants

Closed-set values are typed enums with generated Valid / Validate / Enums / EnumStrings methods (via go generate ./..., the go-enum tool pinned in the tools module), so the compiler guides you and values can be validated:

  • Orientation (Portrait, Landscape)
  • Unit (UnitPoint, UnitMillimeter, UnitCentimeter, UnitInch)
  • PageSize (A1A8, Letter, Legal, Tabloid)
  • FontStyle (StyleRegular, StyleBold, StyleItalic, StyleUnderline, StyleStrikeOut, and every combination, e.g. StyleBoldItalic) — the named combos double as concatenations: StyleBold + StyleItalic == StyleBoldItalic
  • Border (BorderNone, BorderFull, the four edges, and every combination, e.g. BorderLeftTop) — the named combos double as concatenations: BorderLeft + BorderTop == BorderLeftTop
  • HAlign (AlignLeft, AlignCenter, AlignRight, AlignJustify) and VAlign (AlignTop, AlignMiddle, AlignBottom, AlignBaseline) — two single-choice axes for cell text alignment
  • DrawOp (Stroke, FillShape, FillStroke)
  • LnPos (LnRight, LnNewline, LnBelow)
  • LineCapStyle (CapButt, CapRound, CapSquare)
  • LineJoinStyle (JoinMiter, JoinRound, JoinBevel)
  • ImageType (ImagePNG, ImageJPEG, ImageGIF) for in-memory images

The only genuinely open value is the font family name, a plain string because any registered font is valid: Helvetica, Arial, Times, Courier, Symbol, ZapfDingbats, or any family added with LoadUTF8Font….

Plus the RGB Color type with named colors (Black, White, Red, …), RGB, Gray, and a CSS-style Hex / MustHex parser, and Point (alias of fpdf.PointType) with the Pt(x, y) helper.

The shortest path to a one-page document is Paragraph, which is a full-width, auto-line-height, left-aligned MultiCell — the PDF analog of <p>.

Scoping state with Save
pdf.Save(
    pdf.TextColor(pdf.Red),
    pdf.Font(pdf.Times, pdf.StyleItalic, 14),
    pdf.Paragraph("only this text is red and italic"),
)

Save captures and restores the font (family, style and size), the text/fill/draw colors, the line width, the line cap/join styles and the cursor position, using fpdf's getters — so it works whether the state was set through this package or the raw embedded renderer. The dash pattern and the alpha/blend mode are not restored (fpdf has no dash-pattern getter, and its zero alpha value is indistinguishable from a deliberate fully-transparent setting); reset those explicitly if you change them inside the scope. The cursor restore assumes children stay on the same page — if they trigger an automatic page break, the restored position lands on the new page, so Save is for scoping style, not page flow.

In-memory assets

No asset needs to live on disk. Images draw from memory with ImageReader / ImageBytes:

pdf.ImageBytes("logo", pdf.ImagePNG, pngBytes, 20, 40, 30, 30)

The name argument is fpdf's image cache key — reuse it to draw the same image without re-decoding, and give distinct images distinct names.

Fonts load from memory through the renderer. LoadUTF8FontBytes / LoadUTF8FontReader register an embedded TrueType font and switch the translator to identity so non-Latin text works without any .ttf file:

r := doc.NewRenderer()
r.LoadUTF8FontBytes("DejaVu", pdf.StyleRegular, ttfBytes)
// then select it: pdf.Font("DejaVu", pdf.StyleRegular, 12)

The remaining fpdf assets are already in-memory-capable on the embedded *fpdf.Fpdf: metrics-format fonts via AddFontFromBytes / AddFontFromReader, file attachments via SetAttachments (the Attachment carries its bytes), and XMP metadata via SetXmpMetadata.

Document

Document carries metadata, page setup, a default font, optional per-page Header/Footer, and the body. It renders to a Renderer, an io.Writer (Output), a []byte (Bytes), a file (OutputFile), or an http.ResponseWriter (ServeHTTP, served as application/pdf with a generic 500 on error). All page-setup fields default to A4 / portrait / millimeters with a Helvetica 12pt font.

Coordinate system and units

fpdf puts the origin at the top-left and Y grows downward (the PDF imaging model itself uses a bottom-left origin). All coordinates, widths and heights are in the document Unit; font sizes are always in points regardless of the document unit.

Errors

fpdf accumulates the first error internally and silently turns subsequent calls into no-ops; you must check Renderer.Error(). Every primitive in this package does that for you and returns it from Render, and components honor context cancellation.

Concurrency

An *fpdf.Fpdf — and therefore a Renderer — is stateful and not safe for concurrent use. Build each document from a single goroutine.


Limitations of the fpdf renderer vs. the PDF specification

fpdf is a pragmatic generator, not a full PDF implementation. It emits PDF 1.3 (bumped to 1.4 for alpha/blend modes and 1.5 for layers). The following parts of the PDF spec are unsupported or only partially supported. Where a primitive in this package can't help, drop down to the embedded *fpdf.Fpdf or post-process the output with a more complete library.

Text and fonts
  • Standard ("core") fonts are cp1252 only. Helvetica/Arial, Times, Courier, Symbol and ZapfDingbats use the Windows Western-Europe encoding. Characters outside cp1252 (most non-Latin scripts, many typographic symbols) require embedding a TrueType/UTF-8 font — from a file via Renderer.AddUTF8Font, or from memory via Renderer.LoadUTF8FontBytes / LoadUTF8FontReader, which also switch the translator so UTF-8 strings pass through unchanged.
  • No complex text shaping. No ligatures, contextual forms, Indic reordering, mark positioning or kerning beyond raw font metrics. RTL() merely reverses direction; there is no Unicode bidi algorithm and no Arabic/Hebrew shaping. No vertical writing modes.
  • No hyphenation. MultiCell wraps on spaces only; a single word wider than the box is broken crudely by character.
  • Limited font formats. TrueType and Type1; non-UTF8 core-font use needs metrics generated by the makefont tool. No reliable OpenType-CFF (.otf with PostScript outlines), no variable fonts, no automatic system-font discovery.
Color and graphics
  • Color spaces: DeviceRGB and DeviceGray only, plus Separation spot colors (AddSpotColor). No ICC-based color, no CIE Lab, and CMYK only via spot colors — there is no direct DeviceCMYK fill/stroke.
  • Shadings/patterns: only axial (linear) and radial gradients. No tiling patterns, no function-based, free-form/lattice (Gouraud) or Coons/ tensor mesh shadings (PDF shading types 4–7).
  • Transparency: constant alpha and blend modes via SetAlpha, and an image soft mask, but no general soft masks, transparency groups, or isolated/knockout groups.
Images
  • JPEG, PNG and GIF only (PNG alpha supported via soft mask). No TIFF, BMP, WebP, JPEG 2000, or inline images. CMYK JPEG support is limited.
Interactivity and structure
  • No interactive form fields (AcroForm). No text fields, checkboxes, radio buttons, choice lists or push buttons. (Link annotations, file-attachment annotations, document-level JavaScript and a basic outline/bookmark tree are available.)
  • Annotations are limited to links and file attachments — no highlight, text/sticky-note, stamp, ink, redaction or widget annotations.
  • No Tagged PDF / accessibility (PDF/UA). No structure tree, logical reading order, alt text, or /Tagged marking, so output is not accessible.
  • No full PDF/A or PDF/X conformance. v0.12.0 adds AddOutputIntent for an ICC output intent and SetXmpMetadata for XMP — the building blocks — but nothing enforces or validates archival/print conformance, and font embedding, color and metadata still have to be made conformant by hand.
  • Optional content (layers) is supported only as simple show/hide groups, not nested membership dictionaries or complex configurations.
Security
  • Encryption is RC4 (40/128-bit) only via SetProtection — the legacy standard security handler. No AES-128 or AES-256, so protection is weak by modern standards.
Other
  • No SVG import beyond SVGBasicWrite / SVGBasicDraw, which handle only basic path data (<path d="…"> move/line/curve/close) — no SVG text, gradients, filters, clipping or transforms.
  • No page transitions, multimedia, 3D, embedded-file UI, or digital signatures.

Documentation

Overview

Package pdf provides composable PDF rendering primitives structured like the go-mx html package, but targeting the codeberg.org/go-pdf/fpdf renderer instead of an HTML markup writer.

The correspondence to the html package is deliberate:

  • Component is the html Component: anything that can draw implements Render(context.Context, *Renderer) error.
  • Renderer replaces the markup writer. It embeds *fpdf.Fpdf, so every fpdf method is available directly and any primitive can be expressed in raw fpdf when needed.
  • Components, If, Iff, ForEach and ForEachIter mirror their mx counterparts for composing and conditionally rendering content.
  • Document is html.Document: it carries metadata, page setup and a body, and renders to a Renderer, an io.Writer, a file or an http.ResponseWriter.

Unlike HTML, PDF has no element tree. fpdf is an imperative, stateful drawing API: the current page, cursor, font and colors persist across calls. The primitives here are therefore thin wrappers around that state machine rather than a retained tree. They divide into:

Closed-set values are typed enums with generated Valid, Validate, Enums and EnumStrings methods (Orientation, Unit, PageSize, FontStyle, HAlign, VAlign, Border, DrawOp, LnPos, LineCapStyle, LineJoinStyle, ImageType); FontStyle enumerates all sixteen bold/italic/underline/ strike-out combinations and Border all sixteen left/top/right/bottom edge combinations plus the "1" full-border shorthand, while horizontal and vertical cell alignment are two independent single-choice axes (HAlign, VAlign). The only genuinely open value is the font family name (Helvetica, …, or any registered font), which stays a plain string constant. There is also an RGB Color type with named colors and a Hex parser.

A minimal document:

doc := pdf.NewDocument("Hello",
	pdf.Font(pdf.Helvetica, pdf.StyleBold, 24),
	pdf.Paragraph("Hello, PDF!"),
)
err := doc.OutputFile(ctx, "hello.pdf")

See README.md for the limitations of the fpdf renderer relative to the PDF specification.

Index

Constants

View Source
const (
	DefaultFontFamily = Helvetica
	DefaultFontSize   = 12.0
)

Defaults applied by the Renderer constructors and Document so text can be drawn without explicit setup.

View Source
const (
	Helvetica    = "Helvetica"    // sans-serif (alias of Arial)
	Arial        = "Arial"        // sans-serif (alias of Helvetica)
	Times        = "Times"        // serif
	Courier      = "Courier"      // fixed-width
	Symbol       = "Symbol"       // symbolic
	ZapfDingbats = "ZapfDingbats" // symbolic
)

Standard (core) font families, which need no font files. These are untyped string constants because any family registered with the raw fpdf AddFont / AddUTF8Font API (or Renderer.LoadUTF8FontBytes) is an equally valid family name and can be passed as a plain string.

View Source
const ContentType = "application/pdf"

ContentType is the MIME type of PDF output.

Variables

View Source
var (
	Black   = Color{0, 0, 0}
	White   = Color{255, 255, 255}
	Red     = Color{255, 0, 0}
	Green   = Color{0, 128, 0}
	Blue    = Color{0, 0, 255}
	Yellow  = Color{255, 255, 0}
	Cyan    = Color{0, 255, 255}
	Magenta = Color{255, 0, 255}
	Gray50  = Color{128, 128, 128}
	Silver  = Color{192, 192, 192}
	Orange  = Color{255, 165, 0}
)

Common named colors, matching the basic CSS keyword palette.

View Source
var (
	// AsComponent converts a value passed as a child into a Component. It
	// defaults to DefaultAsComponent — see its docs for the recognized types and
	// the github.com/domonda/go-pretty fallback used to draw an unexpected value
	// as text. Document, page, state and component constructors call AsComponent
	// indirectly (via AsComponents), so assigning a different func changes child
	// conversion everywhere.
	//
	// For example, to turn the silent "unexpected value becomes text" fallback
	// into a hard failure during development (widen the accepted set to taste):
	//
	//	base := pdf.AsComponent
	//	pdf.AsComponent = func(c any) pdf.Component {
	//		switch c.(type) {
	//		case nil, pdf.Component, string:
	//			return base(c)
	//		default:
	//			panic(fmt.Sprintf("pdf: unexpected child of type %T", c))
	//		}
	//	}
	AsComponent = DefaultAsComponent
)

The variables in this file are the package-level configuration of the pdf package, mirroring the configuration vars of the mx package. Each has a working default and is consulted while a document tree is built or rendered, so assigning a different value changes that behavior for the whole program. They are plain package variables with no locking: set them once during initialization (before any concurrent rendering), not while rendering.

Functions

This section is empty.

Types

type Border

type Border string //#enum

Border selects which cell edges are stroked. The four edges are independent fpdf flags (L, T, R, B); every combination is enumerated below in canonical L-T-R-B order, so the values serve both as a closed enum and as the result of concatenating the single-edge constants — BorderLeft + BorderRight equals BorderLeftRight. Concatenate in L-T-R-B order to stay within the enumerated set. BorderNone strokes nothing; BorderFull is fpdf's "1" shorthand that strokes all four edges as a single rectangle — a more compact content stream than the otherwise equivalent BorderLeftTopRightBottom, which strokes four separate lines.

const (
	// BorderNone strokes no cell edge.
	BorderNone Border = "" // no border
	// BorderFull strokes all four edges as a single rectangle (fpdf's "1" shorthand).
	BorderFull Border = "1" // all four edges as a single rectangle stroke

	// BorderLeft strokes the left edge.
	BorderLeft Border = "L" // left edge
	// BorderTop strokes the top edge.
	BorderTop Border = "T" // top edge
	// BorderRight strokes the right edge.
	BorderRight Border = "R" // right edge
	// BorderBottom strokes the bottom edge.
	BorderBottom Border = "B" // bottom edge

	// BorderLeftTop strokes the left and top edges.
	BorderLeftTop Border = "LT" // left + top
	// BorderLeftRight strokes the left and right edges.
	BorderLeftRight Border = "LR" // left + right
	// BorderLeftBottom strokes the left and bottom edges.
	BorderLeftBottom Border = "LB" // left + bottom
	// BorderTopRight strokes the top and right edges.
	BorderTopRight Border = "TR" // top + right
	// BorderTopBottom strokes the top and bottom edges.
	BorderTopBottom Border = "TB" // top + bottom
	// BorderRightBottom strokes the right and bottom edges.
	BorderRightBottom Border = "RB" // right + bottom

	// BorderLeftTopRight strokes the left, top and right edges.
	BorderLeftTopRight Border = "LTR" // left + top + right
	// BorderLeftTopBottom strokes the left, top and bottom edges.
	BorderLeftTopBottom Border = "LTB" // left + top + bottom
	// BorderLeftRightBottom strokes the left, right and bottom edges.
	BorderLeftRightBottom Border = "LRB" // left + right + bottom
	// BorderTopRightBottom strokes the top, right and bottom edges.
	BorderTopRightBottom Border = "TRB" // top + right + bottom

	// BorderLeftTopRightBottom strokes all four edges as separate lines.
	BorderLeftTopRightBottom Border = "LTRB" // all four edges as separate lines
)

func (Border) EnumStrings

func (Border) EnumStrings() []string

EnumStrings returns all valid values for Border as strings

func (Border) Enums

func (Border) Enums() []Border

Enums returns all valid values for Border

func (Border) String

func (b Border) String() string

String implements the fmt.Stringer interface for Border

func (Border) Valid

func (b Border) Valid() bool

Valid indicates if b is any of the valid values for Border

func (Border) Validate

func (b Border) Validate() error

Validate returns an error if b is none of the valid values for Border

type Color

type Color struct {
	R, G, B int
}

Color is an 8-bit-per-channel RGB color, the form fpdf uses for the draw, fill and text colors. fpdf has no notion of alpha in colors; use the renderer's SetAlpha for transparency.

func Gray

func Gray(v int) Color

Gray builds a gray Color with the given 0–255 value on all three channels.

func Hex

func Hex(s string) (Color, error)

Hex parses a CSS-style hex color: "#rgb", "#rrggbb" or the same without the leading '#'. An invalid string returns black and a non-nil error, so callers that want strictness can check it; the State helpers ignore the error and fall back to black.

func MustHex

func MustHex(s string) Color

MustHex is Hex that panics on an invalid string, for use with constant literals.

func RGB

func RGB(r, g, b int) Color

RGB builds a Color from red, green and blue components in the range 0–255.

type Component

type Component interface {
	Render(ctx context.Context, r *Renderer) error
}

Component is the fundamental interface of the pdf package, mirroring the Component interface of the html package: everything that can draw onto a page implements Render. The Renderer replaces the markup writer used for HTML, but the shape — Render(context.Context, target) error — is identical, so the same composition patterns (Components, If, ForEach, …) apply.

func Cell

func Cell(w, h float64, text string) Component

Cell prints text in a single-line box of the given width and height and moves the cursor to its right. A width of 0 extends the cell to the right margin. For borders, alignment, fill or a different cursor move use CellFormat.

func CellFormat

func CellFormat(w, h float64, text string, border Border, ln LnPos, hAlign HAlign, vAlign VAlign, fill bool) Component

CellFormat prints text in a single-line box with full control over the border, post-cell cursor move, horizontal and vertical alignment and background fill, mirroring fpdf.CellFormat with typed parameters. A width of 0 extends to the right margin. fill paints the box with the current fill color before the text.

func Circle

func Circle(x, y, rad float64, op DrawOp) Component

Circle paints a circle of radius rad centered at (x, y).

func DefaultAsComponent

func DefaultAsComponent(c any) Component

DefaultAsComponent converts an arbitrary value into a Component, the PDF counterpart of mx.DefaultAsComponent. Children are accepted as ...any and converted at render-build time:

  • nil -> nil (renders nothing)
  • Component -> returned unchanged
  • string -> Text (flowing text)
  • the func signatures in the switch -> wrapped as ComponentFunc
  • error -> Text of error.Error()
  • fmt.Stringer -> Text of String()

Any other value falls back to Text(pretty.Sprint(c)) using github.com/domonda/go-pretty, mirroring the mx package: primitives get their plain textual form and any other value a compact, single-line representation where structs and pointers are tagged with their type name (for example "Item{Name:`x`;Count:3}" rather than fmt's anonymous "{x 3}") while slices and maps keep their literal form, with pointers dereferenced and the length bounded, which makes an unexpected value easy to spot. Unlike the markup packages there is no escaping step — a PDF is not markup, so a stringified value cannot inject anything; it is simply drawn as text. The flip side is the same as in mx: a value passed by mistake is silently drawn as text rather than causing a compile error, so convert non-obvious children to a Component explicitly.

DefaultAsComponent is the default implementation of the package-level AsComponent variable, which may be reassigned to customize this.

func DrawColor

func DrawColor(c Color) Component

DrawColor sets the color used to stroke lines and shape outlines.

func Ellipse

func Ellipse(x, y, rx, ry, degRotate float64, op DrawOp) Component

Ellipse paints an ellipse centered at (x, y) with horizontal radius rx and vertical radius ry, rotated degRotate degrees counter-clockwise.

func FillColor

func FillColor(c Color) Component

FillColor sets the color used to fill shapes and cell backgrounds.

func Font

func Font(family string, style FontStyle, size float64) Component

Font selects the font family, style and size for subsequent text. It is the stateful PDF analog of setting CSS font properties: the selection persists until changed. Wrap it in Save to scope it to a group of children.

func FontSize

func FontSize(size float64) Component

FontSize changes only the size of the current font, in points.

func Image

func Image(file string, x, y, w, h float64) Component

Image draws the image file scaled into the box at (x, y) of width w and height h. A zero w or h preserves the image's aspect ratio from the other dimension; both zero uses the image's natural size at 72 dpi. The format is inferred from the file extension. To draw an image held in memory, use ImageReader or ImageBytes.

func ImageBytes

func ImageBytes(name string, imageType ImageType, data []byte, x, y, w, h float64) Component

ImageBytes is ImageReader for an in-memory byte slice.

func ImageReader

func ImageReader(name string, imageType ImageType, src io.Reader, x, y, w, h float64) Component

ImageReader draws an image read from src into the box at (x, y) of width w and height h, without touching the filesystem. Sizing follows Image.

Because the source has no filename, name is used as fpdf's cache key: draw the same image again by passing the same name (the bytes are decoded only once), and give distinct images distinct names. imageType gives the encoding.

func Line

func Line(x1, y1, x2, y2 float64) Component

Line strokes a straight line from (x1, y1) to (x2, y2) using the current draw color and line width.

func LineCap

func LineCap(style LineCapStyle) Component

LineCap sets the shape drawn at the ends of open stroked paths.

func LineJoin

func LineJoin(style LineJoinStyle) Component

LineJoin sets the shape drawn where stroked path segments meet.

func LineWidth

func LineWidth(w float64) Component

LineWidth sets the stroke width in document units.

func Ln

func Ln(h float64) Component

Ln breaks to a new line, advancing the cursor down by h document units and back to the left margin. A value <= 0 uses the height of the last printed cell (fpdf's Ln(-1) behavior).

func MoveDown

func MoveDown(dy float64) Component

MoveDown moves the cursor down by dy document units, keeping x.

func MoveRight

func MoveRight(dx float64) Component

MoveRight moves the cursor right by dx document units, keeping y.

func MultiCell

func MultiCell(w, h float64, text string, border Border, hAlign HAlign, fill bool) Component

MultiCell prints word-wrapped text in a box of the given width, breaking into as many lines of height h as needed and advancing the cursor below the block, mirroring fpdf.MultiCell. A width of 0 wraps at the right margin. Only the horizontal alignment applies; vertical alignment is meaningless for flowing, multi-line text.

func NewLine

func NewLine() Component

NewLine breaks to a new line using the renderer's default line height.

func Page

func Page(children ...any) Component

Page starts a new page and renders children onto it. It is the structural unit of a document, loosely analogous to an html section: content is grouped per page and a new Page begins a fresh one. The very first Page (or the first drawing primitive) opens page one, so wrapping a one-page document in Page is optional.

func PageFormat

func PageFormat(orientation Orientation, size PageSize, children ...any) Component

PageFormat is Page with a per-page orientation and size override, for documents that mix, say, portrait and landscape pages.

func Paragraph

func Paragraph(text string) Component

Paragraph is the common-case shortcut for a block of wrapped, left-aligned body text: full content width, automatic line height, no border, no fill. It is the PDF analog of an html.P.

func Polygon

func Polygon(op DrawOp, points ...Point) Component

Polygon paints a closed polygon through the given points (at least three).

func Rect

func Rect(x, y, w, h float64, op DrawOp) Component

Rect paints a rectangle at (x, y) of width w and height h with the given paint operation (Stroke, FillShape or FillStroke).

func RoundedRect

func RoundedRect(x, y, w, h, radius float64, op DrawOp) Component

RoundedRect paints a rectangle with all four corners rounded to radius. Use the raw fpdf RoundedRectExt for per-corner radii.

func Save

func Save(children ...any) Component

Save renders children with the current graphics state restored afterwards, the PDF analog of wrapping content in an element so style changes inside do not leak out. It captures and restores the font (family, style and size), the text, fill and draw colors, the line width, the line cap and join styles, and the cursor position — using fpdf's getters, so it works regardless of whether the state was set through this package or the raw embedded renderer.

The dash pattern and the alpha/blend mode are not restored: fpdf exposes no getter for the dash pattern, and its zero alpha value is indistinguishable from a deliberate fully-transparent setting. Reset those explicitly if you change them inside a Save.

The cursor restore assumes children stay on the same page: if they trigger an automatic page break or add a page, the restored x, y lands on the new page, where later content can overprint. Save is meant for scoping style, not page flow. State setters and drawing primitives may be freely mixed as children, e.g. Save(TextColor(Red), Text("warning")).

func TextAt

func TextAt(x, y float64, text string) Component

TextAt prints text once at the absolute coordinate (x, y) without wrapping or advancing the cursor, mirroring fpdf.Text. Useful for labels and annotations placed by coordinate rather than by flow.

func TextColor

func TextColor(c Color) Component

TextColor sets the fill color used to paint text.

func X

func X(x float64) Component

X moves the cursor to the absolute horizontal position x, keeping y.

func XY

func XY(x, y float64) Component

XY moves the cursor to the absolute position (x, y).

func Y

func Y(y float64) Component

Y moves the cursor to the absolute vertical position y and resets x to the left margin (fpdf.SetY behavior).

type ComponentFunc

type ComponentFunc func(ctx context.Context, r *Renderer) error

ComponentFunc adapts a function to the Component interface.

func (ComponentFunc) Render

func (f ComponentFunc) Render(ctx context.Context, r *Renderer) error

Render calls the wrapped function.

type Components

type Components []Component

Components is an ordered list of components rendered one after another, the PDF counterpart of mx.Components. A nil element renders nothing.

func AsComponents

func AsComponents(cs ...any) Components

AsComponents converts a list of arbitrary values into Components using AsComponent, dropping nil results.

func ForEach

func ForEach[V any, C Component](values []V, componentForValue func(V) C) Components

ForEach builds a component for every value in a slice, mirroring mx.ForEach.

func ForEachIter

func ForEachIter[V any, C Component](values iter.Seq[V], componentForValue func(V) C) Components

ForEachIter is ForEach over an iterator sequence.

func (Components) Render

func (cs Components) Render(ctx context.Context, r *Renderer) error

Render draws each component in order, skipping nil elements, and stops at the first error.

type Document

type Document struct {
	// Metadata written to the PDF info dictionary.
	Title    string
	Author   string
	Subject  string
	Keywords string
	Creator  string

	// Page setup. Zero values default to A4 portrait in millimeters.
	Orientation Orientation
	Unit        Unit
	PageSize    PageSize

	// Margins overrides the page margins when non-nil; nil keeps fpdf defaults.
	Margins *Margins

	// Default font applied before the body. Zero values use Helvetica 12pt.
	FontFamily string
	FontStyle  FontStyle
	FontSize   float64

	// Header and Footer, if set, render at the top and bottom of every page.
	// They run inside fpdf's page lifecycle with the context passed to Render.
	Header Component
	Footer Component

	// Body holds the page content.
	Body Component
}

Document is the top-level PDF builder, the analog of html.Document. It holds document metadata, page setup, a default font and the body components, and can render into an existing Renderer or produce a finished PDF directly.

All zero-valued setup fields fall back to sensible defaults: A4 portrait in millimeters with a Helvetica 12pt font. The body is rendered after setup; it typically contains Page components, but any drawing primitive auto-starts the first page, so a single flow of text needs no explicit Page.

func NewDocument

func NewDocument(title string, body ...any) *Document

NewDocument creates a Document with the given title and body components.

func (*Document) Bytes

func (d *Document) Bytes(ctx context.Context) ([]byte, error)

Bytes renders the document and returns the encoded PDF.

func (*Document) NewRenderer

func (d *Document) NewRenderer() *Renderer

NewRenderer creates a Renderer configured from the document's page setup, applying the A4/portrait/millimeter defaults for any unset field.

func (*Document) Output

func (d *Document) Output(ctx context.Context, w io.Writer) error

Output renders the document to its own renderer and writes the PDF to w.

func (*Document) OutputFile

func (d *Document) OutputFile(ctx context.Context, filename string) error

OutputFile renders the document and writes the PDF to the named file.

func (*Document) Render

func (d *Document) Render(ctx context.Context, r *Renderer) error

Render applies the document's metadata, margins, default font and header/footer to r, then renders the body. The Document is itself a Component, so it can be embedded in a larger render.

func (*Document) ServeHTTP

func (d *Document) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP renders the document and serves it as application/pdf, using the request context for cancellation. On error it responds with a short, generic 500 message and does not leak the underlying error.

type DrawOp

type DrawOp string //#enum

DrawOp is the paint operation for vector shapes: stroke the outline, fill the interior, or both — the three canonical combinations of fill and stroke. fpdf also accepts the even-odd variants ("F*", "FD*") and raw PDF path operators, reachable through the embedded renderer for the rare cases that need them.

const (
	// Stroke strokes the shape outline with the draw color.
	Stroke DrawOp = "D" // stroke the outline with the draw color
	// FillShape fills the shape interior with the fill color.
	FillShape DrawOp = "F" // fill the interior with the fill color
	// FillStroke fills the interior and then strokes the outline.
	FillStroke DrawOp = "FD" // fill, then stroke
)

func (DrawOp) EnumStrings

func (DrawOp) EnumStrings() []string

EnumStrings returns all valid values for DrawOp as strings

func (DrawOp) Enums

func (DrawOp) Enums() []DrawOp

Enums returns all valid values for DrawOp

func (DrawOp) String

func (d DrawOp) String() string

String implements the fmt.Stringer interface for DrawOp

func (DrawOp) Valid

func (d DrawOp) Valid() bool

Valid indicates if d is any of the valid values for DrawOp

func (DrawOp) Validate

func (d DrawOp) Validate() error

Validate returns an error if d is none of the valid values for DrawOp

type FontStyle

type FontStyle string //#enum

FontStyle selects bold/italic/underline/strike-out. The four are independent fpdf flags (B, I, U, S); every combination is enumerated below in canonical B-I-U-S order, so the values serve both as a closed enum and as the result of concatenating the single-flag constants — StyleBold + StyleItalic equals StyleBoldItalic. Concatenate in B-I-U-S order to stay within the enumerated set. Bold and italic do not apply to the Symbol and ZapfDingbats families.

const (
	// StyleRegular is the unstyled (regular) font style.
	StyleRegular FontStyle = "" // regular
	// StyleBold is the bold (B) font style.
	StyleBold FontStyle = "B" // bold
	// StyleItalic is the italic (I) font style.
	StyleItalic FontStyle = "I" // italic
	// StyleUnderline is the underline (U) font style.
	StyleUnderline FontStyle = "U" // underline
	// StyleStrikeOut is the strike-out (S) font style.
	StyleStrikeOut FontStyle = "S" // strike-out

	// StyleBoldItalic combines the bold and italic styles (BI).
	StyleBoldItalic FontStyle = "BI" // bold + italic
	// StyleBoldUnderline combines the bold and underline styles (BU).
	StyleBoldUnderline FontStyle = "BU" // bold + underline
	// StyleBoldStrikeOut combines the bold and strike-out styles (BS).
	StyleBoldStrikeOut FontStyle = "BS" // bold + strike-out
	// StyleItalicUnderline combines the italic and underline styles (IU).
	StyleItalicUnderline FontStyle = "IU" // italic + underline
	// StyleItalicStrikeOut combines the italic and strike-out styles (IS).
	StyleItalicStrikeOut FontStyle = "IS" // italic + strike-out
	// StyleUnderlineStrikeOut combines the underline and strike-out styles (US).
	StyleUnderlineStrikeOut FontStyle = "US" // underline + strike-out

	// StyleBoldItalicUnderline combines the bold, italic and underline styles (BIU).
	StyleBoldItalicUnderline FontStyle = "BIU" // bold + italic + underline
	// StyleBoldItalicStrikeOut combines the bold, italic and strike-out styles (BIS).
	StyleBoldItalicStrikeOut FontStyle = "BIS" // bold + italic + strike-out
	// StyleBoldUnderlineStrikeOut combines the bold, underline and strike-out styles (BUS).
	StyleBoldUnderlineStrikeOut FontStyle = "BUS" // bold + underline + strike-out
	// StyleItalicUnderlineStrikeOut combines the italic, underline and strike-out styles (IUS).
	StyleItalicUnderlineStrikeOut FontStyle = "IUS" // italic + underline + strike-out

	// StyleBoldItalicUnderlineStrikeOut combines all four styles (BIUS).
	StyleBoldItalicUnderlineStrikeOut FontStyle = "BIUS" // all four
)

func (FontStyle) EnumStrings

func (FontStyle) EnumStrings() []string

EnumStrings returns all valid values for FontStyle as strings

func (FontStyle) Enums

func (FontStyle) Enums() []FontStyle

Enums returns all valid values for FontStyle

func (FontStyle) String

func (f FontStyle) String() string

String implements the fmt.Stringer interface for FontStyle

func (FontStyle) Valid

func (f FontStyle) Valid() bool

Valid indicates if f is any of the valid values for FontStyle

func (FontStyle) Validate

func (f FontStyle) Validate() error

Validate returns an error if f is none of the valid values for FontStyle

type HAlign

type HAlign string //#enum

HAlign is the horizontal text alignment inside a cell. Horizontal and vertical alignment are two independent single-choice axes rather than a flag set, so they are modelled as two enums (HAlign and VAlign) instead of one large combined enumeration. fpdf treats left as the default, so AlignLeft and the empty value render identically.

const (
	// AlignLeft aligns text to the left edge of the cell (fpdf default).
	AlignLeft HAlign = "L" // left (default)
	// AlignCenter centers text horizontally within the cell.
	AlignCenter HAlign = "C" // center
	// AlignRight aligns text to the right edge of the cell.
	AlignRight HAlign = "R" // right
	// AlignJustify justifies text to both edges of the cell (MultiCell only).
	AlignJustify HAlign = "J" // justified (MultiCell only)
)

func (HAlign) EnumStrings

func (HAlign) EnumStrings() []string

EnumStrings returns all valid values for HAlign as strings

func (HAlign) Enums

func (HAlign) Enums() []HAlign

Enums returns all valid values for HAlign

func (HAlign) String

func (h HAlign) String() string

String implements the fmt.Stringer interface for HAlign

func (HAlign) Valid

func (h HAlign) Valid() bool

Valid indicates if h is any of the valid values for HAlign

func (HAlign) Validate

func (h HAlign) Validate() error

Validate returns an error if h is none of the valid values for HAlign

type IfElse

type IfElse struct {
	// contains filtered or unexported fields
}

IfElse is a conditional component returned by If and Iff.

func If

func If(cond bool, comps ...Component) IfElse

If renders comps only when cond is true, mirroring mx.If. Use the returned IfElse's Else / ElseIf methods for the false branch.

func Iff

func Iff(condFunc func() bool, comps ...Component) IfElse

Iff is like If but takes the condition as a function, so the condition can be computed lazily at call time.

func (IfElse) Else

func (i IfElse) Else(comps ...Component) Components

Else returns the components to render when the condition was false.

func (IfElse) ElseIf

func (i IfElse) ElseIf(cond bool, comps ...Component) IfElse

ElseIf starts a new conditional branch when the previous condition was false.

func (IfElse) Render

func (i IfElse) Render(ctx context.Context, r *Renderer) error

Render draws the wrapped components when the condition is true and does nothing otherwise.

type ImageType

type ImageType string //#enum

ImageType identifies the encoding of an in-memory image passed to ImageReader / ImageBytes, where there is no filename to infer it from. fpdf supports these three raster formats only.

const (
	// ImagePNG is the PNG image encoding.
	ImagePNG ImageType = "png"
	// ImageJPEG is the JPEG image encoding.
	ImageJPEG ImageType = "jpg"
	// ImageGIF is the GIF image encoding.
	ImageGIF ImageType = "gif"
)

func (ImageType) EnumStrings

func (ImageType) EnumStrings() []string

EnumStrings returns all valid values for ImageType as strings

func (ImageType) Enums

func (ImageType) Enums() []ImageType

Enums returns all valid values for ImageType

func (ImageType) String

func (i ImageType) String() string

String implements the fmt.Stringer interface for ImageType

func (ImageType) Valid

func (i ImageType) Valid() bool

Valid indicates if i is any of the valid values for ImageType

func (ImageType) Validate

func (i ImageType) Validate() error

Validate returns an error if i is none of the valid values for ImageType

type LineCapStyle

type LineCapStyle string //#enum

LineCapStyle is the shape drawn at the ends of open paths.

const (
	// CapButt ends open paths flush at the endpoint with no extension.
	CapButt LineCapStyle = "butt"
	// CapRound ends open paths with a semicircular cap centered on the endpoint.
	CapRound LineCapStyle = "round"
	// CapSquare ends open paths with a square cap extending half the line width past the endpoint.
	CapSquare LineCapStyle = "square"
)

func (LineCapStyle) EnumStrings

func (LineCapStyle) EnumStrings() []string

EnumStrings returns all valid values for LineCapStyle as strings

func (LineCapStyle) Enums

func (LineCapStyle) Enums() []LineCapStyle

Enums returns all valid values for LineCapStyle

func (LineCapStyle) String

func (l LineCapStyle) String() string

String implements the fmt.Stringer interface for LineCapStyle

func (LineCapStyle) Valid

func (l LineCapStyle) Valid() bool

Valid indicates if l is any of the valid values for LineCapStyle

func (LineCapStyle) Validate

func (l LineCapStyle) Validate() error

Validate returns an error if l is none of the valid values for LineCapStyle

type LineJoinStyle

type LineJoinStyle string //#enum

LineJoinStyle is the shape drawn where path segments meet.

const (
	// JoinMiter joins segments with a sharp, extended corner.
	JoinMiter LineJoinStyle = "miter"
	// JoinRound joins segments with a rounded corner.
	JoinRound LineJoinStyle = "round"
	// JoinBevel joins segments with a flattened corner.
	JoinBevel LineJoinStyle = "bevel"
)

func (LineJoinStyle) EnumStrings

func (LineJoinStyle) EnumStrings() []string

EnumStrings returns all valid values for LineJoinStyle as strings

func (LineJoinStyle) Enums

func (LineJoinStyle) Enums() []LineJoinStyle

Enums returns all valid values for LineJoinStyle

func (LineJoinStyle) String

func (l LineJoinStyle) String() string

String implements the fmt.Stringer interface for LineJoinStyle

func (LineJoinStyle) Valid

func (l LineJoinStyle) Valid() bool

Valid indicates if l is any of the valid values for LineJoinStyle

func (LineJoinStyle) Validate

func (l LineJoinStyle) Validate() error

Validate returns an error if l is none of the valid values for LineJoinStyle

type LnPos

type LnPos int //#enum

LnPos selects where the cursor moves after a Cell, matching fpdf's ln argument.

const (
	// LnRight moves the cursor to the right of the cell (fpdf default).
	LnRight LnPos = 0 // to the right of the cell (default)
	// LnNewline moves the cursor to the start of the next line.
	LnNewline LnPos = 1 // to the start of the next line
	// LnBelow moves the cursor directly below the cell.
	LnBelow LnPos = 2 // directly below the cell
)

func (LnPos) EnumStrings

func (LnPos) EnumStrings() []string

EnumStrings returns all valid values for LnPos as strings

func (LnPos) Enums

func (LnPos) Enums() []LnPos

Enums returns all valid values for LnPos

func (LnPos) Valid

func (l LnPos) Valid() bool

Valid indicates if l is any of the valid values for LnPos

func (LnPos) Validate

func (l LnPos) Validate() error

Validate returns an error if l is none of the valid values for LnPos

type Margins

type Margins struct {
	Left, Top, Right float64
}

Margins are the left, top and right page margins in document units. fpdf derives the bottom margin (the auto page-break trigger) from the top margin.

type Orientation

type Orientation string //#enum

Orientation is a page orientation passed to the Renderer constructors and to the Page component. fpdf matches on the first letter, case-insensitively, so Portrait and Landscape are the only two distinct orientations.

const (
	// Portrait is the upright "portrait" page orientation (taller than wide).
	Portrait Orientation = fpdf.OrientationPortrait // "portrait"
	// Landscape is the sideways "landscape" page orientation (wider than tall).
	Landscape Orientation = fpdf.OrientationLandscape // "landscape"
)

func (Orientation) EnumStrings

func (Orientation) EnumStrings() []string

EnumStrings returns all valid values for Orientation as strings

func (Orientation) Enums

func (Orientation) Enums() []Orientation

Enums returns all valid values for Orientation

func (Orientation) String

func (o Orientation) String() string

String implements the fmt.Stringer interface for Orientation

func (Orientation) Valid

func (o Orientation) Valid() bool

Valid indicates if o is any of the valid values for Orientation

func (Orientation) Validate

func (o Orientation) Validate() error

Validate returns an error if o is none of the valid values for Orientation

type PageSize

type PageSize string //#enum

PageSize is a standard page size accepted by fpdf's string-based page setup. The constants below are all of them; fully custom dimensions go through the raw fpdf API (fpdf.NewCustom / AddPageFormat with a SizeType). fpdf lower-cases the value, so these upper-case forms and their lower-case spellings are equivalent.

const (
	// A1 is the ISO 216 A1 page size (594 × 841 mm).
	A1 PageSize = "A1" // 594 × 841 mm
	// A2 is the ISO 216 A2 page size (420 × 594 mm).
	A2 PageSize = "A2" // 420 × 594 mm
	// A3 is the ISO 216 A3 page size (297 × 420 mm).
	A3 PageSize = fpdf.PageSizeA3 // 297 × 420 mm
	// A4 is the ISO 216 A4 page size (210 × 297 mm).
	A4 PageSize = fpdf.PageSizeA4 // 210 × 297 mm
	// A5 is the ISO 216 A5 page size (148 × 210 mm).
	A5 PageSize = fpdf.PageSizeA5 // 148 × 210 mm
	// A6 is the ISO 216 A6 page size (105 × 148 mm).
	A6 PageSize = "A6" // 105 × 148 mm
	// A7 is the ISO 216 A7 page size (74 × 105 mm).
	A7 PageSize = "A7" // 74 × 105 mm
	// A8 is the ISO 216 A8 page size (52 × 74 mm).
	A8 PageSize = "A8" // 52 × 74 mm
	// Letter is the US Letter page size (8.5 × 11 in).
	Letter PageSize = fpdf.PageSizeLetter // 8.5 × 11 in
	// Legal is the US Legal page size (8.5 × 14 in).
	Legal PageSize = fpdf.PageSizeLegal // 8.5 × 14 in
	// Tabloid is the US Tabloid/Ledger page size (11 × 17 in).
	Tabloid PageSize = "Tabloid" // 11 × 17 in
)

func (PageSize) EnumStrings

func (PageSize) EnumStrings() []string

EnumStrings returns all valid values for PageSize as strings

func (PageSize) Enums

func (PageSize) Enums() []PageSize

Enums returns all valid values for PageSize

func (PageSize) String

func (p PageSize) String() string

String implements the fmt.Stringer interface for PageSize

func (PageSize) Valid

func (p PageSize) Valid() bool

Valid indicates if p is any of the valid values for PageSize

func (PageSize) Validate

func (p PageSize) Validate() error

Validate returns an error if p is none of the valid values for PageSize

type Point

type Point = fpdf.PointType

Point is a coordinate in document units, re-exported from fpdf so it can be passed straight to the embedded renderer's polygon and curve methods.

func Pt

func Pt(x, y float64) Point

Pt builds a Point from x and y coordinates.

type Renderer

type Renderer struct {
	*fpdf.Fpdf
	// contains filtered or unexported fields
}

Renderer is the PDF output target that components draw into.

It is the PDF counterpart of the markup writer used by the html package: where an html component writes tags into a markup writer, a pdf Component issues drawing calls against a Renderer. The embedded *fpdf.Fpdf is the actual renderer, so every fpdf method (Cell, Rect, Image, Transform, …) is available directly and components can always drop down to raw fpdf for anything the typed primitives do not cover.

fpdf is imperative and stateful: the current page, cursor position, font, and colors persist between calls. The primitives in this package are thin, composable wrappers around that state machine rather than a retained tree.

func NewRenderer

func NewRenderer(orientation Orientation, unit Unit, size PageSize) *Renderer

NewRenderer creates a Renderer for the given page orientation, measurement unit and page size, with a Helvetica 12pt default font already selected so text can be drawn without further setup.

func NewRendererA4Landscape

func NewRendererA4Landscape() *Renderer

NewRendererA4Landscape creates a Renderer for an A4 landscape document measured in millimeters.

func NewRendererA4Portrait

func NewRendererA4Portrait() *Renderer

NewRendererA4Portrait creates a Renderer for an A4 portrait document measured in millimeters.

func NewRendererLetterPortrait

func NewRendererLetterPortrait() *Renderer

NewRendererLetterPortrait creates a Renderer for a US Letter portrait document measured in inches.

func (*Renderer) LineHeight

func (r *Renderer) LineHeight() float64

LineHeight returns the default line height for flowing text in document units, resolving the "auto" zero value to 1.15× the current font size.

func (*Renderer) LoadUTF8FontBytes

func (r *Renderer) LoadUTF8FontBytes(family string, style FontStyle, ttf []byte)

LoadUTF8FontBytes registers a UTF-8 TrueType font from in-memory bytes under the given family and style — the in-memory counterpart of fpdf's file-based AddUTF8Font, so non-Latin text needs no font file on disk. It also switches the renderer's translator to identity, because UTF-8 fonts take UTF-8 strings directly and the cp1252 translation used for the core fonts would corrupt them; call SetTranslator if you later go back to a core font. Select the font afterwards with the Font component or SetFont.

func (*Renderer) LoadUTF8FontReader

func (r *Renderer) LoadUTF8FontReader(family string, style FontStyle, src io.Reader)

LoadUTF8FontReader is Renderer.LoadUTF8FontBytes reading the font from src. A read error is recorded on the renderer and surfaces from the next Error().

func (*Renderer) SetLineHeight

func (r *Renderer) SetLineHeight(h float64)

SetLineHeight sets the default line height in document units for flowing text. A value <= 0 restores automatic height derived from the font size.

func (*Renderer) SetTranslator

func (r *Renderer) SetTranslator(translate func(string) string)

SetTranslator replaces the UTF-8 translator, e.g. after switching to a font with a different code page. Pass the result of fpdf.UnicodeTranslatorFromDescriptor or the identity for UTF-8 fonts.

func (*Renderer) Str

func (r *Renderer) Str(s string) string

Str applies the current font's UTF-8 translation to s. The text primitives call this automatically; use it when passing strings to raw fpdf methods.

type Text

type Text string

Text is flowing text printed at the current cursor with automatic line wrapping at the right margin, the PDF counterpart of mx.Text and the type a bare string child is converted to. It uses the renderer's default line height and advances the cursor; embedded "\n" force line breaks.

func Textf

func Textf(format string, args ...any) Text

Textf is Text with fmt.Sprintf formatting, mirroring html.Textf.

func (Text) Render

func (t Text) Render(ctx context.Context, r *Renderer) error

Render draws the text at the current cursor, wrapping at the right margin and advancing the cursor.

type Unit

type Unit string //#enum

Unit is the document measurement unit. All coordinates, widths and heights passed to components are expressed in this unit; font sizes are always in points regardless of the document unit. These four are the only distinct units fpdf supports.

const (
	// UnitPoint is the typographic point unit ("pt", 1/72 inch).
	UnitPoint Unit = fpdf.UnitPoint // "pt"
	// UnitMillimeter is the millimeter unit ("mm").
	UnitMillimeter Unit = fpdf.UnitMillimeter // "mm"
	// UnitCentimeter is the centimeter unit ("cm").
	UnitCentimeter Unit = fpdf.UnitCentimeter // "cm"
	// UnitInch is the inch unit ("inch").
	UnitInch Unit = fpdf.UnitInch // "inch"
)

func (Unit) EnumStrings

func (Unit) EnumStrings() []string

EnumStrings returns all valid values for Unit as strings

func (Unit) Enums

func (Unit) Enums() []Unit

Enums returns all valid values for Unit

func (Unit) String

func (u Unit) String() string

String implements the fmt.Stringer interface for Unit

func (Unit) Valid

func (u Unit) Valid() bool

Valid indicates if u is any of the valid values for Unit

func (Unit) Validate

func (u Unit) Validate() error

Validate returns an error if u is none of the valid values for Unit

type VAlign

type VAlign string //#enum

VAlign is the vertical text alignment inside a cell. fpdf treats middle as the default, so AlignMiddle and the empty value render identically.

const (
	// AlignTop aligns text to the top edge of the cell.
	AlignTop VAlign = "T" // top
	// AlignMiddle centers text vertically within the cell (fpdf default).
	AlignMiddle VAlign = "M" // middle (default)
	// AlignBottom aligns text to the bottom edge of the cell.
	AlignBottom VAlign = "B" // bottom
	// AlignBaseline aligns text to the font baseline.
	AlignBaseline VAlign = "A" // baseline
)

func (VAlign) EnumStrings

func (VAlign) EnumStrings() []string

EnumStrings returns all valid values for VAlign as strings

func (VAlign) Enums

func (VAlign) Enums() []VAlign

Enums returns all valid values for VAlign

func (VAlign) String

func (v VAlign) String() string

String implements the fmt.Stringer interface for VAlign

func (VAlign) Valid

func (v VAlign) Valid() bool

Valid indicates if v is any of the valid values for VAlign

func (VAlign) Validate

func (v VAlign) Validate() error

Validate returns an error if v is none of the valid values for VAlign

Jump to

Keyboard shortcuts

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