Skip to main content

Image Elements

This page shows how to use the image element in json2doc.

Image Properties & Defaults

Image Element Properties

PropertyTypeRequiredDescriptionDefault
typestringElement type: image-
srcstringImage source: storage URL starting with /image/ or public HTTP/HTTPS URL-
altstringAlternative text for accessibility (max 200 characters)-
widthnumberImage width in pixels (10-2000)Auto (from image)
heightnumberImage height in pixels (10-2000)Auto (from image)
alignstringImage alignment: left, center, rightleft
spacingobjectCustom spacing override (before / after in pt)From defaults.spacing.image

Image Defaults (defaults)

For images, only the spacing defaults under defaults.spacing are applied. Other global defaults do not affect image rendering.

note

Document-level defaults for other image properties (such as width, height or align) are currently not supported. These values must be set on each individual image element if needed.

Nested Default Properties (dot notation)

PropertyTypeDescription
defaults.spacing.before.imagenumberSpacing before image elements in pt (0-100, default: 10)
defaults.spacing.after.imagenumberSpacing after image elements in pt (0-100, default: 15)

Defaults Example

{
"document": {
"type": "pdf",
"filename": "image-defaults-example"
},
"defaults": {
"spacing": {
"before": {
"image": 12
},
"after": {
"image": 18
}
}
},
"sections": []
}

Image Examples

Image Example JSON
{
"document": {
"type": "pdf",
"filename": "image-elements-example"
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "h1",
"text": "Image Elements Example"
},
{
"type": "text",
"text": "Left aligned image with custom spacing:"
},
{
"type": "image",
"src": "https://fastly.picsum.photos/id/831/1600/900.jpg?hmac=gIi_21iE10nYnQETpI_xB8_CP_hYqPtJol_lj_zY0k4",
"alt": "Sample landscape image",
"width": 200,
"align": "left",
"spacing": {
"before": 10,
"after": 20
}
},
{
"type": "text",
"text": "Center aligned image with medium size:"
},
{
"type": "image",
"src": "https://fastly.picsum.photos/id/831/1600/900.jpg?hmac=gIi_21iE10nYnQETpI_xB8_CP_hYqPtJol_lj_zY0k4",
"alt": "Sample landscape image (center)",
"width": 300,
"align": "center"
},
{
"type": "text",
"text": "Right aligned image with larger width:"
},
{
"type": "image",
"src": "https://fastly.picsum.photos/id/831/1600/900.jpg?hmac=gIi_21iE10nYnQETpI_xB8_CP_hYqPtJol_lj_zY0k4",
"alt": "Sample landscape image (right)",
"width": 400,
"align": "right",
"spacing": {
"before": 15,
"after": 25
}
}
]
}
]
}