[//]: #@corifeus-header [![NPM](https://img.shields.io/npm/v/p3x-html-pdf.svg)](https://www.npmjs.com/package/p3x-html-pdf) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://paypal.me/patrikx3) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Corifeus @ Facebook](https://img.shields.io/badge/Facebook-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) [![Uptime Robot ratio (30 days)](https://img.shields.io/uptimerobot/ratio/m780749701-41bcade28c1ea8154eda7cca.svg)](https://stats.uptimerobot.com/9ggnzcWrw) # πŸ“ƒ Generates PDF from HTML with custom headers and footers with wkhtmltopdf v2025.4.116 🌌 **Bugs are evidentβ„’ - MATRIX️** 🚧 **This project is under active development!** πŸ“’ **We welcome your feedback and contributions.** ### NodeJS LTS is supported ### πŸ› οΈ Built on NodeJs version ```txt v22.13.0 ``` # πŸ“ Description [//]: #@corifeus-header:end `p3x-html-pdf` is a Node.js package that generates PDFs from HTML with custom headers and footers using `wkhtmltopdf`. It is a robust tool for creating professional-grade PDFs with features like: - πŸ“œ **Dynamic Headers and Footers**: Add placeholders for page numbers, dates, and more. - πŸ› οΈ **Customizable Layouts**: Configure margins, orientation, and paper size. - ⚑ **Async/Await Support**: Modern JavaScript compatibility for efficient workflows. - πŸ”„ **Dynamic Content**: Render data-driven tables and content dynamically. ## πŸš€ Installation Install via Yarn: ```bash yarn add p3x-html-pdf ``` Import in your project: ```javascript const { generate } = require('p3x-html-pdf'); ``` ## πŸ› οΈ Features - πŸ“œ **Custom Headers and Footers** - πŸ“ **Flexible Page Settings** - ⚑ **Async/Await Support** - πŸ“Š **Dynamic Tables and Content** ## πŸ“– Usage Example ```javascript const { generate } = require('p3x-html-pdf'); const path = require('path'); (async () => { const options = { settings: { save: true, template: { format: 'A4', orientation: 'portrait', marginLeft: 10, marginRight: 10, }, html: `

Header Content

Content

This is a test PDF document.

Header 1 Header 2 Header 3
Data 1 Data 2 Data 3
Data 4 Data 5 Data 6
`, }, title: 'Sample PDF', saveFile: path.resolve(__dirname, 'output.pdf'), }; try { await generate(options); console.log('βœ… PDF generated successfully!'); } catch (err) { console.error('❌ Error generating PDF:', err); } })(); ``` ## πŸ”§ Configuration ### Options - **Settings** - `save`: If false, it returns as a buffer. - `template.format`: Page size, e.g., `A4`, `Letter`. - `template.orientation`: Page orientation (`portrait` or `landscape`). - `template.marginLeft`, `template.marginRight`: Margins in mm. - `html`: HTML content with placeholders. - **title**: PDF document title. - **saveFile**: Path for saving the PDF. ### Placeholders - `${page}`: Current page. - `${pages}`: Total pages. - `${date}`: Current date. - `${isodate}`: ISO date format. - `${time}`: Current time. ## πŸ“Š Advanced Features - **Debugging**: Use `debug: true` to enable detailed logs. - **Header/Footer Templates**: Define rich HTML templates for headers/footers. ## 🀝 Contributing Contributions are welcome! Feel free to submit issues or pull requests on [GitHub](https://github.com/patrikx3/html-pdf). ## πŸ“œ License This project is licensed under the [MIT License](https://github.com/patrikx3/html-pdf/blob/master/LICENSE). --- For detailed documentation, visit the [npm page](https://www.npmjs.com/package/p3x-html-pdf). --- ARM64 Support: If os.arch() === 'arm64', it automatically sets the wkhtmltopdf path to /usr/local/bin/wkhtmltopdf-arm64. You can download and place it at: https://github.com/houseoftech/wkhtmltopdf-arm64/raw/refs/heads/master/bin/wkhtmltopdf-arm64 [//]: #@corifeus-footer --- ## πŸš€ Quick and Affordable Web Development Services If you want to quickly and affordably develop your next digital project, visit [corifeus.eu](https://corifeus.eu) for expert solutions tailored to your needs. --- ## 🌐 Powerful Online Networking Tool Discover the powerful and free online networking tool at [network.corifeus.com](https://network.corifeus.com). **πŸ†“ Free** Designed for professionals and enthusiasts, this tool provides essential features for network analysis, troubleshooting, and management. Additionally, it offers tools for: - πŸ“‘ Monitoring TCP, HTTP, and Ping to ensure optimal network performance and reliability. - πŸ“Š Status page management to track uptime, performance, and incidents in real time with customizable dashboards. All these features are completely free to use. --- ## ❀️ Support Our Open-Source Project If you appreciate our work, consider ⭐ starring this repository or πŸ’° making a donation to support server maintenance and ongoing development. Your support means the world to usβ€”thank you! --- ### πŸ–₯️ Server Availability Our server may occasionally be down, but please be patient. Typically, it will be back online within 15-30 minutes. We appreciate your understanding. --- ### 🌍 About My Domains All my domains, including [patrikx3.com](https://patrikx3.com), [corifeus.hu](https://corifeus.hu), and [corifeus.com](https://corifeus.com), are developed in my spare time. While you may encounter minor errors, the sites are generally stable and fully functional. --- ### πŸ“ˆ Versioning Policy **Version Structure:** We follow a **Major.Minor.Patch** versioning scheme: - **Major:** πŸ“… Corresponds to the current year. - **Minor:** πŸŒ“ Set as 4 for releases from January to June, and 10 for July to December. - **Patch:** πŸ”§ Incremental, updated with each build. **🚨 Important Changes:** Any breaking changes are prominently noted in the readme to keep you informed. --- [**P3X-HTML-PDF**](https://corifeus.com/html-pdf) Build v2025.4.116 [![NPM](https://img.shields.io/npm/v/p3x-html-pdf.svg)](https://www.npmjs.com/package/p3x-html-pdf) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) [//]: #@corifeus-footer:end