UNPKG

pdfile

Version:

PDFile is a Node.js library for generating high-quality, dynamic PDFs using Handlebars templates and Puppeteer. It supports multi-page PDFs and offers full customization. Perfect for web developers, it enables easy creation of multi-page PDFs by simply de

25 lines (24 loc) 1.64 kB
/// <reference types="node" /> import { PDFOptions, LaunchOptions } from 'puppeteer'; export interface GeneratePdfOptions { templateFilePath: string; dataPerPage: Array<object>; pdfFilePath?: string; useStream?: boolean; helpersFilePath?: string; puppeteerOptions?: LaunchOptions; pdfOptions?: PDFOptions; } /** * Generate a PDF from a Handlebars template using Puppeteer. * @param {string} templateFilePath - The path to the Handlebars template file. * @param {object[]} dataPerPage - An array containing data objects for each page of the PDF. * @param {string} pdfFilePath - [Optional] The path where the generated PDF file will be saved. Required, if useStream is not passed or set to false. * @param {boolean} useStream - [Optional] Setting this to true will return a readable stream of the pdf instead of writing to the disk on the path "pdfFilePath". * @param {string} [helpersFilePath] - [Optional] The path to a Handlebars helpers file containing custom Handlebars helpers. * @param {LaunchOptions} [puppeteerOptions] - [Optional] Puppeteer launch options. * @param {PDFOptions} [pdfOptions] - [Optional] PDF generation options. * @returns {Promise<string>} A Promise that resolves with the path to the generated PDF file or a readable stream of the pdf if "useStream is set to true". * @throws {Error} Throws an error if no data is passed to inject into the PDF. */ export declare const generatePdf: ({ templateFilePath, dataPerPage, pdfFilePath, useStream, helpersFilePath, puppeteerOptions, pdfOptions, }: GeneratePdfOptions) => Promise<string | NodeJS.ReadableStream>;