Skip to main content

Inject Data

This feature allows you to pass a serializable object to the reportToPdf function during the report building process, making the data available inside your report components.

script.ts
import { promises as fs } from 'fs';

const jsonData = await fs.readFile('my-json-data.json', 'utf-8');
await reportToPdf(page, '/', jsonData);
MyReportData.ts
interface MyReportData {
info: {
name: string;
lastName: string;
age: number;
};
}

const defaultData = {
info: { name: 'John', lastName: 'Doe', age: 44 },
};
<span data-pz-v-json-data-key="info.lastName"></span>

The element’s content will be replaced with the provided data after pagination is completed.