简体   繁体   中英

Print with Google Chrome Extension

I am trying to choose the printer in the default chrome dialog via a Chrome Extension, but have not be to get PrinterProvider events to trigger at all in my extension. Is PrinterProvider the correct way to go about this? If so, any examples would be helpful. Is it possible to select which printer name shows up in the printer dropdown?

For example, I have the following in my background.js and the event is never triggered:

chrome.printerProvider.onPrintRequested.addListener(async (chromePrintJob, printRequestCallback) => {
  console.log("Print requested");
  await chromePrintJob.document.text();
  console.log("resolve");
  printRequestCallback("OK");

});

I am trying to choose the printer in the default chrome dialog via a Chrome Extension

This isn't possible. Chrome does not give extensions that kind of control over its UI. Moreover, default printer selection is typically an OS-level setting.

Is PrinterProvider the correct way to go about this?

No, that interface allows an extension to act as a printer, not to modify existing printers. In other words, you can use PrinterProvider in your extension to add new printers the user can select in the print dialog window and handle print jobs sent to your custom printer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM