How to print without preview dialog box using javascript in laravel

4.2k Views Asked by At

I am working on the receipt print when i click print i am expecting it to be print directly without the print preview dialog box.

While searching for this most of the answers were configure the browser setting.

Can it will be done programmatically i am using laravel for my project

Script used for Printing

<script type = 'text/javascript'>  
  window.onload = function(){ window.print(); }
</script>
1

There are 1 best solutions below

0
Tayyab mehar On

This article can help you pricing directly to client printer without dialogue box.

https://www.neodynamic.com/articles/Print-HTML-from-Javascript-to-client-printer-without-print-dialog-silently/

or use following script if your browser supports It.

<form> <input type="button" value="Print Page" onClick="window.print()"> </form> <script language="VBScript"> // THIS VB SCRIP REMOVES THE PRINT DIALOG BOX AND PRINTS TO YOUR DEFAULT PRINTER Sub window_onunload() On Error Resume Next Set WB = nothing On Error Goto 0 End Sub Sub Print() OLECMDID_PRINT = 6 OLECMDEXECOPT_DONTPROMPTUSER = 2 OLECMDEXECOPT_PROMPTUSER = 1 On Error Resume Next If DA Then call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1) Else call WB.IOleCommandTarget.Exec(OLECMDID_PRINT ,OLECMDEXECOPT_DONTPROMPTUSER,"","","") End If If Err.Number <> 0 Then If DA Then Alert("Nothing Printed :" & err.number & " : " & err.description) Else HandleError() End if End If On Error Goto 0 End Sub If DA Then wbvers="8856F961-340A-11D0-A96B-00C04FD705A2" Else wbvers="EAB22AC3-30C1-11CF-A7EB-0000C05BAE0B" End If document.write "<object ID=""WB"" WIDTH=0 HEIGHT=0 CLASSID=""CLSID:" document.write wbvers & """> </object>" </script>