Package Exports
- @myunisoft/html-to-pdf
- @myunisoft/html-to-pdf/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@myunisoft/html-to-pdf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
HTML-PDF
Node lib to converts HTML with property binding or url to PDF files.
🚧 Requirements
- Node.js version 14 or higher
🚀 Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn
$ npm i @myunisoft/html-to-pdf
# or
$ yarn add @myunisoft/html-to-pdf📚 Usage
async function main() {
const browser = await initBrowser();
let readable;
try {
readable = Readable.from(generatePDF(browser, [{ content: html }], pdfOptions));
}
finally {
await terminateBrowser(browser);
}
return readable;
}
main().catch(console.error);API
initBrowser(options?: PuppeteerLaunchOptions): Promise< Browser >
import { initBrowser } from "@myunisoft/html-to-pdf";
const browser = await initBrowser();Options payload is described by the following TypeScript interface:
import {
LaunchOptions,
BrowserLaunchArgumentOptions,
BrowserConnectOptions,
Product
} from "puppeteer";
type PuppeteerLaunchOptions = LaunchOptions & BrowserLaunchArgumentOptions & BrowserConnectOptions & {
product?: Product;
extraPrefsFirefox?: Record<string, unknown>;
}generatePDF(browser: Browser, files: pdfFile[], options?: PuppeteerPDFOptions): AsyncIterableIterator< Buffer >
files and options arguments are described with the following TypeScript interface/type:
interface pdfFile {
content?: string,
url?: string
}
type PuppeteerPDFOptions = PDFOptions & { paginationOffset?: number };import * as pdf from "@myunisoft/html-to-pdf";
const browser = await pdf.initBrowser();
const pdfOptions = {};
const content = "..HTML HERE..";
const readable = Readable.from(
pdf.generatePDF(browser, [{ content }], pdfOptions)
);
// Do the work with readable (pipe to an http response for example).terminateBrowser(browser: Browser): Promise< void >
import * as pdf from "@myunisoft/html-to-pdf";
const browser = await pdf.initBrowser();
try {
// DO THE WORK HERE
}
finally {
await pdf.terminateBrowser(browser);
}Contributors ✨
Thanks goes to these wonderful people (emoji key):
Nicolas Hallaert 💻 📖 ⚠️ |
Gentilhomme 🛡️ 👀 📖 |
PierreD 💻 |
License
MIT