Skip to main content

.image()

Adds an image.

ImageOptions

.image({
source: Buffer | string, // Buffer, URL, or file path
width?: number, // Width (pixels)
height?: number, // Height (pixels)
row?: number, // Row position (0-indexed)
col?: number, // Column position (0-indexed)
})
PropertyTypeDescription
sourceBuffer | stringImage data, URL, or file path (Node.js only)
widthnumberImage width (pixels)
heightnumberImage height (pixels)
rownumberRow to place (starting from 0)
colnumberColumn to place (starting from 0)

source

Using Buffer

import { readFileSync } from "fs";

const logoBuffer = readFileSync("./logo.png");

.image({
source: logoBuffer,
width: 150,
height: 75,
})

Using File Path (Node.js only)

.image({
source: "./logo.png",
width: 150,
height: 75,
})

Using URL (Browser & Node.js)

.image({
source: "https://example.com/logo.png",
width: 150,
height: 75,
})

Example

import { readFileSync } from "fs";

const logoBuffer = readFileSync("./logo.png");

const output = await xlmake()
.sheet("Report")
.text({ value: "Monthly Report", style: { bold: true, fontSize: 16 } })
.space(1)
.image({
source: logoBuffer,
width: 150,
height: 75,
})
.space(2)
.table({
preset: "basic",
columns: [...],
data: [...],
})
.getNode();