1.0.8 • Published 10 months ago
@logismiko/html-pdf v1.0.8
@logismiko/html-pdf
Convert HTML content or web pages to PDF using Node.js and Puppeteer.
Installation
npm install @logismiko/html-pdfUsage
import { generatePdf } from '@logismiko/html-pdf';
// Generate single PDF
const file = { content: "Welcome" };
// or
const file = { url: "https://example.com" };
const options = { format: 'A4' };
// Promise
generatePdf(file, options)
.then(pdfBuffer => {
console.log("PDF Buffer:-", pdfBuffer);
});
// Callback
generatePdf(file, options, (err, pdfBuffer) => {
if (err) {
console.log(err);
return;
}
console.log("PDF Buffer:-", pdfBuffer);
});Options
The options parameter accepts all Puppeteer PDF options.
Common options include:
format: 'A4', 'Letter', etc.path: File path to save the PDF towidth: Page widthheight: Page heightprintBackground: Include background graphicsmargin: Page margins
License
ISC