@cabletv102/capacitor-plugin-printer
v0.0.3
Published
Capacitor plugin for printing HTML format value in iOS/Android apps.
Downloads
197
Maintainers
Readme
Printer.print({ content: '<b>Lorem ipsum...</b>'})Versions
| Capacitor Version | Plugin Version | | ------------------ | ------------------ | | v5.x | v0.0.3 | | v6.x | v0.0.4+ | | v7.x | Forked and updated |
Supported Platforms
- Android 6.1+
- iOS 14+
Supported Contents
- HTML (can use CSS inline styling)
- Text
- Image(as HTML)
- Base64(PDF & image) (since v0.0.5)
Installation
npm install @cabletv102/capacitor-plugin-printer
npx cap syncUsage
import { Printer } from '@cabletv102/capacitor-plugin-printer';
.
.
.
Printer.print({ content: 'Lorem ipsum...', name: 'lorem-filename', orientation: 'landscape' })Examples
Text:
Printer.print({ content: 'Lorem ipsum...'})HTML:
Printer.print({ content: '<h1>Lorem</h1>'})Printing multiple HTML elements:
let contentTest: string = "";
contentTest += '<li style="color:green">Tea</li>'
contentTest += '<li style="font-size:50px">Coffee</li>'
contentTest += '<img src="https://picsum.photos/200">'
Printer.print({ content: contentTest })Images with HTML:
Printer.print({ content: '<img src="base64/url/path">'})with inline CSS:
Printer.print({ content: '<b style="color:red">Lorem ipsum</b>'})Base64:
// (since v0.0.5)
// Base64 decoder supports Plain text(just the Base64 value) & Data URI(data:content/type;base64)
Printer.print({ content: 'base64:...'})API
print(...)
print(printOptions: PrintOptions) => Promise<void>| Param | Type |
| ------------------ | ----------------------------------------------------- |
| printOptions | PrintOptions |
getAvailablePrinters()
getAvailablePrinters() => Promise<{ printers: PrinterInfo[]; }>Retrieves a list of available printers.
Returns: Promise<{ printers: PrinterInfo[]; }>
Since: 0.0.3
Interfaces
PrintOptions
| Prop | Type | Description | Default | Since |
| ----------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ----- |
| content | string | HTML content for print. | | 0.0.1 |
| name | string | Name of the print of the document. | iOS=YourAppName/Android=Document+CurrentTimestamp | 0.0.1 |
| orientation | string | Orientation of the printing page. "portrait" or "landscape" | "portrait" | 0.0.1 |
| paperSize | { width: number; height: number; } | Custom paper size in inches. Accepts an object with width and height properties. Example: { width: 3.9, height: 2.4 } | undefined (uses printer's default) | 0.0.2 |
PrinterInfo
Represents printer details.
| Prop | Type |
| ----------------- | -------------------- |
| displayName | string |
| url | string |
| isAvailable | boolean |
