Skip to content

@capawesome-team/capacitor-printer

Capacitor plugin for printing.

Features

  • 🖥️ Cross-platform: Supports Android and iOS.
  • 🖨️ PDF Printer: Print PDF files.
  • 🖨️ HTML Printer: Print custom HTML content.
  • 🖨️ Web View Printer: Print web view content.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.
  • ⭐️ Support: First-class support from the Capawesome Team.

Installation

This plugin is only available to Capawesome Insiders. First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:

npm config set @capawesome-team:registry https://npm.registry.capawesome.io
npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>

Attention: Replace <YOUR_LICENSE_KEY> with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a Capawesome Insider.

Next, install the package:

npm install @capawesome-team/capacitor-printer
npx cap sync

Android

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $androidxDocumentFileVersion version of androidx.documentfile:documentfile (default: 1.0.1)

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Android iOS

Usage

import { Printer } from '@capawesome-team/capacitor-printer';

const printHtml = async () => {
  await Printer.printHtml({
    name: 'My Document',
    html: '<h1>Hello World</h1>',
  });
};

const printPdf = async () => {
  await Printer.printPdf({
    name: 'My Document',
    path: 'content://com.android.providers.downloads.documents/document/msf%3A1000000485',
  });
};

const printWebView = async () => {
  await Printer.printWebView({
    name: 'My Document',
  });
};

API

printHtml(...)

printHtml(options: PrintHtmlOptions) => Promise<void>

Present the printing user interface to print a html document.

Only available on Android and iOS.

Param Type
options PrintHtmlOptions

Since: 5.0.0


printPdf(...)

printPdf(options: PrintPdfOptions) => Promise<void>

Present the printing user interface to print a pdf document.

Only available on Android and iOS.

Param Type
options PrintPdfOptions

Since: 5.1.0


printWebView(...)

printWebView(options?: PrintOptions | undefined) => Promise<void>

Present the printing user interface to print the web view content.

You can use a print style sheet to customize the print output (see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Printing).

Param Type
options PrintOptions

Since: 5.0.0


Interfaces

PrintHtmlOptions

Prop Type Description Since
html string The HTML content to print. 5.0.0

PrintPdfOptions

Prop Type Description Since
path string The path to the pdf document on the device. 5.1.0

PrintOptions

Prop Type Description Default Since
name string The name of the print job. 'Document' 5.0.0

Type Aliases

PrintWebViewOptions

PrintOptions

Changelog

See CHANGELOG.md.

License

See LICENSE.