1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "template": `<!doctype html>
12<html>
13<head>
14<meta charset="utf-8">
15<title>Invoice {{number}}</title>
16<style>
17 body { font-size: 11pt; color: #102a43; }
18 .top { display: flex; justify-content: space-between; align-items: flex-start; }
19 h1 { margin: 0; font-size: 22pt; }
20 .ar { font-family: 'Noto Sans Arabic', sans-serif; direction: rtl; }
21 table { width: 100%; border-collapse: collapse; margin-top: 18px; }
22 th, td { border-bottom: 1px solid #d9e2ec; padding: 8px; text-align: start; }
23 th { background: #f0f4f8; }
24 .num { text-align: end; }
25 .total td { font-weight: bold; border-top: 2px solid #102a43; }
26</style>
27</head>
28<body>
29 <div class="top">
30 <div>
31 <h1>Invoice</h1>
32 <div>No. {{number}}</div>
33 <div>Date: {{formatDate date style="long"}}</div>
34 </div>
35 <div class="ar">
36 <h1>فاتورة</h1>
37 <div>رقم {{number}}</div>
38 <div>التاريخ: {{formatDate date style="long" locale="ar-SA-u-ca-gregory"}}</div>
39 </div>
40 </div>
41 <p><strong>Bill to:</strong> {{customer}}</p>
42 <table>
43 <thead><tr><th>Item</th><th class="num">Qty</th><th class="num">Unit price</th><th class="num">Amount</th></tr></thead>
44 <tbody>
45 {{#each items}}
46 <tr><td>{{name}}</td><td class="num">{{qty}}</td><td class="num">{{formatCurrency price ../currency}}</td><td class="num">{{formatCurrency (multiply qty price) ../currency}}</td></tr>
47 {{/each}}
48 <tr class="total"><td colspan="3">Total / الإجمالي</td><td class="num">{{formatCurrency (sum items "qty" "price") currency}}</td></tr>
49 </tbody>
50 </table>
51</body>
52</html>`,
53 "data": [
54 {
55 "number": "INV-1001",
56 "date": "2026-10-01",
57 "customer": "Example Trading LLC",
58 "currency": "USD",
59 "items": [
60 {
61 "name": "Design work",
62 "qty": 10,
63 "price": 45
64 },
65 {
66 "name": "Hosting, 12 months",
67 "qty": 1,
68 "price": 120
69 }
70 ]
71 },
72 {
73 "number": "INV-1002",
74 "date": "2026-10-08",
75 "customer": "Sample Studio",
76 "currency": "EUR",
77 "items": [
78 {
79 "name": "Consulting hours",
80 "qty": 6,
81 "price": 80
82 },
83 {
84 "name": "Travel",
85 "qty": 1,
86 "price": 95.5
87 }
88 ]
89 },
90 {
91 "number": "INV-1003",
92 "date": "2026-10-15",
93 "customer": "Demo Supplies Co.",
94 "currency": "SAR",
95 "items": [
96 {
97 "name": "Printed brochures",
98 "qty": 500,
99 "price": 1.2
100 },
101 {
102 "name": "Delivery",
103 "qty": 1,
104 "price": 60
105 }
106 ]
107 }
108 ],
109 "fileName": "invoice-{{number}}",
110 "maxPdfs": 100
111};
112
113
114const run = await client.actor("maliksaid/html-to-pdf").call(input);
115
116
117console.log('Results from dataset');
118console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
119const { items } = await client.dataset(run.defaultDatasetId).listItems();
120items.forEach((item) => {
121 console.dir(item);
122});
123
124