将便携式蓝牙打印机与我的cordova应用程序连接,并希望发送一些文本进行打印。有没有可用的插件
答案 0 :(得分:0)
总结讨论的替代解决方案;
<强> 1。 PDF生成:使用jsPDF https://github.com/MrRio/jsPDF
<强> 2。使用文件插件在本地保存。 http://docs.phonegap.com/en/edge/cordova_file_file.md.html
var pdf = new jsPDF('p', 'pt', 'letter');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
console.log(fileSystem.name);
console.log(fileSystem.root.name);
console.log(fileSystem.root.fullPath);
fileSystem.root.getFile("test.pdf", {
create: true
}, function(entry) {
var fileEntry = entry;
console.log(entry);
entry.createWriter(function(writer) {
writer.onwrite = function(evt) {
console.log("write success");
//Show YES NOT Popup
//alert("PDF is generated successfully");
$("#popupPrint").popup("open");
};
console.log("writing to file");
writer.write(pdfOutput);
}, function(error) {
alert("Unexpected error occured!");
console.log(error);
});
}, function(error) {
alert("Unexpected error occured!");
console.log(error);
});
},
function(event) {
alert("Unexpected error occured! code : " + evt.target.error.code);
console.log(evt.target.error.code);
});
第3。和文件的开放方法;使用以下插件; https://github.com/pwlin/cordova-plugin-file-opener2
var devicePlatform = device.platform;
if (devicePlatform == "Android") {
cordova.plugins.fileOpener2.open(
'file:///mnt/sdcard/test.pdf',
'application/pdf', {
error: function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success: function() {
console.log('file opened successfully');
}
}
);
}
<强> 4。用户单击默认PDF查看器的打印按钮,选择配对的打印机设备,然后完成操作。