Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Repository files navigation

HTML-PDF

Node lib to converts HTML with property binding or url to PDF files.

npm versionlicensesize

🚧 Requirements

🚀 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

asyncfunctionmain(){constbrowser=awaitinitBrowser();letreadable;try{readable=Readable.from(generatePDF(browser,[{content: html}],pdfOptions));}finally{awaitterminateBrowser(browser);}returnreadable;}main().catch(console.error);

API

initBrowser(options?: PuppeteerLaunchOptions): Promise< Browser >
import{initBrowser}from"@myunisoft/html-to-pdf";constbrowser=awaitinitBrowser();

Options payload is described by the following TypeScript interface:

import{LaunchOptions,BrowserLaunchArgumentOptions,BrowserConnectOptions,Product}from"puppeteer";typePuppeteerLaunchOptions=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:

interfacepdfFile{content?: string,url?: string}typePuppeteerPDFOptions=PDFOptions&{paginationOffset?: number};
import*aspdffrom"@myunisoft/html-to-pdf";constbrowser=awaitpdf.initBrowser();constpdfOptions={};constcontent="..HTML HERE..";constreadable=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*aspdffrom"@myunisoft/html-to-pdf";constbrowser=awaitpdf.initBrowser();try{// DO THE WORK HERE}finally{awaitpdf.terminateBrowser(browser);}

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Nicolas Hallaert

💻📖⚠️

Gentilhomme

🛡️👀📖

PierreD

💻

License

MIT

About

Node lib to converts HTML with property binding or url to PDF files.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages