mirror of
https://github.com/pdfme/pdfme.git
synced 2026-04-17 12:38:57 -04:00
44 lines
939 B
JavaScript
44 lines
939 B
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { BLANK_PDF } from '@pdfme/common';
|
|
import { generate } from '@pdfme/generator';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const template = {
|
|
basePdf: BLANK_PDF,
|
|
schemas: [
|
|
[
|
|
{
|
|
name: 'a',
|
|
type: 'text',
|
|
position: { x: 0, y: 0 },
|
|
width: 10,
|
|
height: 10,
|
|
},
|
|
{
|
|
name: 'b',
|
|
type: 'text',
|
|
position: { x: 10, y: 10 },
|
|
width: 10,
|
|
height: 10,
|
|
},
|
|
{
|
|
name: 'c',
|
|
type: 'text',
|
|
position: { x: 20, y: 20 },
|
|
width: 10,
|
|
height: 10,
|
|
},
|
|
],
|
|
],
|
|
};
|
|
|
|
const inputs = [{ a: 'a1', b: 'b1', c: 'c1' }];
|
|
|
|
const pdf = await generate({ template, inputs });
|
|
console.log(pdf);
|
|
fs.writeFileSync(path.join(__dirname, 'test-generate.pdf'), pdf);
|