A Capacitor plugin to print HTML, PDF, images, and plain text on iOS, Android, and Web.
import { Printer } from '@dimer47/capacitor-plugin-printer';
await Printer.printHtml({ html: '<b>Hello Capacitor!</b>' });- 📄 Print HTML & CSS with full styling support
- 📝 Print plain text with font customization
- 📑 Print PDF documents from file paths or URIs
- 🖼️ Print images (PNG, JPEG, GIF, BMP, HEIF)
- 🔐 Print base64-encoded data with explicit MIME types
- 🌐 Print the current WebView content
- 📐 Paper sizes — named sizes (A0–A10, Letter, Legal, Tabloid, etc.) and custom dimensions
- 📏 Unit support — points, inches, millimeters, centimeters
- 🎨 Headers & footers with labels, page numbers, and font styling (iOS)
- 🖨️ Direct print to a specific printer without dialog (iOS)
- ✂️ Duplex printing (double-sided)
| Platform | Version |
|---|---|
| iOS | 15+ |
| Android | 7.0+ (API 24) |
| Web | Modern browsers |
npm install @dimer47/capacitor-plugin-printer
npx cap sync| Method | Description |
|---|---|
print() |
Print content with auto-detected type |
printHtml() |
Print an HTML string |
printPdf() |
Print a PDF from a file path or URI |
printBase64() |
Print base64-encoded data |
printFile() |
Print a file from a path or URI |
printWebView() |
Print the current WebView content |
canPrintItem() |
Check if the device can print |
getPrintableTypes() |
List supported printable document types |
pick() |
Show the printer picker (iOS only) |
print(options?: PrintOptions) => Promise<PrintResult>Print content with automatic type detection. The plugin detects whether the content is HTML, a file URI, base64 data, or plain text.
// HTML
await Printer.print({ content: '<h1>Hello</h1>' });
// File
await Printer.print({ content: 'file:///path/to/document.pdf' });
// Base64
await Printer.print({ content: 'base64://JVBERi0...' });
// Plain text
await Printer.print({ content: 'Hello World' });printHtml(options: PrintHtmlOptions) => Promise<PrintResult>Print an HTML string.
await Printer.printHtml({
html: '<h1>Invoice</h1><p>Amount: $42.00</p>',
name: 'Invoice',
orientation: 'portrait',
});printPdf(options: PrintPdfOptions) => Promise<PrintResult>Print a PDF file from a path or URI.
await Printer.printPdf({ path: 'file:///path/to/document.pdf' });printBase64(options: PrintBase64Options) => Promise<PrintResult>Print base64-encoded data with an explicit MIME type.
await Printer.printBase64({
data: 'JVBERi0xLjQK...', // base64 string without prefix
mimeType: 'application/pdf',
});printFile(options: PrintFileOptions) => Promise<PrintResult>Print a file from a path or URI. The MIME type is detected automatically if not provided.
await Printer.printFile({ path: 'file:///path/to/image.png' });
// With explicit MIME type
await Printer.printFile({
path: 'file:///path/to/doc',
mimeType: 'application/pdf',
});printWebView(options?: PrintWebViewOptions) => Promise<PrintResult>Print the current WebView content.
await Printer.printWebView();
// With options
await Printer.printWebView({ orientation: 'landscape' });canPrintItem(options?: CanPrintOptions) => Promise<CanPrintResult>Check if the device supports printing, optionally for a specific item.
const { available } = await Printer.canPrintItem();
// Check a specific URI
const { available } = await Printer.canPrintItem({ uri: 'file:///path/to/file.pdf' });getPrintableTypes() => Promise<PrintableTypesResult>Get the list of printable document types supported by the platform (UTIs on iOS, MIME types on Android).
const { types } = await Printer.getPrintableTypes();
// e.g. ["com.adobe.pdf", "public.jpeg", "public.png", ...]pick(options?: PickOptions) => Promise<PickResult>Show the system printer picker. iOS only — on Android, this method will reject.
const { url } = await Printer.pick();
if (url) {
await Printer.printHtml({ html: '<p>Direct print</p>', printer: url });
}Common options shared by all print methods.
| Property | Type | Default | Platform | Description |
|---|---|---|---|---|
name |
string |
— | All | Job name and document title |
orientation |
'portrait' | 'landscape' |
'portrait' |
All | Print orientation |
monochrome |
boolean |
false |
All | Black & white printing |
photo |
boolean |
false |
iOS | Photography media type for higher quality |
copies |
number |
1 |
iOS | Number of copies |
pageCount |
number |
— | iOS, Android | Maximum number of pages to print |
duplex |
'none' | 'long' | 'short' |
'none' |
All | Double-sided printing |
margin |
boolean | MarginOptions |
— | All | Margins. Set to false to disable |
font |
FontOptions |
— | iOS | Font configuration for plain text |
maxWidth |
string | number |
— | iOS | Maximum content width |
maxHeight |
string | number |
— | iOS | Maximum content height |
header |
HeaderFooterOptions |
— | iOS | Header configuration |
footer |
HeaderFooterOptions |
— | iOS | Footer configuration |
paper |
PaperOptions |
— | iOS, Android | Paper format |
printer |
string |
— | iOS | Printer URL for direct printing (skip dialog) |
ui |
UIOptions |
— | iOS | Printer dialog UI options |
autoFit |
boolean |
true |
Android | Auto-scale images to fit content area |
javascript |
boolean |
false |
Android | Enable JavaScript in WebView rendering |
Extends BasePrintOptions with:
| Property | Type | Description |
|---|---|---|
content |
string |
Content to print (HTML, text, file URI, or base64 URI) |
Extends BasePrintOptions with:
| Property | Type | Description |
|---|---|---|
html |
string (required) |
HTML string to print |
Extends BasePrintOptions with:
| Property | Type | Description |
|---|---|---|
path |
string (required) |
File path or URI to the PDF |
Extends BasePrintOptions with:
| Property | Type | Description |
|---|---|---|
data |
string (required) |
Base64-encoded data |
mimeType |
string (required) |
MIME type (e.g. 'application/pdf', 'image/png') |
Extends BasePrintOptions with:
| Property | Type | Description |
|---|---|---|
path |
string (required) |
File path or URI |
mimeType |
string |
MIME type (auto-detected if omitted) |
| Property | Type | Description |
|---|---|---|
top |
string | number |
Top margin |
left |
string | number |
Left margin |
bottom |
string | number |
Bottom margin |
right |
string | number |
Right margin |
| Property | Type | Description |
|---|---|---|
name |
string |
Font family name |
size |
number |
Font size in points |
color |
string |
Hex color (e.g. '#FF0000') |
align |
'left' | 'right' | 'center' | 'justified' |
Text alignment |
bold |
boolean |
Bold text |
italic |
boolean |
Italic text |
| Property | Type | Description |
|---|---|---|
height |
string | number |
Header/footer area height |
text |
string |
Simple text content |
label |
LabelOptions |
Single label |
labels |
LabelOptions[] |
Multiple labels |
| Property | Type | Description |
|---|---|---|
text |
string |
Label text. Use %ld to insert page number (e.g. "Page %ld") |
showPageIndex |
boolean |
Display the page number |
font |
FontOptions |
Label font styling |
top |
string | number |
Top offset within the header/footer area |
left |
string | number |
Left offset |
right |
string | number |
Right offset |
bottom |
string | number |
Bottom offset |
| Property | Type | Description |
|---|---|---|
width |
string | number |
Paper width (e.g. '210mm') |
height |
string | number |
Paper height (e.g. '297mm') |
name |
string |
Named paper size (e.g. 'A4', 'LETTER') |
length |
string | number |
Cut length for roll-fed printers (iOS) |
Named paper sizes: A0–A10, B0–B10, C0–C10, LETTER, LEGAL, TABLOID, LEDGER, JUNIOR_LEGAL, GOVT_LETTER, 4X6, 5X7, 8X10, JIS_B0–JIS_B10, and many more (JPN, ROC, PRC series).
| Property | Type | Platform | Description |
|---|---|---|---|
hideNumberOfCopies |
boolean |
iOS | Hide the copies control |
hidePaperFormat |
boolean |
iOS | Hide the paper format control |
top |
number |
iPad | Popover Y position |
left |
number |
iPad | Popover X position |
width |
number |
iPad | Popover width |
height |
number |
iPad | Popover height |
Dimension values accept either a number (in points) or a string with a unit suffix:
| Suffix | Unit | Example |
|---|---|---|
pt |
Points | "72pt" (= 1 inch) |
in |
Inches | "2in" |
mm |
Millimeters | "210mm" |
cm |
Centimeters | "29.7cm" |
A plain number is interpreted as points: 72 is the same as "72pt" (1 inch).
interface PrintResult {
success: boolean;
}interface CanPrintResult {
available: boolean;
}interface PrintableTypesResult {
types: string[];
}interface PickResult {
url?: string; // Printer URL, or undefined if cancelled
}| Scheme | Example | Description |
|---|---|---|
file:/// |
file:///path/to/file.pdf |
Absolute file path |
file:// |
file://assets/image.png |
App assets/bundle |
res: |
res://icon |
App resources |
base64: |
base64://JVBERi0... |
Base64-encoded data |
On iOS, you can send content directly to a printer without showing the print dialog by passing the printer URL:
await Printer.printHtml({
html: '<p>Direct print</p>',
printer: 'ipp://printer.local.:631/ipp/print',
});Use pick() to let the user select a printer and retrieve its URL:
const { url } = await Printer.pick();
if (url) {
await Printer.printHtml({ html: content, printer: url });
}import { Printer } from '@dimer47/capacitor-plugin-printer';
await Printer.printHtml({
html: `
<h1>Invoice #1234</h1>
<p>Date: 2025-01-15</p>
<table>
<tr><td>Item</td><td>$42.00</td></tr>
</table>
`,
name: 'Invoice-1234',
orientation: 'portrait',
monochrome: false,
duplex: 'long',
paper: { name: 'A4' },
margin: { top: '1cm', left: '1cm', right: '1cm', bottom: '1cm' },
header: {
height: '2cm',
label: {
text: 'My Company',
font: { bold: true, size: 14, align: 'center' },
},
},
footer: {
height: '1.5cm',
label: {
text: 'Page %ld',
showPageIndex: true,
font: { size: 10, align: 'center' },
},
},
});| Feature | iOS | Android | Web |
|---|---|---|---|
| Print HTML | ✅ | ✅ | ✅ |
| Print plain text | ✅ | ✅ | ✅ |
| Print PDF | ✅ | ✅ | — |
| Print images | ✅ | ✅ | — |
| Print base64 data | ✅ | ✅ | — |
| Print WebView | ✅ | ✅ | ✅ |
| Headers & footers | ✅ | — | — |
| Direct print (printer URL) | ✅ | — | — |
Printer picker (pick) |
✅ | — | — |
| Number of copies | ✅ | — | — |
| Paper size selection | ✅ | ✅ | — |
| JavaScript in WebView | — | ✅ | — |
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
This software is released under the Apache 2.0 License.