Capacitor plugin for printing HTML format value iOS/Android apps.
npm install @bcyesil/capacitor-plugin-printer@bcyesil/capacitor-plugin-printer
Capacitor plugin for printing HTML, plain text, and images in iOS/Android apps. Supports additional features like Base64 PDF and image printing (from v0.0.5).
``typescript`
Printer.print({ content: 'Lorem ipsum...'})
| Plugin Version | iOS | Android |
|----------------|-----|----------|
| v0.0.5 and earlier | 13+ | 5.1+ (API 22)|
| v0.0.6+ | 14+ | 6.0+ (API 23) |
- HTML (can use CSS inline styling)
- Text
- Image(as HTML)
- Base64(PDF & image) (since v0.0.5)
bash
npm install @bcyesil/capacitor-plugin-printer
npx cap sync
`Usage
`typescript
import { Printer } from '@bcyesil/capacitor-plugin-printer';.
.
.
Printer.print({ content: 'Lorem ipsum...', name: 'lorem-filename', orientation: 'landscape' })
`Examples
Text:
`typescript
Printer.print({ content: 'Lorem ipsum...'})
`HTML:
`typescript
Printer.print({ content: 'Lorem
'})
`Printing multiple HTML elements:
`typescript
let contentTest: string = ""; contentTest += '
Tea '
contentTest += 'Coffee '
contentTest += '
' Printer.print({ content: contentTest })
`Images with HTML:
`typescript
Printer.print({ content: '
'})
`with inline CSS:
`typescript
Printer.print({ content: 'Lorem ipsum'})
`Base64:
`typescript
// (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(...)
* Interfaces
$3
`typescript
print(printOptions: PrintOptions) => Promise
`| Param | Type |
| ------------------ | ----------------------------------------------------- |
|
printOptions | PrintOptions |--------------------
$3
#### 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 |