@mahdi.golzar/pdfgenerator
v1.0.0
Published
PDFGenerator is a tool for creating PDF files from HTML and CSS content. It uses Puppeteer to render HTML and CSS into PDF documents, offering flexibility and high-quality output.
Downloads
9
Maintainers
Readme
PDFGenerator
PDFGenerator is a tool for creating PDF files from HTML and CSS content. It uses Puppeteer to render HTML and CSS into PDF documents, offering flexibility and high-quality output.
Features
- HTML to PDF Conversion: Converts HTML and CSS content into PDF documents.
- Customizable Options: Supports various PDF options like page format and background printing.
- Easy to Use: Simple methods to generate and save PDFs.
Installation
Install the required dependencies:
npm install puppeteer
Usage
- Create a PDFGenerator Instance
const pdfGenerator = new PDFGenerator(); await pdfGenerator.initialize();
- Generate PDF from HTML
const htmlContent = `
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a PDF generated from HTML and CSS.</p>
</body>
</html>
`;
await pdfGenerator.generatePDF(htmlContent, { format: 'A4' }, './output.pdf');
- Close the PDFGenerator
await pdfGenerator.close();