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

@flitzinteractive/react-native-nitro-html-pdf

v0.1.5

Published

Generate professional PDF documents directly on device from HTML - perfect for invoices, receipts, reports, and contracts with custom headers, footers, and page numbers. No backend required, works offline, zero cloud costs.

Downloads

451

Readme


Features

  • ✅ Vector-based PDF generation (text remains selectable)
  • ✅ Custom headers and footers with vector quality
  • ✅ Automatic page numbering
  • ✅ Multiple page sizes (A4, A3, A5, Letter, Legal)
  • ✅ Custom margins
  • ✅ iOS and Android support
  • ✅ Built with Nitro Modules for optimal performance
  • ✅ No Backend Required - Works offline
  • ✅ Privacy-First - No data sent to servers
  • ✅ Zero Cloud Costs - Local PDF generation

Use Cases

This library is perfect for:

  • 📄 Invoices and Receipts - Professional documents with company headers and page numbers
  • 📊 Reports - Multi-page reports with consistent branding
  • 📋 Contracts - Legal documents with headers, footers, and pagination
  • 🎓 Certificates - Custom-designed certificates with vector quality
  • 💳 Statements - Bank statements, account summaries, etc.
  • 🎫 Tickets and Passes - Event tickets, boarding passes, etc.
  • 📑 Documentation - Technical manuals, user guides
  • 💼 Business Documents - Proposals, quotes, presentations

Installation

npm install @flitzinteractive/react-native-nitro-html-pdf react-native-nitro-modules

Or with yarn:

yarn add @flitzinteractive/react-native-nitro-html-pdf react-native-nitro-modules

react-native-nitro-modules is required as this library relies on Nitro Modules.

Android Setup

Add to your MainActivity.kt:

import com.margelo.nitro.nitrohtmlpdf.NitroHtmlPdf

override fun onCreate(savedInstanceState: android.os.Bundle?) {
    super.onCreate(savedInstanceState)
    NitroHtmlPdf.appContext = applicationContext
}

Usage

Basic Example

import { generatePdf } from '@flitzinteractive/react-native-nitro-html-pdf';

const result = await generatePdf({
  html: '<h1>Hello World</h1><p>This is a PDF document.</p>',
  fileName: 'document.pdf',
  pageSize: 'A4',
});

console.log('PDF created at:', result.filePath);

With Header and Footer

const result = await generatePdf({
  html: '<h1>Invoice</h1><p>Invoice content...</p>',
  fileName: 'invoice.pdf',
  pageSize: 'A4',
  header: '<div style="text-align: center;"><h3>Company Name</h3></div>',
  footer: '<div style="text-align: center;"><p>Thank you!</p></div>',
  headerHeight: 100,  // Required when using header
  footerHeight: 80,   // Required when using footer
  showPageNumbers: true,
  pageNumberFormat: 'Page {page} of {total}',
  marginTop: 20,
  marginBottom: 20,
});

API Reference

generatePdf(options: PdfOptions): Promise<PdfResult>

PdfOptions

| Property | Type | Required | Default | Description | |----------|------|----------|---------|-------------| | html | string | ✅ | - | HTML content to convert to PDF | | fileName | string | ✅ | - | Output PDF file name (must end with .pdf) | | pageSize | 'A4' \| 'A3' \| 'A5' \| 'LETTER' \| 'LEGAL' | ❌ | 'A4' | Page size | | header | string | ❌ | - | HTML content for header | | footer | string | ❌ | - | HTML content for footer | | headerHeight | number | ⚠️ | - | Header height in pixels (required if header is provided) | | footerHeight | number | ⚠️ | - | Footer height in pixels (required if footer is provided) | | showPageNumbers | boolean | ❌ | false | Show page numbers in footer | | pageNumberFormat | string | ❌ | 'Page {page} of {total}' | Page number format | | pageNumberFontSize | number | ❌ | 12 | Page number font size | | marginTop | number | ❌ | 0 | Top margin in pixels | | marginBottom | number | ❌ | 0 | Bottom margin in pixels | | marginLeft | number | ❌ | 0 | Left margin in pixels | | marginRight | number | ❌ | 0 | Right margin in pixels | | directory | string | ❌ | Cache dir | Output directory path |

PdfResult

interface PdfResult {
  filePath: string;  // Absolute path to generated PDF
  success: boolean;  // Whether generation succeeded
  error?: string;    // Error message if failed
}

Important Notes

Header and Footer Heights

You must provide explicit headerHeight and footerHeight values when using headers or footers. The library does not auto-calculate these values.

// ❌ Wrong - will throw error
await generatePdf({
  html: '...',
  fileName: 'doc.pdf',
  header: '<h3>Header</h3>',  // Missing headerHeight!
});

// ✅ Correct
await generatePdf({
  html: '...',
  fileName: 'doc.pdf',
  header: '<h3>Header</h3>',
  headerHeight: 100,  // Explicit height
});

Page Size Dimensions

  • A4: 595 × 842 pts (210 × 297 mm)
  • A3: 842 × 1191 pts (297 × 420 mm)
  • A5: 420 × 595 pts (148 × 210 mm)
  • Letter: 612 × 792 pts (8.5 × 11 in)
  • Legal: 612 × 1008 pts (8.5 × 14 in)

Margin Behavior

The library automatically adjusts content margins to prevent overlap:

  • Total top margin = marginTop + headerHeight
  • Total bottom margin = marginBottom + footerHeight + (showPageNumbers ? 20 : 0)

Supported HTML/CSS

Both iOS and Android use native WebView rendering, supporting:

  • Standard HTML5 tags
  • CSS styling (inline, <style> tags)
  • Tables, lists, images
  • Custom fonts (with proper CSS @font-face)

Error Handling

try {
  const result = await generatePdf(options);
  
  if (result.success) {
    console.log('PDF created:', result.filePath);
  } else {
    console.error('PDF generation failed:', result.error);
  }
} catch (error) {
  console.error('Unexpected error:', error);
}

Common Errors

| Error | Cause | Solution | |-------|-------|----------| | headerHeight must be provided | Using header without height | Add headerHeight property | | footerHeight must be provided | Using footer without height | Add footerHeight property | | Combined header, footer, and margins exceed page height | Heights too large | Reduce header/footer/margin values | | File name must end with .pdf | Invalid file name | Ensure fileName ends with .pdf | | HTML content cannot be empty | Empty HTML | Provide valid HTML content |

Platform Differences

Android

  • Uses PrintDocumentAdapter for vector rendering
  • PDFs merged using PDFBox LayerUtility
  • Text remains selectable in output PDF

iOS

  • Uses UIPrintPageRenderer for vector rendering
  • Native PDF context drawing
  • Text remains selectable in output PDF

Contributing

License

MIT


Crafted with vision by Flitz Interactive