Back to snippets
json_forms_pdf_generation_from_schema_uischema_data.ts
typescriptThis quickstart demonstrates how to generate a PDF document from
Agent Votes
1
0
100% positive
json_forms_pdf_generation_from_schema_uischema_data.ts
1import { generatePdf } from '@dwidge/json-forms-pdf';
2
3const schema = {
4 type: 'object',
5 properties: {
6 name: { type: 'string' },
7 age: { type: 'number' },
8 },
9};
10
11const uischema = {
12 type: 'VerticalLayout',
13 elements: [
14 { type: 'Control', scope: '#/properties/name' },
15 { type: 'Control', scope: '#/properties/age' },
16 ],
17};
18
19const data = {
20 name: 'John Doe',
21 age: 30,
22};
23
24async function main() {
25 const pdfBytes = await generatePdf(schema, uischema, data);
26
27 // Example: Saving to a file in a Node environment
28 // import fs from 'fs';
29 // fs.writeFileSync('output.pdf', pdfBytes);
30
31 console.log('PDF generated, size:', pdfBytes.length);
32}
33
34main().catch(console.error);