更新记录
v1.0.0(2024-07-05) 下载此版本
UNIPHIZ系统打印机设备控制插件
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 14.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
UNIPHIZ-API-Printer Specification
To use this plugin, you also need to install the UNIPHIZ-API-Common plugin, otherwise some functions may not work properly
1. Reference Mode
const printer = uni.requireNativePlugin('UNIPHIZ-API-Printer-PrintManager')
2. Interface Catalog
// Get instance
// Release resource
// Cut a paper
// Perform label gap paper learning
// Enumerate the fonts supported by the current device
enumFontsSupported(maxFontNum)
// Get the paper cutting modes supported by the machine
// Get the current number of dot matrix lines printed
// Read the print matrix of the specified character
// Get the printing mode.
// Query the current printing status
// Get printer temperature
// Move the printer forward or backward by the specified number of pixels
// Print a image by file's data encoded in Base64
// Print a image by file's data encoded in base64
printImageByDataAtGrayThreshold(imageData, grayThreshold)
// Print a image by file's path
// Print a image by file's path
printImageByPathAtGrayThreshold(imagePath, grayThreshold)
// Print string
// Select the printer font
parameter with 1 - Font attributes for half-width character font (e.g., English, Russian, etc.)
parameter with 2 - Font attributes for full-width character font (e.g., Chinese, Japanese, etc.)
selectFont(charSet1, width1, height1, bold1, italic1, charSet2, width2, height2, bold2, italic2)
// Set the paper cutting mode to cut the paper immediately after printing
Note: Please call this function before calling prnStart()
// Set the printing font height, enabling double-height printing on the basic font
setDoubleHeight(redoubleHalfWidthChar, redoubleFullWidthChar)
// Set the printing font width, enabling double-width printing on the basic font
setDoubleWidth(redoubleHalfWidthChar, redoubleFullWidthChar)
// Set the printer font name
// Set the font for printing
setFontSize(halfWidthCharCode, fullWidthCharCode)
// Set the printing grayscale level
// Set the label paper size
setLabelBoundary(height, width)
// Set the left margin for character printing
// Set the printing mode
// Set reverse printing
// Set the printing character spacing and line spacing
setSpacing(charSpace, lineSpace)
// Open the printer and print the data from the buffer
For proper usage, follow the formula: Dots per line = Character height + Line spacing
Total dots = Dots per line * Number of lines [Total dots should be less than 3000, Default character height is 24]
3. Interface Specification
Function Description
Function | Type | Description |
---|---|---|
function | get instance |
Example
printer.init() // initByContext()
Function Description
Function | Type | Description |
---|---|---|
function | release resource |
Example
printer.destroy()
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
mode | number | cut-mode of device |
Example
printer.cutPaper(1)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Example
printer.detectPaper()
enumFontsSupported(maxFontNum)
Function Description
Function | Type | Description |
---|---|---|
json | fonts supported by the current device |
Parameter | Type | Description |
---|---|---|
maxFontNum | number | maximum number of fonts that the Fonts buffer can hold(0-64) |
Example
const result = printer.enumFontsSupported(8)
Function Description
Function | Type | Description |
---|---|---|
json | paper cutting modes supported by the machine |
Example
const modes = printer.getCutMode()
Function Description
Function | Type | Description |
---|---|---|
json | number of dot matrix lines printed |
Example
const result = printer.getDotLine()
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
fontSize | number | 0: smaller, 1: larger |
str | string | the specified character |
Example
const result = printer.getFontDot(0, "gb2312")
Function Description
Function | Type | Description |
---|---|---|
json | mode of printing |
Example
const result = printer.getPrintMode()
Function Description
Function | Type | Description |
---|---|---|
json | status of printing |
Example
const result = printer.getPrintStatus()
Function Description
Function | Type | Description |
---|---|---|
json | temperature of printer |
Example
const result = printer.getTemperature()
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
pix | number | number of pixels to move forward or backward |
Example
const result = printer.movePaper(20)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
imageData | string | image data in base64 |
Example
const result = printer.printImageByData("GIUYGBUKYgfufUTFUGYFVYUFYTDFYG ... ")
printImageByDataAtGrayThreshold(imageData, grayThreshold)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
imageData | string | image data encoded in base64 |
grayThreshold | number | grayThreshold |
Example
const result = printer.printImageByDataAtGrayThreshold("GIUYGBUKYgfufUTFUGYFVYUFYTDFYG ... ", 60)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
imagePath | string | image's path |
Example
const result = printer.printImageByPath("/storage/emulated/0/Download/image.JPG")
printImageByPathAtGrayThreshold(imagePath, grayThreshold)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
imagePath | string | image's path |
grayThreshold | number | grayThreshold |
Example
const result = printer.printImageByPathAtGrayThreshold("/storage/emulated/0/Download/image.JPG", 60)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
str | string | string to be print |
charset | string | result of execution |
Example
const result = printer.printStr("Data to be print ...", "GB2312")
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
mode | number | mode of paper cutting |
Example
const result = printer.setCutPaperMode(1)
setDoubleHeight(redoubleHalfWidthChar, redoubleFullWidthChar)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
redoubleHalfWidthChar | number | whether redouble half-width character's height |
redoubleFullWidthChar | number | whether redouble full-width character's height |
Example
const result = printer.setDoubleHeight(0, 0)
setDoubleWidth(redoubleHalfWidthChar, redoubleFullWidthChar)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
redoubleHalfWidthChar | number | whether redouble half-width character's width |
redoubleFullWidthChar | number | whether redouble full-width character's width |
Example
const result = printer.setDoubleWidth(0, 0)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
name | string | font's name |
setFontSize(halfWidthCharCode, fullWidthCharCode)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
halfWidthCharCode | number | font size of half-width character |
fullWidthCharCode | number | font size of full-width character |
Example
const result = printer.setFontSize(1,1)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
level | number | level of grayscale |
Example
const result = printer.setGrayscale(1)
setLabelBoundary(height, width)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
height | number | height of the label paper in millimeters |
width | number | width of the label paper in millimeters |
Example
const result = printer.setLabelBoundary(10, 10)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
indent | number | left indent |
Example
const result = printer.setLeftIndent(20)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
mode | number | print mode |
Example
const result = printer.setPrintMode(0)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
reverse | number | reverse printing code |
Example
const result = printer.setReversePrint(0)
setSpacing(charSpace, lineSpace)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Parameter | Type | Description |
---|---|---|
charSpace | number | Character spacing [in pixels] |
lineSpace | number | Line spaceing [in pixels] |
Example
const result = printer.setSpacing(10, 15)
Function Description
Function | Type | Description |
---|---|---|
json | result of execution |
Example
const result = printer.startPrint()