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:

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

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);
printcommandobject.outerhtml = "";
else {

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

2-this is second code which i tried

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;

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

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

any help will be appreciated.


Updated 27-Jul-15 22:26pm
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
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>
<title>Print Test</title>
<script language="VBScript">
sub Print()
End Sub
document.write "<object id='WB' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
Click Here to Print

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.


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