如何在 Ionic 3 中使用蓝牙打印机打印 PDF



>我在php中创建了一个pdf文件。我想使用蓝牙串行打印机插件在 ionic 3 中打印该 pdf 文件。为此,我编写了一些代码。蓝牙串口插件直接不支持打印pdf数据。因此,为了避免此问题,我使用本机打印机插件进行打印,对于连接,我使用蓝牙插件。但它不起作用。你能不能帮我怎么做。

goToTestprint()
{
----------
this.bluetoothSerial.isEnabled().then(()=>{
this.storage.get('printeraddress').then((getdata) => {
if(getdata!=undefined && getdata!='undefined')
{
this.printercode=getdata;
if(this.printercode!='')
{
let xyz=  this.bluetoothSerial.connect(this.printercode).subscribe((data) => {
let toast = this.toastCtrl.create({
message: 'printer is connected',
duration: 10000,
position: 'top'
});
toast.present();
let options: PrintOptions = {
name: 'MyDocument',
printerId:this.printercode,
duplex: true,
landscape: true,
grayscale: true
};
var filepath='file://'+this.services.gettestbaseurlweb()+'admin/images/workorder/'+'INV1908172193'+'.pdf';
this.printer.print(filepath, options).then(onSuccess => {
console.log("on success print" +JSON.stringify(onSuccess));
let mno=this.alerCtrl.create({
title:"Print SUCCESS!",
buttons:['Dismiss']
});
mno.present();
xyz.unsubscribe();
}, onError => {
let toast = this.toastCtrl.create({
message: 'problem inprinting'+JSON.stringify(onError),
duration: 10000,
position: 'top'
});
toast.present();
console.log("on error print" +JSON.stringify(onError));
});
}, (error) => {
console.log('not Connected', error);
let toast = this.toastCtrl.create({
message: 'printer is not connected'+this.printercode,
duration: 5000,
position: 'top'
});
toast.present();
});
}
}   
else 
console.log('printer code'+this.printercode);
});
},(error)=>{
console.log('bluetooth is not enabled'+error);
let toast = this.toastCtrl.create({
message: 'Sorry..! Bluetooth is not truned on, so printing is not possible.',
duration: 10000,
position: 'top'
});
toast.present();
});   
}

我建议,您尝试将用于在pdf文件中生成的数据传递到您的移动应用程序,然后尝试使用它并对其进行格式化,以便由插件打印。

最新更新