1

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

--kiosk --kiosk-priting
Nuno Santos
  • 167
  • 2
  • 8
  • What do you mean by print? Print to printer? Print to `console`? – 0xcaff Mar 12 '14 at 16:37
  • Yes, print to printer. Something like this [link](http://support.vendhq.com/entries/21006382-Enable-kiosk-silent-printing-for-Google-Chrome-on-Windows-Video-) but as Google Chrome App. Thanks! – Nuno Santos Mar 12 '14 at 17:29
  • You want to print from a background/event page, right? – 0xcaff Mar 12 '14 at 17:32
  • Exactly,from a background/event page to the default printer. – Nuno Santos Mar 12 '14 at 17:48
  • Is there a possibility of adding an [application/device in the environment which can listen to WebSocket events](http://stackoverflow.com/a/28783269/3196753)? – tresf Oct 27 '16 at 05:22

3 Answers3

0

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

0xcaff
  • 13,085
  • 5
  • 47
  • 55
  • Ok, that it's util for background event but my problem is the print preview dialogue is open and need the user action to confirm de printing. When you're using chrome in --kiosk --kiosk-priting print starts automatically. I want to do this but in a Chrome Google App. – Nuno Santos Mar 12 '14 at 18:53
  • Start chrome with the `--kiosk` and `--kiosk-priting` and then open the app and print. That works, right? – 0xcaff Mar 12 '14 at 18:54
  • Yes it works, but it's something that I don't want because is one more thing that user need to do. I was searching something like Websockets and Network Communication as mentioned here http://stackoverflow.com/questions/19217687/is-it-possible-to-access-printer-installed-in-network-in-google-chrome-packaged?rq=1 Thanks! – Nuno Santos Mar 12 '14 at 19:15
  • You simply configure your remote printer and set it as the default. No web sockets required. – 0xcaff Mar 12 '14 at 19:29
  • How to do that to avoid print preview confirmation? – Nuno Santos Mar 13 '14 at 10:34
  • Start chrome with the `--kiosk` and `--kiosk-priting` flags! – 0xcaff Mar 13 '14 at 15:57
0

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)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kadir950
  • 117
  • 12
0

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

Bang Andre
  • 471
  • 7
  • 11