Google Chrome App print slient

浪尽此生 提交于 2019-12-11 08:16:06

问题


It's possible in a Google Chrome App print silent like when Chrome is running in kiosk mode?

--kiosk --kiosk-priting

回答1:


When you print something in kiosk mode things gets printed automatically to the default printer, silently. Simply call print() in the context of the page you want to print. If you want to print from the background/event page you will need to do something like the following:

// ...
function closePrint () {
  document.body.removeChild(this.__container__);
}

function setPrint () {
  this.contentWindow.__container__ = this;
  this.contentWindow.onbeforeunload = closePrint;
  this.contentWindow.onafterprint = closePrint;
  this.contentWindow.print();
}

function printPage (sURL) {
  var oHiddFrame = document.createElement("iframe");
  oHiddFrame.onload = setPrint;
  oHiddFrame.style.visibility = "hidden";
  oHiddFrame.style.position = "fixed";
  oHiddFrame.style.right = "0";
  oHiddFrame.style.bottom = "0";
  oHiddFrame.src = sURL;
  document.body.appendChild(oHiddFrame);
}
//...

Simply call printPage, passing a URL, to print something.

Code from MDN




回答2:


I found a temporary (maybe not temporary :) ) solution for this subject:

SOLUTION FOR CHROME APP

  1. Install your App to chrome

  2. Create shortcut from this app to desktop.

  3. Right click > Properties > Edit Target Textbox like the below (you will add "--kiosk-printing" parameter )

    Before Edit: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" --app-id=eoaefbbbpgcbhgeilphgobiicboopknp

    After Edit: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk-printing --profile-directory="Profile 2" --app-id=eoaefbbbpgcbhgeilphgobiicboopknp

  4. Absolutely restart chrome for effect (close every tabs and windows on chrome)
  5. Try to print

  6. If you want to remove default header and footer (page address and date) : Open normal chrome print something > on printer preview > More Settings > uncheck "Header and Footer". Chrome ll remember this settings always.

(In fact chrome must provide this property on manifest.json too, but i couldnt find yet)



来源:https://stackoverflow.com/questions/22357398/google-chrome-app-print-slient

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