laru-pdf-js
v0.0.1
Published
Laru — JS library: shared API and types for HTML-to-PDF. Use with laru-cap-pdf on native iOS/Android.
Maintainers
Readme
laru-pdf-js
Laru — JavaScript library: shared API and types for HTML-to-PDF.
This package provides the same API (fromData, fromUrl, HtmlToPdfOptions) for use in web contexts. In the browser, these methods reject with a clear message: use laru-cap-pdf in a Capacitor (iOS/Android) app for native, fast PDF generation, or use the browser Print dialog and "Save as PDF".
Install
npm install laru-pdf-jsUsage (web)
import { fromData, fromUrl, type HtmlToPdfOptions } from 'laru-pdf-js';
// In browser: throws with guidance to use native or Print → Save as PDF
await fromData({ data: '<h1>Hello</h1>', documentSize: 'A4' });
await fromUrl({ url: 'https://example.com/page', type: 'base64' });Use with laru-cap-pdf (native)
In a Capacitor app, install laru-cap-pdf for iOS/Android. The same options apply; native implementation handles 500+ pages and full CSS/JS with baseUrl.
API
- fromData(options) —
options: { data: string } & HtmlToPdfOptions - fromUrl(options) —
options: { url: string } & HtmlToPdfOptions - HtmlToPdfOptions — documentSize, orientation, margins, printBackground, injectStyles, scale, fitToPage, type, fileName, outputPath, encoding, baseUrl, enableJavaScript, loadImages, timeout, delayAfterLoad, waitForSelector, httpHeaders (fromUrl), title, author, subject, creator. All optional except
data/url. Validation enforces bounds (e.g. scale 0.1–3, timeout ≤ 10 min, non-negative margins).
Testing
npm test # run once
npm run test:watch # watch modeTests cover validation (options, bounds, margins) and that fromData/fromUrl reject with the expected message in the browser.
License
MIT
