Google JavaScript API - chrome.printerProvider

做~自己de王妃 提交于 2019-12-24 05:16:26

问题


I'm trying to make a printing extension, that can configure printing options and send a print job to the attached printers.

I have made sample extensions other than printing, but the printing API has no methods, just events, so it's not working for me.

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).

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

Can anyone tell me what am i doing wrong? or guide me to a useful resources?


回答1:


The printer you're providing has to register itself at onGetPrintersRequested event first.

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.



来源:https://stackoverflow.com/questions/32459473/google-javascript-api-chrome-printerprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!