Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I tried print pdf from browser via javascript.

it prints with dialog box . i tried to skip this dialog box but failed in doing so.

i tried several codes like

1 -- // this also opens dialog box

JavaScript
function print1()
{
if (navigator.appname == "microsoft internet explore")
{
var printcommand = '<object id="printcommandobject" width=0 height=0 classid="clsid:8856f961-340a-11d0-a96b-00c04fd705a2"></object>';
document.body.insertadjacenthtml('beforeend', printcommand);
 document.all.printcommandobject.execwb(6,-1);
printcommandobject.outerhtml = "";
}
else {
window.print();
}
}
</script>

<button onclick=print1()>Try it</button>

2-this is second code which i tried

<script>
function btn_print_onclick() {
  factory.printing.header = "This is MeadCo";
  factory.printing.footer = "Printing by ScriptX";
  factory.printing.portrait = false;
  factory.printing.leftMargin = 1.0;
  factory.printing.topMargin = 1.0;
  factory.printing.rightMargin = 1.0;
  factory.printing.bottomMargin = 1.0;
  factory.printing.Print(false);
}
</script>


</head>
<body>
   <button onclick="btn_print_onclick()">Print report</button>
</body>


3 - also tried some links but they also didn't work for me

http://forums.asp.net/t/1364879.aspx?Avoid+Print+dialog+box+while+printing+webpage

http://www.webdeveloper.com/forum/showthread.php?174029.html

http://justtalkaboutweb.com/2008/05/09/javascript-print-bypass-printer-dialog-in-ie-and-firefox/

http://scriptx.meadroid.com/community-support/community-forum/general/2014/1/the-problem-of-scriptx-in-ie8.aspx


http://codeverge.com/asp.net.getting-started/avoid-print-dialog-box-while-printing/726740

https://gist.github.com/cchitsiang/7349218

http://www.codeproject.com/Questions/784656/Printing-in-one-click-I-dont-want-print-setup-dial

any help will be appreciated.

Thanks

Sushil
Posted
Updated 27-Jul-15 22:26pm
v2
Comments
Richard MacCutchan 28-Jul-15 3:26am    
You are not allowed to print direct on the client system. The user may not want the data printed.
Patil@300 28-Jul-15 6:16am    
Actually we wants the print directly to the browser send which are default connected printer without opening any popup
Richard MacCutchan 28-Jul-15 8:54am    
Well you are not allowed to do that as it would allow the browser to make decisions which belong to the user.
Philippe Mori 28-Jul-15 21:41pm    
It make no sense at all. If it was possible, then there would be abuse of that.

1 solution

There is no way to print silently on client machine - otherwise I would print the 'War and Peace' on your local printer right now!!!
 
Share this answer
 
Comments
Richard MacCutchan 28-Jul-15 9:26am    
But I already read that. How about A la recherche du temps perdu?
Kornfeld Eliyahu Peter 28-Jul-15 9:28am    
Fill the tray up!!!
Patil@300 29-Jul-15 11:46am    
i had done silent print code but this only works on IE with Genuine window if window is not activated then this code fails.
here is my code
<!DOCTYPE html>
<html>
<head>
<title>Print Test</title>
<script language="VBScript">
sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object id='WB' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>
</head>
<body>
<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
Click Here to Print
</body>
</html>

any help why it work with activated window only
Kornfeld Eliyahu Peter 29-Jul-15 14:39pm    
It does not work even newer IE - as ActiveX is disabled by default (or banned even later)...
It also assumes that VBScript installed and enabled - which is not in most, standard clients...
It also can be a thread problem (as the ActiveX class is single threaded and not all web activities are)...
In any case it is very unwise to use such a code...
Patil@300 30-Jul-15 2:28am    
yes i understand these points but its my requirement that i don't want to open printDialog every time i have print many documents and its becomes iritating for me that click on print button on browser and then click on print button of printDialog for one printing. thats why i wanted to not open the printDialog and its working on IE but only if window is activated.
I don't understand why its not working for non activated windows.
can you please suggest me why this is happening and how can i resolve this.

thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900