期待有人谁可以纠正或指导我通过这一点,我一直在做一个简单的离子移动的应用程序,使用参考Here,到目前为止,我能够做文本和格式的基本打印,但每当我尝试打印图像它不打印,并调整字体高度和宽度使用打印机esc/pos命令的动态尺寸,它只是打印默认字体.
这是我的密码
import { Component, ViewChild, NgZone } from '@angular/core';
import EscPosEncoder from 'esc-pos-encoder-ionic';
import { commands } from '../printer/printer-command';
import { BluetoothSerial } from '@awesome-cordova-plugins/bluetooth-serial/ngx';
@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss']
})
export class Tab3Page {
testFont() {
let img = new Image()
img.src = 'assets/header.bmp'
const encoder = new EscPosEncoder();
const result = encoder.initialize();
result
.image(img, 300, 300, 'atkinson', 128)
.raw(commands.TEXT_FORMAT.TXT_4SQUARE)
.raw(commands.TEXT_FORMAT.TXT_FONT_A)
.line('4SQUARE FONT A')
.raw(commands.TEXT_FORMAT.TXT_4SQUARE)
.raw(commands.TEXT_FORMAT.TXT_FONT_B)
.line('4SQUARE FONT B')
.raw(commands.TEXT_FORMAT.TXT_4SQUARE)
.raw(commands.TEXT_FORMAT.TXT_FONT_C)
.line('4SQUARE FONT C')
.raw(commands.TEXT_FORMAT.TXT_NORMAL)
.raw(commands.TEXT_FORMAT.TXT_FONT_A)
.line('NORMAL FONT A')
.raw(commands.TEXT_FORMAT.TXT_NORMAL)
.raw(commands.TEXT_FORMAT.TXT_FONT_B)
.line('NORMAL FONT B')
.raw(commands.TEXT_FORMAT.TXT_NORMAL)
.raw(commands.TEXT_FORMAT.TXT_FONT_C)
.line('NORMAL FONT C')
.raw(commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(33,25))
.line('CUSTOM SIZE TEST')
.raw(commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(21,18))
.line('CUSTOM SIZE TEST')
.raw(commands.TEXT_FORMAT.TXT_CUSTOM_SIZE(11,18))
.line('CUSTOM SIZE TEST')
.raw(commands.TEXT_FORMAT.TXT_HEIGHT[1])
.line('HEIGHT TEST')
.raw(commands.TEXT_FORMAT.TXT_HEIGHT[2])
.line('HEIGHT TEST')
.raw(commands.TEXT_FORMAT.TXT_HEIGHT[3])
.line('HEIGHT TEST')
.raw(commands.TEXT_FORMAT.TXT_HEIGHT[4])
.line('HEIGHT TEST')
.raw(commands.TEXT_FORMAT.TXT_HEIGHT[5])
.line('HEIGHT TEST')
.raw(commands.TEXT_FORMAT.TXT_WIDTH[1])
.line('WIDTH TEST')
.raw(commands.TEXT_FORMAT.TXT_WIDTH[2])
.line('WIDTH TEST')
.raw(commands.TEXT_FORMAT.TXT_WIDTH[3])
.line('WIDTH TEST')
.raw(commands.TEXT_FORMAT.TXT_WIDTH[4])
.line('WIDTH TEST')
.raw(commands.TEXT_FORMAT.TXT_WIDTH[5])
.line('WIDTH TEST')
.raw(commands.TEXT_FORMAT.TXT_2WIDTH)
.line('2WIDTH TEST')
.size('small')
.line('small text')
.size('normal')
.line('A line of normal text')
const resultByte = result.encode();
this.bluetoothSerial.connect(this.MAC).subscribe(() => {
this.bluetoothSerial.write(resultByte)
.then(() => {
this.printNotif()
this.bluetoothSerial.disconnect();
})
.catch((err) => {
this.printError(err)
this.bluetoothSerial.disconnect();
});
})
}
}
下面是我的esc/pos打印机命令
//commands based on https://github.com/humbertopiaia/escpos-commands-js/blob/master/src/commands.js
//all the commands below may vary by printer, check the manual
export const commands = {
LF: [0x0a],
ESC: [0x1b],
FS: [0x1c],
GS: [0x1d],
US: [0x1f],
FF: [0x0c],
DLE: [0x10],
DC1: [0x11],
DC4: [0x14],
EOT: [0x04],
NUL: [0x00],
//EOL: [\n],
HORIZONTAL_LINE: {
HR_58MM: '================================',
HR2_58MM: '********************************'
},
FEED_CONTROL_SEQUENCES: {
CTL_LF: [0x0a], // Print and line feed
CTL_FF: [0x0c], // Form feed
CTL_CR: [0x0d], // Carriage return
CTL_HT: [0x09], // Horizontal tab
CTL_VT: [0x0b], // Vertical tab
},
LINE_SPACING: {
LS_DEFAULT: [0x1b,0x32],
LS_SET: [0x1b,0x33]
},
HARDWARE: {
HW_INIT: [0x1b,0x40], // Clear data in buffer and reset modes
HW_SELECT: [0x1b,0x3d,0x01], // Printer select
HW_RESET: [0x1b,0x3f,0x0a,0x00], // Reset printer hardware
},
CASH_DRAWER: {
CD_KICK_2: [0x1b,0x70,0x00], // Sends a pulse to pin 2 []
CD_KICK_5: [0x1b,0x70,0x01], // Sends a pulse to pin 5 []
},
MARGINS: {
BOTTOM: [0x1b,0x4f], // Fi0x bottom size
LEFT: [0x1b,0x6c], // Fi0x left size
RIGHT: [0x1b,0x51], // Fi0x right size
},
PAPER: {
PAPER_FULL_CUT: [0x1d,0x56,0x00], // Full cut paper
PAPER_PART_CUT: [0x1d,0x56,0x01], // Partial cut paper
PAPER_CUT_A: [0x1d,0x56,0x41], // Partial cut paper
PAPER_CUT_B: [0x1d,0x56,0x42], // Partial cut paper
},
TEXT_FORMAT: {
TXT_NORMAL: [0x1b,0x21,0x00], // Normal text
TXT_2HEIGHT: [0x1b,0x21,0x10], // Double height text
TXT_2WIDTH: [0x1b,0x21,0x20], // Double width text
TXT_4SQUARE: [0x1b,0x21,0x30], // Double width & height text
TXT_CUSTOM_SIZE: function (width, height) { // other sizes
var widthDec = (width - 1) * 16;
var heightDec = height - 1;
var sizeDec = widthDec + heightDec;
return [0x1d,0x21,String.fromCharCode(sizeDec)]
},
TXT_HEIGHT: {
1: [0x00],
2: [0x01],
3: [0x02],
4: [0x03],
5: [0x04],
6: [0x05],
7: [0x06],
8: [0x07]
},
TXT_WIDTH: {
1: [0x00],
2: [0x10],
3: [0x20],
4: [0x30],
5: [0x40],
6: [0x50],
7: [0x60],
8: [0x70]
},
TXT_UNDERL_OFF: [0x1b,0x2d,0x00], // Underline font OFF
TXT_UNDERL_ON: [0x1b,0x2d,0x01], // Underline font 1-dot ON
TXT_UNDERL2_ON: [0x1b,0x2d,0x02], // Underline font 2-dot ON
TXT_BOLD_OFF: [0x1b,0x45,0x00], // Bold font OFF
TXT_BOLD_ON: [0x1b,0x45,0x01], // Bold font ON
TXT_ITALIC_OFF: [0x1b,0x35], // Italic font ON
TXT_ITALIC_ON: [0x1b,0x34], // Italic font ON
TXT_FONT_A: [0x1b,0x4d,0x00], // Font type A
TXT_FONT_B: [0x1b,0x4d,0x01], // Font type B
TXT_FONT_C: [0x1b,0x4d,0x02], // Font type C
TXT_ALIGN_LT: [0x1b,0x61,0x00], // Left justification
TXT_ALIGN_CT: [0x1b,0x61,0x01], // Centering
TXT_ALIGN_RT: [0x1b,0x61,0x02], // Right justification
},
BARCODE_FORMAT: {
BARCODE_TXT_OFF: '\x1d\x48\x00', // HRI barcode chars OFF
BARCODE_TXT_ABV: '\x1d\x48\x01', // HRI barcode chars above
BARCODE_TXT_BLW: '\x1d\x48\x02', // HRI barcode chars below
BARCODE_TXT_BTH: '\x1d\x48\x03', // HRI barcode chars both above and below
BARCODE_FONT_A: '\x1d\x66\x00', // Font type A for HRI barcode chars
BARCODE_FONT_B: '\x1d\x66\x01', // Font type B for HRI barcode chars
BARCODE_HEIGHT: function(height) { // Barcode Height [1-255]
return '\x1d\x68' + String.fromCharCode(height);
},
// Barcode Width [2-6]
BARCODE_WIDTH: {
1: '\x1d\x77\x02',
2: '\x1d\x77\x03',
3: '\x1d\x77\x04',
4: '\x1d\x77\x05',
5: '\x1d\x77\x06',
},
BARCODE_HEIGHT_DEFAULT: '\x1d\x68\x64', // Barcode height default:100
BARCODE_WIDTH_DEFAULT: '\x1d\x77\x01', // Barcode width default:1
BARCODE_UPC_A: '\x1d\x6b\x00', // Barcode type UPC-A
BARCODE_UPC_E: '\x1d\x6b\x01', // Barcode type UPC-E
BARCODE_EAN13: '\x1d\x6b\x02', // Barcode type EAN13
BARCODE_EAN8: '\x1d\x6b\x03', // Barcode type EAN8
BARCODE_CODE39: '\x1d\x6b\x04', // Barcode type CODE39
BARCODE_ITF: '\x1d\x6b\x05', // Barcode type ITF
BARCODE_NW7: '\x1d\x6b\x06', // Barcode type NW7
BARCODE_CODE93: '\x1d\x6b\x48', // Barcode type CODE93
BARCODE_CODE128: '\x1d\x6b\x49', // Barcode type CODE128
},
}
这是默认情况下的结果,我在另一台BT打印机上试过,打印结果相同,所以我猜型号不是问题所在。
1条答案
按热度按时间k3bvogb11#
您可以尝试使用de image.onload方法加载并解析resultByte,如下所示:
这将等待图像加载,因为文档指示EscPosEncoder