Я хочу отправить данные, которые уже отформатированы, в плагин Cordova Bluetooth этот плагин здесь
Я использую эти команды .js для принтера, но мне не удалось выровнять текст влево и вправо в одной строке, как Всего ------------------ --------------------- $ 70
Общая сумма должна быть сдвинута вправо, а общая сумма слева
вот код, который я написал.
import { Component } from '@angular/core'
import { NavController } from 'ionic-angular'
import { commands } from './../../providers/printcommand/printcommand'
declare var bluetoothSerial: any
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
devicelists: any
constructor(public navCtrl: NavController) {
}
ionViewDidLoad(){
this.isEnabled()
this.listDevices()
}
listDevices() {
bluetoothSerial.list(devices => this.devicelists = devices)
}
isEnabled(){
bluetoothSerial.enable(
function() {
alert("Bluetooth is enabled")
},
function() {
alert("The user did *not* enable Bluetooth")
}
)
return true
}
connect(data){
// alert(data)
bluetoothSerial.connect(data,
function(result){
console.log("Success")
alert('Bluetooth printer connected')
})
}
desconnect(data){
bluetoothSerial.disconnect(function(data){
console.log("Success")
alert('Bluetooth printer desconnected')
},function(err){
console.log("Error")
alert(err)
})
}
// Call this method for printing
print(){
//Data to be printed presented in jsonData format.....
let jsonData = [
{ id: 1, name: "Soda", price: 3.12},
{ id: 2, name: "Beer", price: 6.50},
{ id: 3, name: "Margarita", price: 12.99}
]
const items = item => ({name: item.name, price: item.price})
let product = jsonData.map(items)
//Calculate the total price of the items in an object
let totalPrice = jsonData.reduce((acc,next) => acc + next.price, 0)
let company = "Apps Dev"
let cashier = "Mathews M"
let amoutntReceived = 400
let change = amoutntReceived - totalPrice
let receipt = ""
receipt += commands.TEXT_FORMAT.TXT_2WIDTH
receipt += "\x1b\x45\x01 \x00 Welcome to " +company+ "\x1b\x45\x00"
receipt += '\n'
receipt += commands.HORIZONTAL_LINE.HR_58MM
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_NORMAL
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Cashier: "
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += cashier
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Items Bought:"
receipt += '\n'
for(var pro in product) {
if (product.hasOwnProperty(pro)) {
var item = product[pro]
var itemName = item.name
var itemPrice = item.price
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += itemName
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += itemPrice
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
}
}
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Total:"
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += "K" + totalPrice
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Amount Received:"
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += "K" +amoutntReceived
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Change:"
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += "K" + change
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Payment Type:"
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += commands.TEXT_FORMAT.TXT_ALIGN_LT
receipt += "Cash"
receipt += commands.TEXT_FORMAT.TXT_ALIGN_RT
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_FONT_A
receipt += commands.HORIZONTAL_LINE.HR2_58MM
receipt += '\n'
receipt += commands.TEXT_FORMAT.TXT_FONT_A
receipt += '\x1b\x61\x01'+ 'Outsource Now 2018' + '\x0a\x0a\x0a\x0a' //The unicode symbols are for centering the text
// Write data to the printer now
this.printText(receipt)
}
printText(receipt){
bluetoothSerial.write(receipt, function(data){
console.log("Success")
alert(`Work printed.`)
},function(err){
console.log("Error")
alert(err)
}, "String to Print")
}
}
import { commands } from './../../providers/printcommand/printcommand'
имеет команды PRINTER из commands.js команды для форматирования текста
Любая помощь, я буду очень признателен