npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

laru-cap-pdf

v0.0.1

Published

Laru — Capacitor (cap) plugin: native iOS/Android HTML-to-PDF, fast and scalable to 500+ pages.

Readme

laru-cap-pdf

Laru — Capacitor (cap) plugin: native iOS/Android HTML-to-PDF. Fast, robust, efficient — one native render pass, no page limit, streams to file for maximum PDF generation. Full control via a rich options API; uses WebKit/WebView (no canvas).

Why Laru is better

| vs canvas-based (html2pdf, jsPDF+html2canvas) | vs other native plugins | |-----------------------------------------------|--------------------------| | One native render pass — no per-page bitmap; 500+ pages in one go. | All options implemented: timeout, waitForSelector, margins, printBackground, httpHeaders, PDF metadata (iOS). | | Faster — same document in a fraction of the time. | You own the code — MIT, no vendor lock-in. | | Full CSS/JS — pass baseUrl; relative assets resolve. | Same API as laru-pdf-js for a consistent experience. |

Install

npm install laru-cap-pdf
npx cap sync

Usage

import { LaruCapPdf } from 'laru-cap-pdf';

// From HTML string (pass baseUrl when using relative CSS/JS paths)
const result = await LaruCapPdf.fromData({
  data: '<html><body><h1>Hello</h1></body></html>',
  documentSize: 'A4',
  orientation: 'portrait',
  type: 'base64',  // or 'file' | 'share'
  fileName: 'document.pdf',
  baseUrl: 'file:///android_asset/',  // required if HTML has relative links/scripts
});
console.log(result.base64);  // or result.path for type: 'file'

// From URL with auth headers
const result2 = await LaruCapPdf.fromUrl({
  url: 'https://example.com/page',
  httpHeaders: { 'Authorization': 'Bearer token' },
  type: 'file',
  fileName: 'page.pdf',
});

Options (HtmlToPdfOptions)

All options are supported on both iOS and Android unless noted. Every option is optional — only data (fromData) or url (fromUrl) is required.

| Option | Type | Description | |--------|------|-------------| | Page layout | | | | documentSize | 'A2' | 'A3' | 'A4' | 'Letter' | 'Legal' | Paper size. Default: A4. Ignored if customPageSize is set. | | orientation | 'portrait' | 'landscape' | Page orientation. | | customPageSize | { widthPt, heightPt } | Custom size in points (1 pt = 1/72"). Overrides documentSize. | | margins | { top?, bottom?, left?, right? } | Page margins in points (pt). | | marginPreset | 'none' | 'minimal' | 'normal' | 'wide' | Quick margins when margins not set (0, 18pt, 36/72pt, 72pt). | | printBackground | boolean | Include CSS backgrounds (default true). | | omitBackground | boolean | Do not print backgrounds (alias for printBackground: false). | | injectStyles | string | Extra CSS injected before print (e.g. @page { margin: 0; }). | | scale | number | Scale factor 0.1–3 (default 1). | | fitToPage | boolean | Use scale 0.95 to fit content to page. | | pageRange | string | Only include these pages, e.g. "1-5" or "1,3,5". | | headerHtml | string | HTML fragment for header (fixed at top, each page). | | footerHtml | string | HTML fragment for footer (fixed at bottom, each page). | | Output | | | | type | 'base64' | 'share' | 'file' | How to return/save the PDF. For 500+ pages use file. | | fileName | string | Filename for share/file output. | | outputPath | string | For type 'file': directory to write to (optional). | | encoding | string | HTML charset for fromData (default UTF-8). Android. | | Loading & behavior | | | | baseUrl | string | Required for fromData when HTML uses relative CSS/JS/images. | | enableJavaScript | boolean | Allow JS (default true). | | loadImages | boolean | Load images (default true). Android. | | userAgent | string | Custom User-Agent for the WebView. | | viewport | { width, height } | Viewport size in pixels (responsive layout). | | preferColorScheme | 'light' | 'dark' | Force color scheme for @media (prefers-color-scheme). | | mediaType | 'print' | 'screen' | CSS media to emulate (default print). | | runBeforePrint | string | JavaScript to run in the page right before generating PDF. | | delayAfterLoad | number | Ms to wait after load before generating PDF. | | timeout | number | Max ms to wait for load; rejects on timeout. | | waitForSelector | string | CSS selector; wait until element exists (or timeout) before generating. | | retry | number | Retries on failure (e.g. network). Default: 0. | | retryDelay | number | Ms between retries. Default: 500. | | fromUrl only | | | | httpHeaders | Record<string, string> | Extra headers (e.g. Authorization). | | PDF metadata | | iOS (keywords too); Android best-effort. | | title, author, subject, creator, keywords, producer | string | PDF document metadata. |

Platform support

  • iOS: Full support. WKWebView + UIPrintPageRenderer. PDF metadata (title, author, subject, creator) supported. Requires Xcode on macOS to build.
  • Android: Full support. WebView + PrintDocumentAdapter. For share type the app may need to configure FileProvider.
  • Web: Rejects with a message; use browser Print → Save as PDF or laru-pdf-js for the same API.

No arbitrary limits (unlike the market)

Laru does not impose the typical limits of commercial or free HTML-to-PDF libraries:

  • No page limit — Generate 500+ or thousands of pages in one pass (use type: 'file' for large docs).
  • No file size cap — Output size is only limited by device storage.
  • Generous timeoutstimeout and delayAfterLoad can be up to 24 hours (86 400 000 ms) for long-running or batch jobs; no 30s/2 min cap.
  • Wide scale rangescale from 0.01 to 10 (1%–1000%); no narrow 0.5–2 range.
  • Custom page size — Any dimensions via customPageSize; not limited to presets.
  • Page range — Export only the pages you need with pageRange.

Only platform realities apply: PDF metadata (title, author, etc.) is iOS only; Share on Android requires your app to configure a FileProvider.

Testing

npm install --legacy-peer-deps   # if laru-pdf-js is not published
npm test

Tests cover web validation (same options as native). Native behavior is tested on device/simulator.

Performance, efficiency & maximum PDF

  • Fastest path: Set enableJavaScript: false and loadImages: false when your HTML doesn’t need them — load and render are faster.
  • Efficient output: Use type: 'file' for any document that might be large. The PDF is streamed to disk (no full-doc buffer in memory). Use type: 'base64' only for small PDFs.
  • One native render pass: No per-page bitmap or canvas; the engine paginates in a single pass, so generation stays fast and memory use is predictable.
  • Result: path, base64, and when available pages (page count) for diagnostics or progress.
  • Robustness: WebView is destroyed on timeout or error to avoid leaks; use retry and retryDelay for flaky networks.
  • No page cap: Generate as many pages as you need; for very large jobs, keep type: 'file' and ensure enough free disk space.

License

MIT