Laru is an open-source HTML-to-PDF solution: fast, robust, and efficient — one native render pass, no page limit, streams to file for maximum PDF generation. Full control via a rich options API (timeout, retry, waitForSelector, margins, scale, page range, PDF metadata, and more).
| Package | Purpose |
|---|---|
| laru-pdf-js | JS library: shared API and types. In the browser, methods reject with guidance to use native or Print → Save as PDF. |
| laru-cap-pdf | Capacitor (cap) plugin: native iOS/Android HTML→PDF. Uses WebKit/WebView (no canvas). |
In a Capacitor (Ionic) app (native iOS/Android):
npm install laru-cap-pdf
npx cap syncimport { LaruCapPdf } from 'laru-cap-pdf';
const { path } = await LaruCapPdf.fromData({
data: '<h1>Hello</h1>',
type: 'file',
fileName: 'out.pdf',
baseUrl: 'file:///android_asset/', // when HTML has relative CSS/JS
});In a web-only project:
npm install laru-pdf-jsSame API; in the browser it will throw with a message to use Print → Save as PDF or use the cap plugin in a native app.
- Faster than html2pdf / jsPDF / canvas2pdf — One native WebKit/WebView render pass; no per-page canvas or bitmap. Same document in a fraction of the time.
- 500+ pages — Native formatters paginate in one pass; use
type: 'file'for large docs. Canvas-based libs typically choke or run out of memory. - Full CSS/JS — Pass
baseUrlso relative styles, scripts, and images resolve. All options (timeout, waitForSelector, margins, printBackground, httpHeaders, metadata) are implemented. - Open source, you own it — MIT. No vendor or paid-tier lock-in.
- Same API everywhere — laru-pdf-js (web) and laru-cap-pdf (native) share the same
HtmlToPdfOptionsand methods. - Every option you’d expect — page size (preset + custom), margins + presets, scale/fitToPage, pageRange, header/footer HTML, viewport, userAgent, preferColorScheme, mediaType, runBeforePrint, injectStyles, timeout, waitForSelector, PDF metadata, and more. See laru-cap-pdf options.
See laru-cap-pdf for why Laru has no page/timeout/scale limits like the market.
- laru-pdf-js:
npm run buildthennpm test(Vitest; validation and API behavior). - laru-cap-pdf:
npm run buildthennpm test(Vitest; web validation). Usenpm install --legacy-peer-depsif laru-pdf-js is not published yet.
MIT