Nuno Santos
Nuno Santos

Reputation: 167

Google Chrome App print slient

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

--kiosk --kiosk-priting

Upvotes: 1

Views: 4117

Answers (3)

Bang Andre
Bang Andre

Reputation: 537

I have setting:

  1. "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk-printing --profile-directory="Profile 1"

  2. Website testing with jquery library https://printjs.crabbly.com/ Chrome Popup printer auto close and not print out..

Upvotes: 0

kadir950
kadir950

Reputation: 117

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)

Upvotes: 0

0xcaff
0xcaff

Reputation: 13681

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

Upvotes: 0

Related Questions