1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "urls": [
12 "https://example.com",
13 "https://en.wikipedia.org/wiki/PDF"
14 ],
15 "htmlItems": [
16 {
17 "name": "invoice-1001",
18 "html": "<!doctype html>\n<html><head><meta charset=\"utf-8\"><title>Invoice INV-1001</title>\n<style>\n body { font-family: Helvetica, Arial, sans-serif; color: #222; margin: 0; }\n .top { display: flex; justify-content: space-between; align-items: flex-start; }\n h1 { color: #1a56db; margin: 0 0 4px; }\n .muted { color: #666; font-size: 13px; }\n table { width: 100%; border-collapse: collapse; margin-top: 28px; }\n th { background: #1a56db; color: #fff; text-align: left; padding: 8px; }\n td { padding: 8px; border-bottom: 1px solid #ddd; }\n td.n, th.n { text-align: right; }\n .total { font-size: 18px; font-weight: bold; text-align: right; margin-top: 18px; }\n</style></head>\n<body>\n <div class=\"top\">\n <div><h1>INVOICE</h1><div class=\"muted\">INV-1001 · 2026-10-11</div></div>\n <div class=\"muted\" style=\"text-align:right\">Acme Studio Ltd.<br>12 Example Street<br>London, UK</div>\n </div>\n <p><b>Bill to:</b> Jane Doe, Example Corp</p>\n <table>\n <tr><th>Item</th><th class=\"n\">Qty</th><th class=\"n\">Price</th><th class=\"n\">Amount</th></tr>\n <tr><td>Website design</td><td class=\"n\">1</td><td class=\"n\">$1,200.00</td><td class=\"n\">$1,200.00</td></tr>\n <tr><td>Hosting (12 months)</td><td class=\"n\">12</td><td class=\"n\">$15.00</td><td class=\"n\">$180.00</td></tr>\n <tr><td>Support hours</td><td class=\"n\">5</td><td class=\"n\">$60.00</td><td class=\"n\">$300.00</td></tr>\n </table>\n <div class=\"total\">Total due: $1,680.00</div>\n <p class=\"muted\">Payment within 14 days. Thank you for your business!</p>\n</body></html>"
19 }
20 ],
21 "pageFormat": "A4",
22 "margins": {
23 "top": "10mm",
24 "right": "10mm",
25 "bottom": "10mm",
26 "left": "10mm"
27 },
28 "footerTemplate": "<div style=\"font-size:9px;width:100%;text-align:center;color:#666;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>",
29 "fileNameTemplate": "{index}-{name}"
30};
31
32
33const run = await client.actor("gazidev/html-to-pdf").call(input);
34
35
36console.log('Results from dataset');
37console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
38const { items } = await client.dataset(run.defaultDatasetId).listItems();
39items.forEach((item) => {
40 console.dir(item);
41});
42
43