1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "template": `<style>body{font-family:Helvetica,Arial,sans-serif;color:#1f2937;margin:0}h1{font-size:26px;margin:0;color:#0f2a4a}.top{display:flex;justify-content:space-between;border-bottom:3px solid #0f2a4a;padding-bottom:12px}.muted{color:#6b7280;font-size:12px}table{width:100%;border-collapse:collapse;margin-top:24px;font-size:13px}th{background:#0f2a4a;color:#fff;text-align:left;padding:8px}td{padding:8px;border-bottom:1px solid #e5e7eb}td.r,th.r{text-align:right}.tot{margin-top:16px;text-align:right;font-size:16px;font-weight:bold}</style>
12<div class="top"><div><h1>Invoice {{ number }}</h1><div class="muted">Issued {{ date }} - due {{ due }}</div></div><div style="text-align:right"><b>{{ seller }}</b><div class="muted">VAT {{ sellerVat }}</div></div></div>
13<p><b>Bill to:</b> {{ customer }}<br><span class="muted">{{ customerCity }}</span></p>
14<table><tr><th>Description</th><th class="r">Qty</th><th class="r">Unit</th><th class="r">Amount</th></tr>
15{% for l in lines %}<tr><td>{{ l.desc }}</td><td class="r">{{ l.qty }}</td><td class="r">{{ l.unit | money('EUR') }}</td><td class="r">{{ (l.qty * l.unit) | money('EUR') }}</td></tr>{% endfor %}</table>
16<div class="tot">Total excl. VAT: {{ total | money('EUR') }}</div>`,
17 "dataRows": [
18 {
19 "number": "2026-0141",
20 "date": "2026-11-02",
21 "due": "2026-12-02",
22 "seller": "Northwind Studio B.V.",
23 "sellerVat": "NL001234567B01",
24 "customer": "Lindqvist Outdoor AB",
25 "customerCity": "Gothenburg, Sweden",
26 "lines": [
27 {
28 "desc": "Product photography (half day)",
29 "qty": 1,
30 "unit": 640
31 },
32 {
33 "desc": "Retouching, per image",
34 "qty": 24,
35 "unit": 9.5
36 },
37 {
38 "desc": "Usage licence web, 12 months",
39 "qty": 1,
40 "unit": 180
41 }
42 ],
43 "total": 1048
44 },
45 {
46 "number": "2026-0142",
47 "date": "2026-11-05",
48 "due": "2026-12-05",
49 "seller": "Northwind Studio B.V.",
50 "sellerVat": "NL001234567B01",
51 "customer": "Café Moreau SARL",
52 "customerCity": "Lyon, France",
53 "lines": [
54 {
55 "desc": "Menu design, 2 pages",
56 "qty": 1,
57 "unit": 420
58 },
59 {
60 "desc": "Print-ready PDF export",
61 "qty": 2,
62 "unit": 35
63 }
64 ],
65 "total": 490
66 },
67 {
68 "number": "2026-0143",
69 "date": "2026-11-09",
70 "due": "2026-12-09",
71 "seller": "Northwind Studio B.V.",
72 "sellerVat": "NL001234567B01",
73 "customer": "Brauerei Hofmann GmbH",
74 "customerCity": "Bamberg, Germany",
75 "lines": [
76 {
77 "desc": "Label design, 3 variants",
78 "qty": 3,
79 "unit": 260
80 },
81 {
82 "desc": "Colour proof round",
83 "qty": 2,
84 "unit": 45
85 },
86 {
87 "desc": "Rush fee",
88 "qty": 1,
89 "unit": 120
90 }
91 ],
92 "total": 1020
93 }
94 ],
95 "footerTemplate": "<div style='font-size:9px;width:100%;text-align:center;color:#6b7280'>Page <span class='pageNumber'></span> of <span class='totalPages'></span></div>",
96 "fileNameTemplate": "invoice-{{ number }}",
97 "mergeIntoOne": true
98};
99
100
101const run = await client.actor("digivibetech/html-to-pdf").call(input);
102
103
104console.log('Results from dataset');
105console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
106const { items } = await client.dataset(run.defaultDatasetId).listItems();
107items.forEach((item) => {
108 console.dir(item);
109});
110
111