Text Elements
This page shows how to use text-based elements (h1-h6, text, text2) in json2doc.
note
All text elements support Markdown formatting for rich text styling. You can use bold, italic, underline, highlight, and hyperlinks in any text content including headings, paragraphs, list items, table cells, and captions.
Supported Formatting:
- Bold text:
**text**→ text - Italic text:
*text*→ text - Underlined text:
__text__→ text - ==Highlighted text==:
==text==→ ==text== - Hyperlinks:
[text](url)→ text - Bold links:
[**text**](url)→ text - Italic links:
[*text*](url)→ text
text2 is a smaller text variant, typically used for captions, footnotes, or supplementary information.
Text Element Properties & Defaults
Text & Heading Element Properties
| Property | Type | Required | Description | Default |
|---|---|---|---|---|
type | string | ✓ | Element type: h1, h2, h3, h4, h5, h6, text, or text2 | - |
text | string | ✓ | Text content (supports markdown, up to 5000 characters) | - |
fontFamily | string | ✗ | Font family override (1-100 chars) | From defaults / styles |
fontSize | number | ✗ | Font size in points (6-72) | From defaults / styles |
fontWeight | string | ✗ | Font weight: normal or bold | From defaults / styles |
align | string | ✗ | Text alignment: left, center, right, justify | From defaults / styles |
color | string | ✗ | Text color in hex format | From defaults / styles |
spacing | object | ✗ | Custom spacing override (before / after in pt) | From defaults.spacing |
Text & Heading Defaults (defaults)
Global defaults control typography, spacing and per-element styles. They are defined under defaults on the document root.
Nested Default Properties (dot notation)
| Property | Type | Description |
|---|---|---|
defaults.fontFamily | string | Global default font family (default: "Arial") |
defaults.fontSize | number | Global default font size in pt (6-72, default: 11) |
defaults.color | string | Global text color in hex (default: #000000) |
defaults.lineHeight | number | Global line height multiplier (0.5-3.0, default: 1.5) |
defaults.spacing.before.h1-h6 | number | Spacing before each heading level in pt (0-100, defaults as in schema) |
defaults.spacing.before.text / text2 | number | Spacing before text elements in pt (0-100) |
defaults.spacing.after.h1-h6 | number | Spacing after each heading level in pt (0-100) |
defaults.spacing.after.text / text2 | number | Spacing after text elements in pt (0-100) |
defaults.styles.h1-h6 | object | Optional text style overrides for heading levels (uses textStyle schema) |
defaults.styles.text2 | object | Optional style override for text2, e.g. smaller font for captions |
Defaults Example
{
"document": {
"type": "pdf",
"filename": "text-defaults-example"
},
"defaults": {
"fontFamily": "Inter",
"fontSize": 11,
"color": "#111827",
"lineHeight": 1.5,
"spacing": {
"before": {
"h1": 24,
"h2": 20,
// same for h3-h6
"text": 0,
"text2": 0,
},
"after": {
"h1": 16,
"h2": 14,
// same for h3-h6
"text": 10,
"text2": 8,
}
},
"styles": {
"h1": {
"fontSize": 28,
"fontWeight": "bold",
"color": "#111827",
"align": "center"
},
"h2": {
"fontSize": 22,
"fontWeight": "bold",
"color": "#111827"
},
"text2": {
"fontSize": 9,
"color": "#6b7280",
"align": "left"
}
}
},
"sections": []
}
Heading Examples
Headings JSON
{
"document": {
"type": "pdf",
"filename": "text-headings-example"
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "h1",
"text": "Main Document Title (h1)",
"align": "center",
"color": "#0066cc",
"fontSize": 32
},
{
"type": "h2",
"text": "Chapter Heading with **Bold** Text (h2)",
"fontSize": 24
},
{
"type": "h3",
"text": "Section Heading (h3)",
"fontFamily": "Times New Roman",
"fontSize": 18
},
{
"type": "h4",
"text": "Subsection with Custom Spacing (h4)",
"fontSize": 16,
"spacing": {
"before": 20,
"after": 10
}
},
{
"type": "h5",
"text": "Minor Heading (h5)",
"fontSize": 14
},
{
"type": "h6",
"text": "Smallest Heading Level (h6)",
"fontSize": 12
}
]
}
]
}
Text Examples
Text JSON
{
"document": {
"type": "pdf",
"filename": "text-body-example"
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "text",
"text": "Regular paragraph text with **bold**, *italic*, and ***bold italic*** formatting. You can also include [hyperlinks](https://example.com) in your text."
},
{
"type": "text",
"text": "This paragraph demonstrates justified alignment for a professional appearance.",
"align": "justify"
},
{
"type": "text",
"text": "Centered text with custom color and Bold",
"align": "center",
"color": "#0066cc",
"fontWeight": "bold"
},
{
"type": "text",
"text": "Text with custom spacing and font",
"fontFamily": "Times New Roman",
"spacing": {
"before": 20,
"after": 15
}
},
{
"type": "text2",
"text": "This is text2 style - smaller and typically used for captions or footnotes"
}
]
}
]
}