{"_id":"@benpley/wappler-html2pdf","_rev":"9-9820cc78ea49f6cb8b5c63d28460715c","name":"@benpley/wappler-html2pdf","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.2":{"name":"@benpley/wappler-html2pdf","version":"1.0.2","keywords":["wappler-extension","server-connect","module","pdf","html","node"],"author":{"name":"Ben Pleysier"},"license":"MIT","_id":"@benpley/wappler-html2pdf@1.0.2","maintainers":[{"name":"benpley","email":"ben@pleysier.com.au"}],"dist":{"shasum":"d17c275040b9f195c54a34571b3125bdf320abcc","tarball":"https://registry.npmjs.org/@benpley/wappler-html2pdf/-/wappler-html2pdf-1.0.2.tgz","fileCount":7,"integrity":"sha512-fMStk+gZbGgNsQoQSIgnw0wc4JiAugYEH1Jv45TvLN3SNdJLW4kZK8whApeSWjNdqVB9IRGORDWBsURcbHWugw==","signatures":[{"sig":"MEUCIHqVJX1FCd+Q/H9IZ8Nnz8r//xaveoaASdmJ4VHMGPIkAiEAzwQluyYIelZsdMlBGkFdWzJvwnTcEE26zvgP62SBMac=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20118},"_npmUser":{"name":"benpley","email":"ben@pleysier.com.au"},"_npmVersion":"10.9.3","description":"Convert HTML to PDF using headless Chrome in Wappler Server Connect","directories":{},"_nodeVersion":"22.19.0","dependencies":{"puppeteer":"^22.0.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wappler-html2pdf_1.0.2_1761526711233_0.04019400851247479","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@benpley/wappler-html2pdf","version":"1.0.3","keywords":["wappler-extension","server-connect","module","pdf","html","node"],"author":{"name":"Ben Pleysier"},"license":"MIT","_id":"@benpley/wappler-html2pdf@1.0.3","maintainers":[{"name":"benpley","email":"ben@pleysier.com.au"}],"dist":{"shasum":"d75143a310e62d021115d5d0ef8cad256b4dd056","tarball":"https://registry.npmjs.org/@benpley/wappler-html2pdf/-/wappler-html2pdf-1.0.3.tgz","fileCount":8,"integrity":"sha512-9qBer7tz2hjkqf9UBFyJ7C0MBJll+rNszAF3N0eP+Ak5nAOirFjHAHp0k7Ip2Yl3sEDkYFk4OZOeSMYtotsyfg==","signatures":[{"sig":"MEQCIAYAF3etMLHx7jvPyaM93leEJN2x27Ve5pusXzqdwXsEAiB4aQU8+2aTyUdS1jLFzFWS5rfCGSiVYhiIlNOQbiFhBg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20152},"_npmUser":{"name":"benpley","email":"ben@pleysier.com.au"},"_npmVersion":"10.9.3","description":"Convert HTML to PDF using headless Chrome in Wappler Server Connect","directories":{},"_nodeVersion":"22.19.0","dependencies":{"puppeteer":"^22.0.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wappler-html2pdf_1.0.3_1762164267675_0.9477884026709267","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@benpley/wappler-html2pdf","version":"1.0.4","keywords":["wappler-extension","server-connect","module","pdf","html","node"],"author":{"name":"Ben Pleysier"},"license":"MIT","_id":"@benpley/wappler-html2pdf@1.0.4","maintainers":[{"name":"benpley","email":"ben@pleysier.com.au"}],"dist":{"shasum":"b13f4df406045281ac705ca8f57ab7b88e96ad1a","tarball":"https://registry.npmjs.org/@benpley/wappler-html2pdf/-/wappler-html2pdf-1.0.4.tgz","fileCount":9,"integrity":"sha512-ZZKo3NjnhEbP7W5k6LliG8Xp0QrDlWRfqD78IHcMdC/KJQzkEgH4C/+CzDb7Anq3JvJDQZLd84VWfNzVokwnww==","signatures":[{"sig":"MEYCIQDPsTFrNR3A2bicTE7d2nYYhWzcKzh1RK1j98iQhl6i1AIhAKW7rs/1CwHV/0yVJ7NkZ4ieQQp+AeII+CYuL3yd7wQ+","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30936},"_npmUser":{"name":"benpley","email":"ben@pleysier.com.au"},"_npmVersion":"10.9.3","description":"Convert HTML to PDF using headless Chrome in Wappler Server Connect","directories":{},"_nodeVersion":"22.19.0","dependencies":{"puppeteer":"^22.0.0"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/wappler-html2pdf_1.0.4_1762473690659_0.19702706574144901","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@benpley/wappler-html2pdf","version":"2.0.0","description":"Convert HTML to PDF using Playwright Chromium in Wappler Server Connect","license":"MIT","author":{"name":"Ben Pleysier"},"keywords":["wappler-extension","server-connect","module","pdf","html","playwright","node"],"publishConfig":{"access":"public"},"scripts":{"postinstall":"playwright install --with-deps chromium"},"dependencies":{"playwright":"^1.45.0"},"_id":"@benpley/wappler-html2pdf@2.0.0","_nodeVersion":"22.19.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-woEqpKlU5Rl+c/osrLgST/e3vlDIcaxjLgVZxm4GssTBY5rAnik2T38weobEF/8Ee9YQq5eTDnCPV8U9WwJwtg==","shasum":"e004f58a6264eab898fa0c0640c376d8fb3004cb","tarball":"https://registry.npmjs.org/@benpley/wappler-html2pdf/-/wappler-html2pdf-2.0.0.tgz","fileCount":7,"unpackedSize":19024,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCuP8fVToVTWZEhqXnMPCFh21S7Vy136nfvGi/uGprrywIgFMU7axgvKNBGB+UiXCnHeo/zd6TD1oXTYObmpypsnAM="}]},"_npmUser":{"name":"benpley","email":"ben@pleysier.com.au"},"directories":{},"maintainers":[{"name":"benpley","email":"ben@pleysier.com.au"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/wappler-html2pdf_2.0.0_1783751537304_0.3953464681864598"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-27T00:58:31.179Z","modified":"2026-07-11T06:32:17.642Z","1.0.0":"2025-10-26T12:56:55.991Z","1.0.1":"2025-10-27T00:35:08.249Z","1.0.2":"2025-10-27T00:58:31.432Z","1.0.3":"2025-11-03T10:04:27.873Z","1.0.4":"2025-11-07T00:01:30.870Z","2.0.0":"2026-07-11T06:32:17.460Z"},"author":{"name":"Ben Pleysier"},"license":"MIT","keywords":["wappler-extension","server-connect","module","pdf","html","playwright","node"],"description":"Convert HTML to PDF using Playwright Chromium in Wappler Server Connect","maintainers":[{"name":"benpley","email":"ben@pleysier.com.au"}],"readme":"# HTML to PDF — Wappler Server Connect Module\n\n[![Version](https://img.shields.io/badge/version-2.0.0-blue.svg)](https://www.npmjs.com/package/@benpley/wappler-html2pdf)\n[![Playwright](https://img.shields.io/badge/engine-Playwright%20Chromium-green.svg)](https://playwright.dev)\n[![Wappler](https://img.shields.io/badge/Wappler-Extension-orange.svg)](https://wappler.io)\n[![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)\n\nThis Wappler Server Connect module converts HTML content into PDF files using **Playwright Chromium**.  \nIt is ideal for generating invoices, reports, onboarding documents, certificates, or any printable HTML content.\n\n---\n\n## Features\n\n- Convert any HTML string into a PDF file\n- Fully server‑side rendering using Playwright Chromium\n- Supports:\n  - Page formats (A4, Letter, Legal, etc.)\n  - Margins and scaling\n  - Landscape or portrait orientation\n  - Background graphics\n  - Header and footer HTML templates\n  - CSS `@page` support (via `preferCSSPageSize`)\n- Advanced rendering controls:\n  - Wait for a selector before generating\n  - Optional delay for dynamic content\n- Save PDFs to a custom path or temporary folder\n- Works seamlessly inside Wappler NodeJS projects\n\n---\n\n## 🚨 Important: Playwright Browser Install\n\nPlaywright does **not** bundle its browser binaries the same way Puppeteer does.\nAfter installing dependencies, the Chromium browser used for rendering must be downloaded:\n\n```bash\nnpx playwright install --with-deps chromium\n```\n\nA `postinstall` script running this command is included in `package.json`, but on some\nhosts (locked-down CI, limited permissions) you may need to run it manually.\n\n---\n\n## Installation\n\nInstall **Wappler HTML to PDF** using Wappler's built-in **Extension Manager**:\n\n1. Open Wappler and go to **Extensions → Extension Manager**.\n2. Search for **`wappler-html2pdf`** or browse the **Widgets** category.\n3. Click **Install** next to **Wappler HTML to PDF** by *Ben Pleysier*.\n4. Restart Wappler (or reload your project) when prompted.\n5. Ensure the Playwright Chromium browser is installed (see above), otherwise PDF\n   generation will fail with a \"browser executable not found\" error.\n\n---\n\n## Quick Example\n\nAdd the **HTML to PDF** action to a Server Connect action file with options like:\n\n```json\n{\n  \"html\": \"<h1>Invoice #{{$_GET.id}}</h1><p>Thank you for your purchase, {{$_GET.name}}!</p>\",\n  \"filename\": \"invoice_{{$_GET.id}}.pdf\",\n  \"path\": \"uploads/invoices/invoice_{{$_GET.id}}.pdf\",\n  \"format\": \"A4\",\n  \"landscape\": false,\n  \"printBackground\": true,\n  \"marginTop\": \"10mm\",\n  \"marginBottom\": \"10mm\"\n}\n```\n\nThe action returns:\n\n```json\n{\n  \"path\": \"/uploads/invoices/invoice_123.pdf\",\n  \"filename\": \"invoice_123.pdf\",\n  \"size\": 24531\n}\n```\n\nYou can then use `sc_action.data.path` (or the step's `output` name) on the client\nto show a download link, e.g. `<a dmx-bind:href=\"sc_action.data.path\" target=\"_blank\">Download PDF</a>`.\n\n---\n\n## Configuration Options\n\n### **HTML Content**\n- **html** *(required)* — The HTML string to convert into PDF.\n\n### **PDF Output**\n- **filename** — Output filename (default: `document.pdf`)\n- **path** — Optional save path (e.g., `uploads/pdfs/report.pdf`)\n\n### **Page Settings**\n- **format** — `A4`, `A3`, `A5`, `Letter`, `Legal`, `Tabloid`  \n- **landscape** — `true` or `false`\n- **printBackground** — Print background graphics (default: `true`)\n- **scale** — Rendering scale (`0.1` to `2`, default: `1`)\n\n### **Margins**\n- **marginTop**, **marginRight**, **marginBottom**, **marginLeft**  \n  Accepts units like `mm`, `cm`, or `in`.\n\n### **Header & Footer**\n- **displayHeaderFooter** — Enable header/footer rendering\n- **headerTemplate** — HTML template for header\n- **footerTemplate** — HTML template for footer  \n  *(Playwright requires full HTML fragments: `<html><body>...</body></html>`)*\n\n### **Advanced**\n- **preferCSSPageSize** — Use CSS-defined page size if present\n- **waitForSelector** — Wait for a specific element before generating\n- **waitTime** — Additional delay (ms) before PDF generation\n\nAll properties support static values or Wappler server data bindings.\n\n---\n\n## Dependency\n\nThis module uses **Playwright** (Chromium engine).\n\n---\n\n## Troubleshooting\n\n### \"browser executable not found\" / \"Executable doesn't exist\"\nPlaywright's Chromium binary is not installed. Run:\n```bash\nnpx playwright install --with-deps chromium\n```\nSee [Playwright Browser Install](#-important-playwright-browser-install) above.\n\n### PDF is generated but blank / missing content\n- The HTML is likely rendered before dynamic content (JS/images/fonts) finishes loading.\n- Use **waitForSelector** to wait for a specific element that indicates the content is ready.\n- Or use **waitTime** to add a fixed delay (in milliseconds) before the PDF is captured.\n\n### Background colors/images are missing\n- Ensure **printBackground** is set to `true` (default).\n- Some CSS backgrounds also require `-webkit-print-color-adjust: exact;` in your stylesheet.\n\n### Header/footer not showing\n- Make sure **displayHeaderFooter** is enabled.\n- **headerTemplate**/**footerTemplate** must be full HTML fragments (e.g. `<div style=\"font-size:10px;\">...</div>`), not just text.\n\n### Error: \"Failed to generate PDF: ...\" on shared hosting / containers\n- Chromium sandboxing can fail in restricted environments (Docker, some CI/CD, low-privilege containers).\n- The module already launches with `--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage --disable-gpu`, but you may also need to install missing system dependencies with `npx playwright install-deps` (Linux).\n\n### Custom `path` not saving where expected\n- Custom paths are relative to the **project root**, not `/public`. Directories are created automatically if missing.\n\n---\n\n## Issues and Support\nFor bug reports, feature requests, or assistance, please use the [Wappler Community Forum](https://community.wappler.io/).\n\nIf this module saves you time or makes your Wappler workflow easier, you can support me at [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-Support-orange)](https://buymeacoffee.com/Ben.Pleysier)\n\n\n---\n\nVersion 2.0.0 — now powered by Playwright (migrated from Puppeteer). Feedback welcome!\n","readmeFilename":"README.md"}