{"_id":"@chuongtrh/html-to-pdf","_rev":"3-eb58b25596cdc30936c756cfd1128048","name":"@chuongtrh/html-to-pdf","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@chuongtrh/html-to-pdf","version":"1.0.0","author":{"name":"chuongtrh"},"license":"MIT","_id":"@chuongtrh/html-to-pdf@1.0.0","maintainers":[{"name":"chuongtrh","email":"chuongtrh@gmail.com"}],"dist":{"shasum":"e19d8c9b089b9505190680d54135df495c5edc6d","tarball":"https://registry.npmjs.org/@chuongtrh/html-to-pdf/-/html-to-pdf-1.0.0.tgz","fileCount":8,"integrity":"sha512-qvmxaL7S5zb5xgBBwBu/sflbFMzwMFpsnWsL3dHDceRJOwkBawq58OMknW8ZJYiCeNJce19YQEh5ZSp30lFbuw==","signatures":[{"sig":"MEUCIBwd88bXUvxEP0MhCNtgtC79HDDvfHZMLRKnXxo/ysvYAiEAhoFQXlZQziqdj91l1nI8V+M6+ippDTk9NS0porJIngM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":585578,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJimNLMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoriRAAjnoJCaIzgSO0y7LYm5dFxQOX/KxKKON/2dFYSTuh/MwqoRCC\r\ny8l1Tf4lYNSPOmBnfnf7jRuWn+cdlu5Fmy03XCmuX0gOyCTK49rtZHLk+v6g\r\nu2lTvVUlPT+odAU2G6VKPBMOH+HAzab3EtVFBggc730AZOtkkGrK5tf29JES\r\n6Ojs5cpBYF/blnnEF6mvuEl0saJcvqNtPMoTfI2dcMxpbivEbLg305MiXICe\r\nqr/yOTCPs6qfQsXNWAYNdOSNn4hmENidn4JeRTEw4AhJuJIOa5ELr1edk4xP\r\nXwyo8x7PDl7/Z3IFhY8Kg1WLebAHVanrJEK1bttouYHxhLPFo19kG1ey7EPU\r\n2ZZoUYZ+GRVsOsoRwx63SbemwSZ+wAQto7ZahyzIEw7B9j37wM6t4M/UdgA4\r\nrfQw8YaGFr1TQYMpWKUtWBquW8EfF3Jb2KObY46xSp2iXoFI7KVJqxjlhyuS\r\nI7vn09aM/VsPW08KJxGpn13J2cLXeIOwuFDFXAqArkYIlDPPYb5safozlwwF\r\nm76kG8B336yw0TpGDzWXVffpfpAld7n8wzj0Jhcwgr5CmhTTx5SXEz1Z851i\r\ngkPKk9PHuS3w+cl4DImOqRsYwmQiQGBnx/aoQWomBJh8chTlq5FucpDCh4gX\r\nceVLesgYDVG1158xnosNaYdzJcieGVNUxWs=\r\n=hLXv\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"2d90d3221283f865c4d4ec144a90f0305cdfa6c7","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"chuongtrh","email":"chuongtrh@gmail.com"},"_npmVersion":"6.14.13","description":"Generate a simple PDF invoice from HTML using [puppeteer](https://github.com/GoogleChrome/puppeteer) & [handlebars](http://handlebarsjs.com/)","directories":{},"_nodeVersion":"14.17.1","dependencies":{"puppeteer":"^14.2.0","handlebars":"^4.7.7"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/html-to-pdf_1.0.0_1654182604581_0.0019115997590513079","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"@chuongtrh/html-to-pdf","version":"1.0.1","keywords":["puppeteer","pdf","handlebars","html_to_pdf","html_2_pdf"],"author":{"name":"chuongtrh"},"license":"MIT","_id":"@chuongtrh/html-to-pdf@1.0.1","maintainers":[{"name":"chuongtrh","email":"chuongtrh@gmail.com"}],"homepage":"https://github.com/chuongtrh/html_to_pdf#readme","bugs":{"url":"https://github.com/chuongtrh/html_to_pdf/issues"},"dist":{"shasum":"59b903a92c03faff6ffa746068439035e9ac7db1","tarball":"https://registry.npmjs.org/@chuongtrh/html-to-pdf/-/html-to-pdf-1.0.1.tgz","fileCount":8,"integrity":"sha512-6NFaSE+CoCKUpDA5oI30DyKX5fzhmOplLeJ1JV7qXK0WPQA4G1DrWR5/JYzD0P9rnzoRmYX1/kSAcUong5nmBw==","signatures":[{"sig":"MEUCIQDLJ26Zst+dJzPKfK8Llzmh1lfkAyT71ilKW2VKN+SexwIgUxCGs2xqbEWaQSDSSJ6W4RfGUQnboasYqNIHAffJN84=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":585797,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi3iBcACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp3IA//XVgjDVdh+Z0ypsQS0IEm335HIj7TLDIDk3pFwGhG9BOtqCwN\r\nItaJHhWYEgEmxkl4CXeIfcq8qQDJvOOcPAoImBmWZSqbtZLDJS+Ptl/XmUHy\r\nOXHFU+kZ5Wy9iv3Urs/4hR3t0m3pbj2ebT9zt2vDV+zX5CY2ENhGShGLgI2Z\r\n0oAA/TeciRqMu5AqZa6WCm4CuzI7FS/ns0yqJ4AVojI5iz/Mo2jgQ0lNhGos\r\nP6gCVKtj/U7P6PZb6Q79nLFTkZ8cx6uUtrRin8hie+ux3x7eDb0ZRVpAimOA\r\ntzzIgw92iDtkkXyVlLC6WY/Gl3hqEOQLJSAchNKCTp3PU/2XOAVeUSswEV2M\r\nRIbpVcXQivoKAOc2hvKzNbWOZXDo0Z2xoZvw5Rmv5e3cQP5AlslkpFge4bLY\r\nNVazl19Q+WjdlqrWcamlQ6a0Qd5jrnNPcGNSeTJhMxV53oV/AVOZKg+y2N6n\r\nKiqkJtXaa925jZBd9DYIVTJcao1AOkz6fzn2uLbHmTgCP+TaxlcGS6SWFYqo\r\nn7UPy4m997cwUFIgeZ+vfDBXx3hQcAyKIGzbOAX9FBum5fENqfwum2jx/NOI\r\niEXyRuKhfr6HLjZ1j+pUUgSrPrSg4Q8Up+ceJa+fWc6o6Jgo1q1CTMJA9kQb\r\nLgZmTt24K9UKS+klumyQoXaBzGzPsUQuqEY=\r\n=bMgn\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","gitHead":"70d225330255dd5c5ff28def3975ce1dfb986afc","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"chuongtrh","email":"chuongtrh@gmail.com"},"repository":{"url":"git+https://github.com/chuongtrh/html_to_pdf.git","type":"git"},"_npmVersion":"6.14.17","description":"Generate a simple invoice PDF from HTML using puppeteer & handlebars","directories":{},"_nodeVersion":"14.19.3","dependencies":{"puppeteer":"^14.2.0","handlebars":"^4.7.7"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/html-to-pdf_1.0.1_1658724444015_0.7860812493238314","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@chuongtrh/html-to-pdf","version":"1.0.2","description":"Generate a simple invoice PDF from HTML using puppeteer & handlebars","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"chuongtrh"},"license":"MIT","dependencies":{"handlebars":"^4.7.7","puppeteer":"^24.10.0"},"keywords":["puppeteer","pdf","handlebars","html_to_pdf","html_2_pdf"],"repository":{"type":"git","url":"git+https://github.com/chuongtrh/html_to_pdf.git"},"_id":"@chuongtrh/html-to-pdf@1.0.2","gitHead":"4321deecf0e1b20dbcd64d98347a8d9fe78a7262","bugs":{"url":"https://github.com/chuongtrh/html_to_pdf/issues"},"homepage":"https://github.com/chuongtrh/html_to_pdf#readme","_nodeVersion":"20.15.1","_npmVersion":"10.7.0","dist":{"integrity":"sha512-6oaZzKVZ0I8uRmFFOJH+avf30aVMJ2v1ooTXICM3QwDl1B35AmSofyN7SEoFcx/IxBTh6Bc4MzV1p30xNQHymg==","shasum":"58f3ac511e5dd721ee281044afd326c663377b71","tarball":"https://registry.npmjs.org/@chuongtrh/html-to-pdf/-/html-to-pdf-1.0.2.tgz","fileCount":9,"unpackedSize":593356,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBkI6fSrxNAtRjF7a2z+P3mnJvCbybji+swaHcrchxTvAiEA9FvSYe392bS5ECe1+OTzPuXAOgzrr06ofLuQfeikhBw="}]},"_npmUser":{"name":"chuongtrh","email":"chuongtrh@gmail.com"},"directories":{},"maintainers":[{"name":"chuongtrh","email":"chuongtrh@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/html-to-pdf_1.0.2_1749273191108_0.5873118253077185"},"_hasShrinkwrap":false}},"time":{"created":"2022-06-02T15:10:04.521Z","modified":"2025-06-07T05:13:11.601Z","1.0.0":"2022-06-02T15:10:04.787Z","1.0.1":"2022-07-25T04:47:24.211Z","1.0.2":"2025-06-07T05:13:11.436Z"},"bugs":{"url":"https://github.com/chuongtrh/html_to_pdf/issues"},"author":{"name":"chuongtrh"},"license":"MIT","homepage":"https://github.com/chuongtrh/html_to_pdf#readme","keywords":["puppeteer","pdf","handlebars","html_to_pdf","html_2_pdf"],"repository":{"type":"git","url":"git+https://github.com/chuongtrh/html_to_pdf.git"},"description":"Generate a simple invoice PDF from HTML using puppeteer & handlebars","maintainers":[{"name":"chuongtrh","email":"chuongtrh@gmail.com"}],"readme":"## html_to_pdf\n\nGenerate beautiful PDF invoices from HTML using [Puppeteer](https://github.com/GoogleChrome/puppeteer) & [Handlebars](http://handlebarsjs.com/).  \n**Modern, flexible, and easy to use!**\n\n![Invoice](https://raw.githubusercontent.com/chuongtrh/html_to_pdf/master/screenshot/invoice.png)\n\n---\n\n## ⭐ Features\n\n- **Modern rendering:** Uses real Chrome engine for pixel-perfect PDFs\n- **Dynamic templates:** Handlebars for easy data binding\n- **Watermark/stamp support:** Add \"PAID\" or custom stamps with a simple flag\n- **Full CSS/JS support:** Works with modern HTML, CSS, and JavaScript\n- **Easy integration:** Just a few lines of code to get started\n\n---\n\n## 🚀 Quick Start\n\n1. **Install dependencies**\n   ```sh\n   npm install\n   ```\n2. **Generate your first PDF**\n   ```sh\n   node example.js\n   ```\n   This will create `invoice.pdf` in your project folder.\n\n---\n\n## How It Works\n\n1. Prepare your HTML template (`invoice.html`)\n2. Bind your data using Handlebars\n3. Generate PDF with Puppeteer\n\n---\n\n## Example Usage\n\n**index.js**\n```js\nconst puppeteer = require(\"puppeteer\");\nconst handlebars = require(\"handlebars\");\n\nmodule.exports.html_to_pdf = async ({ templateHtml, dataBinding, options }) => {\n  const template = handlebars.compile(templateHtml);\n  const finalHtml = encodeURIComponent(template(dataBinding));\n\n  const browser = await puppeteer.launch({\n    args: [\"--no-sandbox\"],\n    headless: true,\n  });\n  const page = await browser.newPage();\n  await page.goto(`data:text/html;charset=UTF-8,${finalHtml}`, {\n    waitUntil: \"networkidle0\",\n  });\n  await page.pdf(options);\n  await browser.close();\n};\n```\n\n**example.js**\n```js\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst { html_to_pdf } = require(\".\");\n\n(async () => {\n  const dataBinding = {\n    items: [\n      { name: \"item 1\", price: 100 },\n      { name: \"item 2\", price: 200 },\n      { name: \"item 3\", price: 300 },\n    ],\n    total: 600,\n    isWatermark: true,\n  };\n\n  const templateHtml = fs.readFileSync(\n    path.join(process.cwd(), \"invoice.html\"),\n    \"utf8\"\n  );\n\n  const options = {\n    format: \"A4\",\n    headerTemplate: \"<p></p>\",\n    footerTemplate: \"<p></p>\",\n    displayHeaderFooter: false,\n    margin: { top: \"40px\", bottom: \"100px\" },\n    printBackground: true,\n    path: \"invoice.pdf\",\n  };\n\n  await html_to_pdf({ templateHtml, dataBinding, options });\n\n  console.log(\"Done: invoice.pdf is created!\");\n})();\n```\n\n---\n\n## 💡 Watermark/Stamp Example\n\nAdd a \"PAID\" stamp using Handlebars:\n\n```handlebars\n{{#if isWatermark}}\n  <div style=\"border-width: 6px; border-style: solid; border-color: #008000; border-radius: 8px; color: #008000; opacity:0.6; position: absolute; z-index: 1; left:40%; top:30%; font-size: 60pt; transform: rotate(-45deg); font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;\">\n    PAID\n  </div>\n{{/if}}\n```\nSet `isWatermark: true` in your data and run again!\n\n![Invoice with stamp paid watermark](https://raw.githubusercontent.com/chuongtrh/html_to_pdf/master/screenshot/invoice_paid.png)\n\n---\n\n## 🆚 Comparison: Puppeteer vs. wkhtmltopdf vs. dompdf\n\n| Feature                | Puppeteer (This Project) | wkhtmltopdf                | dompdf (PHP)              |\n|------------------------|-------------------------|----------------------------|---------------------------|\n| Language               | Node.js                 | Standalone (CLI, C++)      | PHP                       |\n| Rendering Engine       | Headless Chrome         | WebKit                     | PHP-based HTML parser     |\n| CSS/JS Support         | Full (modern browser)   | Limited (older WebKit)     | Limited (no JS)           |\n| JavaScript Execution   | Yes                     | Partial                    | No                        |\n| Template Engine        | Handlebars (JS)         | None (raw HTML)            | None (raw HTML)           |\n| Custom Fonts           | Yes                     | Yes                        | Yes                       |\n| Page Features          | Headers/Footers, Margins| Headers/Footers, Margins   | Basic                     |\n| Watermark/Stamp        | Easy (template logic)   | Possible (CSS/HTML)        | Possible (CSS/HTML)       |\n| Installation           | `npm install puppeteer` | Download binary            | Composer (PHP)            |\n| Platform               | Cross-platform          | Cross-platform             | Cross-platform            |\n| Output Format          | PDF                     | PDF                        | PDF                       |\n\n### Pros & Cons\n\n#### Puppeteer (This Project)\n**Pros:**\n- Accurate rendering (uses real Chrome engine)\n- Full support for modern CSS and JavaScript\n- Highly customizable with Node.js and Handlebars\n- Easy watermark/stamp logic\n- Active community and frequent updates\n\n**Cons:**\n- Requires Node.js environment\n- Larger binary size due to Chromium\n- Higher memory usage compared to simpler tools\n\n#### wkhtmltopdf\n**Pros:**\n- Simple CLI usage, easy to integrate in scripts\n- No programming language dependency\n- Good for static HTML to PDF conversion\n\n**Cons:**\n- Uses outdated WebKit engine (limited CSS/JS support)\n- JavaScript support is partial and sometimes buggy\n- Less accurate rendering for modern web pages\n\n#### dompdf\n**Pros:**\n- Native PHP solution, easy for PHP projects\n- Simple to install via Composer\n- Good for basic HTML/CSS to PDF\n\n**Cons:**\n- No JavaScript support\n- Limited CSS support (no flexbox, grid, etc.)\n- Rendering may differ from browsers\n\n**Summary:**  \nChoose **Puppeteer** if you need modern web features, dynamic templates, or advanced PDF customization. Use **wkhtmltopdf** for simple CLI-based workflows, or **dompdf** for basic PHP-based PDF generation.\n\n---\n\n## 🙌 Contributing\n\nPull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.\n\n---\n\n## 📣 Spread the Word\n\nIf you find this project useful, please ⭐ star the repo and share it with others!\n\n---\n\n## License\n\nhtml_to_pdf is available under the MIT license. See the LICENSE file for more info.\n","readmeFilename":"README.md"}