1.0.0 • Published 11 months ago

@mahdi.golzar/pdfgenerator v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

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

  1. Create a PDFGenerator Instance
    const pdfGenerator = new PDFGenerator();
    await pdfGenerator.initialize();
  2. 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');
  1. Close the PDFGenerator
   await pdfGenerator.close();