Google JavaScript API - chrome.printerProvider [英] Google JavaScript API - chrome.printerProvider
问题描述
我尝试制作打印扩展程序,可以配置打印选项并将打印作业发送到连接的打印机。
I'm trying to make a printing extension, that can configure printing options and send a print job to the attached printers.
打印,但打印API没有方法,只是事件,所以它不适合我。
I have made sample extensions other than printing, but the printing API has no methods, just events, so it's not working for me.
这是我的脚本(Event.js):
Here is my script (Event.js):
chrome.printerProvider.onPrintRequested.addListener(
function( printJob, callback){
var str = printJob.printerId + " , " + printJob.title ;
alert('str: '+ str);
console.log('str: '+str);
appendToLog('str: '+ str );
});
function callback(infos){
console.log('Printing Completed!');
}
正如我从文档中理解的那样,这应该在打印事件时触发。但是当我打印时,没有任何反应(它们没有触发)。
As I understood from the documentation, this should be triggered on printing events. But when i print, nothing happens (they are not triggered).
这是我的manifest.json的一部分:
Here is part of my manifest.json:
"background": {
"scripts": ["event.js"],
"persistent": false
},
"permissions": [
"printerProvider"
]
Google PrintProvider JS API: https://developer.chrome.com/extensions/printerProvider
Google PrintProvider JS API: https://developer.chrome.com/extensions/printerProvider
谁能告诉我我做错了什么?或指导我一个有用的资源?
Can anyone tell me what am i doing wrong? or guide me to a useful resources?
推荐答案
您提供的打印机必须在 onGetPrintersRequested
事件优先。
The printer you're providing has to register itself at onGetPrintersRequested
event first.
您是否理解此API的用途?它不会允许您修改现有打印机的打印设置。这是一种驱动程序界面,为Chrome提供了一个新的打印机(因此它的名字)。
Do you understand the purpose of this API? It will not allow you to modify print settings for existing printers. It's kind of a "driver" interface to provide (hence the name) a new printer to Chrome.
这篇关于Google JavaScript API - chrome.printerProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!