Skip to content

damiant/capacitor-print-webview

 
 

Repository files navigation

Capacitor Print WebView

A Capacitor plugin that enables printing the current WebView content on iOS and Android devices. This plugin provides a native print dialog that allows users to print or save as PDF the content displayed in your Capacitor application's WebView.

Features

  • 🖨️ Print WebView content directly from your Capacitor app
  • 📱 Native print dialog on iOS and Android
  • 💾 Save as PDF option (platform dependent)
  • 🎨 Preserves styling and formatting from your web content
  • ⚡ Simple, promise-based API
  • 🔧 Supports Capacitor 7

Platforms

  • ✅ iOS
  • ✅ Android
  • ❌ Web (not applicable)

Install

npm install @webnativellc/capacitor-print-webview
npx cap sync

Swift Package Manager (SPM)

This plugin also supports installation via Swift Package Manager for iOS projects. Add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/damiant/capacitor-print-webview.git", from: "7.1.0")
]

Usage

The plugin provides a simple print() method that displays the native print dialog with the current WebView content:

import { PrintWebview } from '@webnativellc/capacitor-print-webview';

// Print the current WebView content
async function printCurrentPage() {
  try {
    await PrintWebview.print();
    console.log('Print dialog opened successfully');
  } catch (error) {
    console.error('Error opening print dialog:', error);
  }
}

Example Use Cases

  • Receipts & Invoices: Allow users to print transaction receipts
  • Reports: Enable printing of generated reports and documents
  • Tickets: Print event tickets or booking confirmations
  • Content Sharing: Provide a print option for articles or documentation

What Gets Printed?

The plugin prints the entire content of the WebView, including:

  • All visible HTML content
  • CSS styling and formatting
  • Images and graphics
  • Dynamic content generated by JavaScript

Note: The content is rendered as it appears in the WebView at the time print() is called.

API

print()

print() => Promise<void>

About

Capacitor Plugin to print the current webview

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 39.2%
  • Swift 35.8%
  • TypeScript 10.4%
  • Ruby 8.0%
  • JavaScript 6.6%