打印
printImage 将移除 MIME 类型前缀的 base64 图像发送到 Brother 打印机。请先完成安装,通过搜索发现打印机,并在开始打印前注册事件以接收打印结果。
请提供真实图像,例如将应用中的 PNG/JPEG 编码并移除 data:...;base64, 前缀。从 onPrinterAvailable 获取并保留 BRLMChannelResult 后,使用其中的 port 和 channelInfo;按实际设备和支持机型表选取匹配的 modelName / labelName。
import {
BrotherPrint,
BRLMPrinterLabelName,
BRLMPrinterModelName,
} from '@rdlabo/capacitor-brotherprint';
import type { BRLMChannelResult, BRLMPrintOptions } from '@rdlabo/capacitor-brotherprint';
const printImage = async (printer: BRLMChannelResult, encodedImage: string) => {
const options: BRLMPrintOptions = {
modelName: BRLMPrinterModelName.QL_820NWB,
labelName: BRLMPrinterLabelName.RollW62,
encodedImage,
numberOfCopies: 1,
autoCut: true,
port: printer.port,
channelInfo: printer.channelInfo,
};
await BrotherPrint.printImage(options);
};
完整的页面示例见演示应用:
https://github.com/rdlabo-dev/capacitor-brotherprint/blob/v9.0.0/demo/src/app/home/home.page.ts
method printImage(...)
printImage(options: BRLMPrintOptions) => Promise<void>
type alias BRLMPrintOptions
{ encodedImage: string; /** * Should use enum BRLMPrinterModelName */ modelName: BRLMPrinterModelName; } & Partial<BRLMChannelResult> & (BRLMPrinterQLModelSettings | BRLMPrinterTDModelSettings)