电容打印机插件
@bcyesil/capacitor-plugin-printer
用于在iOS/Android应用中打印HTML,纯文本和图像的电容插件. 支持Base64 PDF和图像打印等附加功能(出自v.0.0.5).
Printer.print({ content: '<b>Lorem ipsum...</b>'})
版本数
| 电容版本 | 插件版本 |
|---|---|
| 页:1 | 页:1 |
| v6.x (中文(简体) ) | 页:1 |
| v7.x (中文(简体) ) | v0.0.6+ (单位:千美元) |
支持的平台
| 插件版本 | iOS系统 | 机器人 |
|---|---|---|
| v.0.0.5和较早时 | 13岁以上 | 5.1+ (API 22) (中文(简体) ) |
| v0.0.6+ (单位:千美元) | 14岁以上 | 6.0+ (API 23) (英语) |
支持的内容
- HTML( 可使用 CSS 内置样式)
- 文本
- 图像( 作为 HTML)
- Base64( PDF 和图像)(自 v0.0.5)
安装
npm install @bcyesil/capacitor-plugin-printer
npx cap sync
使用量
import { Printer } from '@bcyesil/capacitor-plugin-printer';
.
.
.
Printer.print({ content: 'Lorem ipsum...', name: 'lorem-filename', orientation: 'landscape' })
实例
文本 :
Printer.print({ content: 'Lorem ipsum...'})
HTML : (英语)
Printer.print({ content: '<h1>Lorem</h1>'})
打印多个 HTML 元素 :
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 })
带有 HTML 的图像 :
Printer.print({ content: '<img src="base64/url/path">'})
内置 CSS :
Printer.print({ content: '<b style="color:red">Lorem ipsum</b>'})
基础64:
// (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(printOptions: PrintOptions) => Promise<void>
| 参数 | 类型 |
|---|---|
printOptions | PrintOptions |
接口
打印选项
| Prop | 类型 | 说明 | 默认 | 自兹 |
|---|---|---|---|---|
content | string | HTML 打印内容. | 0.0.1 资源 | |
name | string | 文档打印出的名称. | iOS=YourAppName/Android=Document+CurrentTimestamp | 0.0.1 资源 |
orientation | string | 打印页面的方向 。 "平面"或"地貌" | "portrait" | 0.0.1 资源 |