Element Reference
Complete documentation of all element types, properties, and data binding syntax for the FPDF Generation API.
Contents
Common Properties
All elements share these common properties:
Element Structure
{
"type": "text|richtext|image|barcode|table|chart|box|circle|line|watermark",
"page": 1,
"bounds": {
"x": 10,
"y": 10,
"width": 100,
"height": 50,
"rotation": 0
},
// Element-specific properties...
} | Property | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Element type: text, richtext, image, barcode, table, chart, box, circle, line, or watermark |
page | number | No | Page number (1-indexed). Default: 1 |
bounds | object | Yes | Position and size of the element |
link | string | No | URL to make the element clickable. Supports {{placeholder}} for data binding. See Link Property. |
Bounding Box
All coordinates and dimensions are in millimeters (mm).
Property Type Required Description x number Yes X position from left edge (mm) y number Yes Y position from top edge (mm) width number Yes Element width (mm) height number Yes Element height (mm) rotation number No Rotation in degrees. Default: 0
Color Object
Colors are specified as RGB objects with values from 0-255.
{
"r": 255,
"g": 128,
"b": 0
}
Text Element
Render text with full control over font, alignment, wrapping, and overflow behavior.
Example
{
"type": "text",
"bounds": {"x": 10, "y": 10, "width": 100, "height": 20},
"text": {
"content": "Hello {{name}}!",
"fontFamily": "Arial",
"fontSize": 14,
"fontStyle": "B",
"color": {"r": 0, "g": 0, "b": 128},
"hAlign": "center",
"vAlign": "middle",
"lineHeight": 1.2,
"wrap": true,
"overflow": "ellipsis"
}
} Text Properties
| Property | Type | Required | Description |
|---|---|---|---|
content | string | Yes | Text content. Supports {{placeholder}} syntax for data binding. |
fontFamily | string | No | Font family. Built-in: Arial, Helvetica, Times, Courier. For UTF-8: DejaVuSans. Default: Arial |
fontSize | number | No | Font size in points. Default: 12 |
fontStyle | string | No | Font style: "" (regular), "B" (bold), "I" (italic), "BI" (bold italic) |
color | Color | No | Text color. Default: black {"r":0,"g":0,"b":0} |
hAlign | string | No | Horizontal alignment: "left", "center", "right". Default: "left" |
vAlign | string | No | Vertical alignment: "top", "middle", "bottom". Default: "top" |
lineHeight | number | No | Line height multiplier. Default: 1.2 |
wrap | boolean | No | Enable text wrapping within bounds. Default: true |
overflow | string | No | Overflow handling: "clip" (truncate), "ellipsis" (add ...), "visible" (show all). Default: "clip" |
Font Embedding Built-in fonts (Arial, Helvetica, Times, Courier) are not embedded, keeping PDF sizes small. Use DejaVuSans for UTF-8 characters (embedded automatically).
Rich Text Element
Render formatted text with inline HTML styling including bold, italic, underline, headings, and paragraph alignment. Supports multi-page overflow for long documents.
Example
{
"type": "richtext",
"bounds": {"x": 10, "y": 10, "width": 190, "height": 100},
"richText": {
"content": "<h1>Welcome</h1><p>Hello <b>{{name}}</b>!</p><p align=\"center\">This is <i>formatted</i> and <u>styled</u> text.</p>",
"fontFamily": "Arial",
"fontSize": 12,
"color": {"r": 0, "g": 0, "b": 0},
"lineHeight": 1.4,
"overflow": "clip"
}
}
Rich Text Properties
Property Type Required Description content string Yes HTML content with inline formatting. Supports {{placeholder}} for data binding. fontFamily string No Base font family. Default: "Arial" fontSize number No Base font size in points. Headings scale from this. Default: 12 color Color No Text color. Default: black {"r":0,"g":0,"b":0} lineHeight number No Line height multiplier. Default: 1.4 overflow string No Overflow handling: "clip" (truncate at bounds) or "flow" (continue to next page). Default: "clip"
Supported HTML Tags
Tag Description <b> or <strong> Bold text <i> or <em> Italic text <u> Underlined text <br> or <br/> Line break <p> Paragraph (supports align="left|center|right") <h1> to <h6> Headings with scaled font sizes (h1=2x, h2=1.5x, h3=1.17x, h4=1x, h5=0.83x, h6=0.67x)
Multi-Page Document Example
{
"type": "richtext",
"bounds": {"x": 10, "y": 10, "width": 190, "height": 277},
"richText": {
"content": "<h1>Document Title</h1><p>Long content that spans multiple pages...</p>",
"fontSize": 11,
"overflow": "flow"
}
}
When to Use Rich Text vs Text - Text Element - Simple text with uniform formatting (one font style, one color, one alignment)
- Rich Text Element - Mixed formatting within content (bold words, headings, different alignments per paragraph)
Nesting Tags Tags can be nested: <b><i>bold italic</i></b>. Data binding works inside tags: <b>{{name}}</b>
Image Element
Add images from URLs or base64-encoded data with fit modes and opacity control.
Example
{
"type": "image",
"bounds": {"x": 10, "y": 10, "width": 50, "height": 50},
"image": {
"src": "{{logoUrl}}",
"fitMode": "contain",
"opacity": 0.8,
"borderWidth": 1,
"borderColor": {"r": 200, "g": 200, "b": 200}
}
}
Image Properties
Property Type Required Description src string * Image URL. Supports {{placeholder}} for data binding. Required if data not provided. data string * Base64-encoded image data. Required if src not provided. fitMode string No How to fit image: "contain" (fit within), "cover" (fill, crop), "fill" (stretch), "none" (original size). Default: "contain" opacity number No Image opacity from 0 (transparent) to 1 (opaque). Default: 1 borderWidth number No Border width in mm. Default: 0 (no border) borderColor Color No Border color. Default: black
Fit Modes Explained - contain - Scale to fit within bounds, preserving aspect ratio
- cover - Scale to fill bounds, cropping excess
- fill - Stretch to exactly fill bounds (may distort)
- none - Use original image dimensions
Barcode Element
Generate 1D and 2D barcodes with customizable colors and optional text display.
Example
{
"type": "barcode",
"bounds": {"x": 10, "y": 10, "width": 60, "height": 25},
"barcode": {
"content": "{{sku}}",
"format": "Code128",
"showText": true,
"textPosition": "bottom",
"barColor": {"r": 0, "g": 0, "b": 0},
"backgroundColor": {"r": 255, "g": 255, "b": 255}
}
}
Barcode Properties
Property Type Required Description content string Yes Data to encode. Supports {{placeholder}} for data binding. format string Yes Barcode format (see supported formats below) showText boolean No Show human-readable text. Default: false textPosition string No Text position: "top" or "bottom". Default: "bottom" barColor Color No Bar/module color. Default: black backgroundColor Color No Background color. Default: white
Supported Barcode Formats
1D Barcodes
Code128 - Alphanumeric, variable length Code39 - Alphanumeric, uppercase only EAN13 - 13 digits (retail products) EAN8 - 8 digits (small products) UPC-A - 12 digits (US retail) UPC-E - 6 digits compressed ITF - Interleaved 2 of 5 Code93 - Full ASCII support
2D Barcodes
QR - QR Code (URLs, text) DataMatrix - High density 2D PDF417 - Stacked linear Aztec - Compact 2D
Table Element
Create data tables with headers, footers, dynamic rows, colspan, and multi-page support with repeated headers.
Basic Example
{
"type": "table",
"bounds": {"x": 10, "y": 25, "width": 190},
"table": {
"columns": [
{"width": 40, "align": "left"},
{"width": 80, "align": "left"},
{"width": 35, "align": "right"},
{"width": 35, "align": "right"}
],
"headerRows": [{
"cells": [
{"content": "SKU", "fontStyle": "B"},
{"content": "Product", "fontStyle": "B"},
{"content": "Qty", "fontStyle": "B"},
{"content": "Price", "fontStyle": "B"}
],
"backgroundColor": {"r": 230, "g": 230, "b": 230}
}],
"rows": [
{"cells": [{"content": "ABC001"}, {"content": "Widget Pro"}, {"content": "5"}, {"content": "$49.99"}]},
{"cells": [{"content": "ABC002"}, {"content": "Gadget Plus"}, {"content": "3"}, {"content": "$29.99"}]}
],
"cellPadding": 2,
"fontSize": 10,
"lineWidth": 0.3,
"lineColor": {"r": 180, "g": 180, "b": 180}
}
}
Dynamic Rows with DataSource
{
"type": "table",
"bounds": {"x": 10, "y": 25, "width": 190},
"table": {
"columns": [
{"width": 30, "align": "left"},
{"width": 90, "align": "left"},
{"width": 35, "align": "right"},
{"width": 35, "align": "right"}
],
"headerRows": [{
"cells": [
{"content": "Order #{{orderNumber}}", "colspan": 4, "align": "center", "fontStyle": "B"}
],
"backgroundColor": {"r": 70, "g": 130, "b": 180}
}],
"dataSource": "items",
"rowTemplate": {
"cells": [
{"content": "{{sku}}"},
{"content": "{{name}}"},
{"content": "{{qty}}"},
{"content": "${{price}}"}
]
},
"footerRows": [{
"cells": [
{"content": "Total:", "colspan": 3, "align": "right", "fontStyle": "B"},
{"content": "${{total}}", "fontStyle": "B"}
],
"backgroundColor": {"r": 240, "g": 240, "b": 220}
}],
"alternateRowColor": {"r": 248, "g": 248, "b": 255},
"repeatHeader": true
}
}
Table Properties
Property Type Required Description columns array Yes Column definitions with width (mm) and optional align ("left", "center", "right") headerRows array No Header rows (repeat on each page if repeatHeader is true) rows array No Static data rows footerRows array No Footer rows (rendered at end of table) dataSource string No Data array path for dynamic rows (e.g., "items") rowTemplate object No Row template for each dataSource item. Supports data binding. repeatHeader boolean No Repeat header rows on each page. Default: false cellPadding number No Cell padding in mm. Default: 2 fontSize number No Default font size. Default: 10 fontFamily string No Default font family. Default: "Arial" lineWidth number No Grid line width in mm. Default: 0.2 lineColor Color No Grid line color. Default: black alternateRowColor Color No Background color for alternating rows (zebra striping) headerBackground Color No Default background color for header rows
Cell Properties
Property Type Required Description content string Yes Cell content. Supports {{placeholder}} for data binding. colspan number No Number of columns to span. Default: 1 align string No Override horizontal alignment: "left", "center", "right" vAlign string No Vertical alignment: "top", "middle", "bottom" fontStyle string No Override font style: "", "B", "I", "BI" fontSize number No Override font size color Color No Override text color backgroundColor Color No Cell background color
Multi-Page Tables Tables automatically span multiple pages when content exceeds page height. Enable repeatHeader: true to repeat header rows on each page for better readability.
Box Element
Draw rectangles with optional fill, stroke, and rounded corners.
Example
{
"type": "box",
"bounds": {"x": 10, "y": 10, "width": 80, "height": 40},
"box": {
"fillColor": {"r": 240, "g": 240, "b": 245},
"strokeColor": {"r": 100, "g": 100, "b": 100},
"strokeWidth": 0.5,
"cornerRadius": 3
}
}
Box Properties
Property Type Required Description fillColor Color No Fill color. If omitted, no fill. strokeColor Color No Stroke/border color. Default: black strokeWidth number No Stroke width in mm. Default: 0.2 cornerRadius number No Corner radius in mm. Default: 0 (sharp corners)
Circle Element
Draw circles or ellipses with optional fill and stroke.
Example
{
"type": "circle",
"bounds": {"x": 10, "y": 10, "width": 30, "height": 30},
"circle": {
"fillColor": {"r": 255, "g": 200, "b": 100},
"strokeColor": {"r": 200, "g": 100, "b": 0},
"strokeWidth": 1
}
}
Circle Properties
Property Type Required Description fillColor Color No Fill color. If omitted, no fill. strokeColor Color No Stroke/border color. Default: black strokeWidth number No Stroke width in mm. Default: 0.2
Ellipses For ellipses, use different width and height values. For a perfect circle, use equal width and height.
Line Element
Draw straight lines between two points.
Example
{
"type": "line",
"bounds": {"x": 0, "y": 0, "width": 0, "height": 0},
"line": {
"x1": 10,
"y1": 50,
"x2": 200,
"y2": 50,
"strokeWidth": 0.5,
"strokeColor": {"r": 180, "g": 180, "b": 180}
}
}
Line Properties
Property Type Required Description x1 number Yes Start X position (mm) y1 number Yes Start Y position (mm) x2 number Yes End X position (mm) y2 number Yes End Y position (mm) strokeWidth number No Line width in mm. Default: 0.2 strokeColor Color No Line color. Default: black
Note Line elements use absolute coordinates from line properties, not the bounds. The bounds can be set to zeros.
Chart Element
Render bar, horizontal bar, line, and pie charts with support for multiple series, axis configuration, legends, and custom color palettes.
Bar Chart Example
{
"type": "chart",
"bounds": {"x": 10, "y": 20, "width": 180, "height": 100},
"chart": {
"chartType": "bar",
"title": "Monthly Revenue",
"data": [
{"label": "Jan", "value": 4200},
{"label": "Feb", "value": 5100},
{"label": "Mar", "value": 3800},
{"label": "Apr", "value": 6300}
],
"yAxis": {"gridLines": true, "labels": true},
"showValues": true,
"colors": [{"r": 54, "g": 162, "b": 235}]
}
}
Multi-Series Line Chart
{
"type": "chart",
"bounds": {"x": 10, "y": 20, "width": 180, "height": 100},
"chart": {
"chartType": "line",
"title": "Sales Comparison",
"series": [
{
"name": "2024",
"color": {"r": 54, "g": 162, "b": 235},
"data": [
{"label": "Q1", "value": 1200},
{"label": "Q2", "value": 1900},
{"label": "Q3", "value": 1500},
{"label": "Q4", "value": 2100}
]
},
{
"name": "2025",
"color": {"r": 255, "g": 99, "b": 132},
"data": [
{"label": "Q1", "value": 1400},
{"label": "Q2", "value": 2200},
{"label": "Q3", "value": 1800},
{"label": "Q4", "value": 2500}
]
}
],
"yAxis": {"gridLines": true},
"legend": {"show": true, "position": "bottom"},
"lineWidth": 1.5,
"pointRadius": 3
}
}
Pie Chart Example
{
"type": "chart",
"bounds": {"x": 50, "y": 20, "width": 100, "height": 100},
"chart": {
"chartType": "pie",
"title": "Market Share",
"data": [
{"label": "Product A", "value": 45, "color": {"r": 54, "g": 162, "b": 235}},
{"label": "Product B", "value": 30, "color": {"r": 255, "g": 99, "b": 132}},
{"label": "Product C", "value": 25, "color": {"r": 75, "g": 192, "b": 192}}
],
"showValues": true,
"legend": {"show": true, "position": "bottom"}
}
}
Chart Properties
Property Type Required Description chartType string Yes Chart type: "bar", "horizontalBar", "line", or "pie" title string No Chart title displayed above the chart. Supports data binding. data array * Array of data points for single-series charts. Each point has label, value, and optional color. Required if series not provided. series array * Array of data series for multi-series charts. Each series has name, color, and data array. Required if data not provided. xAxis object No X-axis configuration (see Axis Properties below) yAxis object No Y-axis configuration (see Axis Properties below) legend object No Legend configuration with show (boolean) and position ("top", "bottom", "left", "right"). Default position: "bottom" colors array No Color palette (array of Color objects) for auto-coloring series and data points. A default palette is used if not specified. fontFamily string No Font for labels and title. Default: "Arial" fontSize number No Font size for labels in points. Default: 8 barWidth number No Bar width ratio from 0 to 1 (bar/horizontalBar charts). Default: 0.7 showValues boolean No Show values on data points. Default: false lineWidth number No Line width for line charts in mm. Default: 1.5 pointRadius number No Point radius for line chart data points in mm. Default: 3 background Color No Chart background color. Default: transparent
Axis Properties
Property Type Required Description title string No Axis title text min number No Minimum axis value. Default: auto-calculated max number No Maximum axis value. Default: auto-calculated gridLines boolean No Show grid lines. Default: false labels boolean No Show axis labels. Default: true
Single vs Multi-Series Use data for simple single-series charts. Use series for multi-series charts where each series has its own name and color. Pie charts typically use data with per-point color.
Watermark Element
Add semi-transparent text watermarks for "DRAFT", "CONFIDENTIAL", etc.
Example
{
"type": "watermark",
"bounds": {"x": 0, "y": 100, "width": 210, "height": 50},
"watermark": {
"content": "DRAFT",
"fontFamily": "Arial",
"fontSize": 60,
"fontStyle": "B",
"color": {"r": 200, "g": 200, "b": 200},
"opacity": 0.15,
"rotation": -45
}
}
Watermark Properties
Property Type Required Description content string Yes Watermark text. Supports {{placeholder}} for data binding. fontFamily string No Font family. Default: "Arial" fontSize number No Font size in points. Default: 60 fontStyle string No Font style: "", "B", "I", "BI". Default: "" color Color No Text color before opacity. Default: light gray {"r":200,"g":200,"b":200} opacity number No Opacity from 0 to 1. Default: 0.15 rotation number No Rotation in degrees. Default: -45
Z-Order Elements render in order. Place watermarks after other content to overlay them, or before to place them behind.
Link Property
Make any element clickable by adding a link property with a URL. The entire element bounds become a clickable region in the PDF.
Example
{
"type": "text",
"bounds": {"x": 10, "y": 10, "width": 100, "height": 10},
"link": "https://example.com",
"text": {
"content": "Visit our website",
"color": {"r": 0, "g": 102, "b": 204}
}
}
Dynamic Link with Data Binding
{
"type": "image",
"bounds": {"x": 10, "y": 10, "width": 30, "height": 15},
"link": "{{companyUrl}}",
"image": {"src": "{{companyLogo}}", "fitMode": "contain"}
}
Universal Property The link property works on any element type (text, image, barcode, box, chart, etc.). The clickable area covers the full element bounds. Supports {{placeholder}} syntax for data binding.
Background Elements
Add elements that automatically render on every page, such as background images, watermarks, headers, footers, and page numbers.
Example
{
"page": {"format": "A4"},
"background": [
{
"type": "image",
"bounds": {"x": 0, "y": 0, "width": 210, "height": 297},
"image": {
"src": "https://example.com/bg-pattern.png",
"fitMode": "fill",
"opacity": 0.1
}
},
{
"type": "image",
"bounds": {"x": 10, "y": 10, "width": 30, "height": 15},
"image": {"src": "{{companyLogo}}", "fitMode": "contain"}
},
{
"type": "text",
"bounds": {"x": 10, "y": 280, "width": 190, "height": 10},
"text": {
"content": "Page {{page}} of {{totalPages}}",
"fontSize": 9,
"hAlign": "center",
"color": {"r": 128, "g": 128, "b": 128}
}
}
],
"elements": [
{"type": "text", "page": 1, "bounds": {...}, "text": {"content": "Page 1 content"}},
{"type": "text", "page": 2, "bounds": {...}, "text": {"content": "Page 2 content"}}
]
}
How It Works
The background array accepts the same element types as elements. Background elements:
- Render behind page content (drawn first on each page)
- Appear on every page automatically
- Support data binding including
{{page}} and {{totalPages}} - Images are deduplicated - the same image used on 100 pages is stored only once
Image Deduplication When the same image (same URL or base64 data) is used multiple times, it's stored only once in the PDF. A 100-page document with the same background image adds only ~1KB per page for the reference, not the full image each time.
Tip: Company Letterhead Use background to create reusable letterhead templates with logo, company info, and page numbers that appear consistently across all pages without repeating elements in your template.
Page Settings
Configure page format, orientation, and margins.
Example
{
"page": {
"format": "A4",
"orientation": "portrait",
"margins": {
"top": 10,
"bottom": 10,
"left": 15,
"right": 15
}
},
"elements": [...]
}
Page Properties
Property Type Required Description format string No Page format: "A4", "A3", "A5", "Letter", "Legal", or "custom". Default: "A4" width number * Page width in mm. Required if format is "custom". height number * Page height in mm. Required if format is "custom". orientation string No Page orientation: "portrait" or "landscape". Default: "portrait" margins object No Page margins with top, bottom, left, right in mm
Standard Page Sizes
Format Width (mm) Height (mm) A3297 420 A4210 297 A5148 210 Letter215.9 279.4 Legal215.9 355.6
Label Grid
Configure label sheets for printing multiple labels per page using the /render-labels endpoint.
Example
{
"page": {"format": "A4"},
"labelGrid": {
"labelWidth": 100,
"labelHeight": 50,
"columns": 2,
"rows": 5,
"columnGap": 5,
"rowGap": 5,
"startX": 5,
"startY": 10
},
"elements": [
// Elements positioned relative to each label's origin
{"type": "text", "bounds": {"x": 5, "y": 5, "width": 90, "height": 10},
"text": {"content": "{{productName}}"}}
]
}
Label Grid Properties
Property Type Required Description labelWidth number Yes Width of each label in mm labelHeight number Yes Height of each label in mm columns number Yes Number of label columns rows number Yes Number of label rows per page columnGap number No Gap between columns in mm. Default: 0 rowGap number No Gap between rows in mm. Default: 0 startX number No X offset of first label from page edge in mm. Default: 0 startY number No Y offset of first label from page edge in mm. Default: 0
Skip Positions Use skipPositions in the request to skip already-used label positions on partially used sheets. Positions are 0-indexed from top-left.
Data Binding
Use placeholders to inject dynamic data into text, image URLs, and barcode content.
Basic Syntax
Use double curly braces {{placeholder}} to avoid conflicts with single braces that may appear in content.
// Template
{"content": "Hello {{name}}!"}
// Request
{"data": {"name": "John"}}
// Result
"Hello John!"
Nested Data Access
// Template
{"content": "Ship to: {{customer.address.city}}"}
// Request
{
"data": {
"customer": {
"address": {
"city": "New York"
}
}
}
}
// Result
"Ship to: New York"
Array Access
// Template
{"content": "First item: {{items[0].name}}"}
// Request
{
"data": {
"items": [
{"name": "Widget A"},
{"name": "Widget B"}
]
}
}
// Result
"First item: Widget A"
Special Variables
These variables are available without needing to pass them in data:
Variable Description {{page}} Current page number (1-indexed) {{totalPages}} Total number of pages in the document
Example: Page Footer
{
"type": "text",
"page": 1,
"bounds": {"x": 10, "y": 280, "width": 190, "height": 10},
"text": {
"content": "Page {{page}} of {{totalPages}}",
"hAlign": "center",
"fontSize": 10,
"color": {"r": 128, "g": 128, "b": 128}
}
}
Missing Data If a placeholder references missing data, it remains as-is in the output (e.g., {{missingField}}). Ensure your data includes all referenced fields.