( This is through Grease/Tampermonkey ).
Here’s a print function for a kiosk using the Chrome beta browser:
$("#autoCheckOrder button").click ( function () {
var newWin = window.open ("");
newWin.document.write ( "<!DOCTYPE html>" );
newWin.document.write( "<html>" );
newWin.document.write( "<head>" );
newWin.document.write( "<title>" );
newWin.document.write( "</title>" );
newWin.document.write( "<style>" );
newWin.document.write( "@media print { " );
newWin.document.write( "body { " );
newWin.document.write( "background-color: white;" );
newWin.document.write( "width: 55mm;" );
newWin.document.write( "position: absolute;" );
newWin.document.write( "top: 0;" );
newWin.document.write( "left: 0;" );
newWin.document.write( "padding: 0px;" );
newWin.document.write( "font-size: 14px;" );
newWin.document.write( "line-height: 18px;" );
newWin.document.write( "}" );
newWin.document.write( "}" );
newWin.document.write( "</style>" );
newWin.document.write( "</head>" );
newWin.document.write( "<body>" );
newWin.document.write ( loanHTML );
newWin.document.write( "</body>" );
newWin.document.write( "</html>" );
if(newWin.print()) {
newWin.close();
} else {
newWin.close();
}
});
It grabs a table from the a page listing all items, then creates a
‘receipt’. The receipt is then printed. This worked perfectly for a while, now it only prints the first item.
I have tried the following with absolutely no results:
- Using page-break-after: always
- Placing receipt in div with the above CSS rule
- Reinstalling the printer
- Paper reduction settings for printer
The crazy thing is that it used to print all items flawlessly and now it doesn’t. I even re-installed the script from a backup just to be sure.
No idea where to go from here. All content shows in print preview, but only the first item prints. ‘Header and footer’ setting only makes things worse, not better.
UPDATE
I changed the HTML sent to the printer and it works. Still not sure if it’s entirely valid but it’s printing. I’ll know what to fix if it stops printing. Thanks for the input!
The only plausible explanation I can see is that your loanHTML variable is empty or undefined.
Demo: http://jsfiddle.net/waitinforatrain/bMzUt/2/
Comment out the
var loanHTMLline and run again, and you’ll see what I mean.