1.0.2 • Published 7 months ago
html2pdf-maker v1.0.2
HTML to PDF Converter
A simple and efficient Node.js package for converting HTML content or HTML files to PDF. This tool leverages the power of Puppeteer to generate high-quality, printable PDFs from HTML. Whether you're generating invoices, reports, or any printable content directly from HTML, this package makes the process easy and efficient.
Why Use This Package?
If you are looking for a simple, efficient, and customizable solution to convert HTML to PDF, this is the package for you. It is optimized for speed and low resource usage, making it ideal for both small and large-scale applications.
With the HTML to PDF Converter, you get:
- Efficiency: Reduced CPU and memory usage by reusing browser instances.
- Customization: Easily control PDF output size, margins, and other settings.
- Simplicity: Easy-to-use API for seamless integration into your Node.js applications.
Features
- Convert HTML to PDF: Convert raw HTML strings or HTML files into high-quality PDF documents.
- Customizable Output: Specify margins, page format, background printing, and other options.
- Optimized Performance: Minimize CPU and memory consumption through reuse of Puppeteer browser instances.
- Fast and Simple: Quick conversion with minimal setup.
Installation
To get started, simply install the package via npm:
Install
npm install html-to-pdf-converter
Usage
1. Convert HTML Content to PDF
const { convertHtmlToPdf } = require('html-to-pdf-converter');
const path = require('path');
(async () => {
try {
// Example HTML content
const htmlContent = `
<html>
<body>
<h1>PDF Generated from HTML</h1>
<p>This is an example of HTML to PDF conversion.</p>
</body>
</html>
`;
const outputPath = path.join(__dirname, 'output.pdf');
// Convert HTML content to PDF
await convertHtmlToPdf(htmlContent, outputPath, { format: 'A4' });
console.log('PDF generated at:', outputPath);
} catch (error) {
console.error('Error:', error.message);
}
})()