Connecting Tech Pros Worldwide Forums | Help | Site Map

print pdf page without opening

rlu rlu is offline
Newbie
 
Join Date: Jan 2008
Posts: 1
#1: Aug 18 '08
Is there a way to print a pdf document without opening it, if user just select the pdf files in the checkbox and click a button?

I tried the following two methods, but both fail.

1. open a new window:

Expand|Select|Wrap|Line Numbers
  1. win=window.open("","","width=5 height=5");
  2. win.blur();
  3. win.document.location="http://www.mydomain.com/mydoc.pdf";
  4. win.print();
  5. win.close();
  6.  
2. use iframe:
Expand|Select|Wrap|Line Numbers
  1. iframe = document.createElement("IFRAME");
  2. iframe.setAttribute("id","testiframe");
  3. iframe.setAttribute("name","testiframe");
  4. iframe.setAttribute("src", "http://www.mydomain.com/mydoc.pdf"); 
  5. iframe.style.display = "none";
  6. window.document.body.appendChild(iframe);
  7.  
  8. var x = document.getElementById("testiframe");
  9. x.focus();
  10. x.print();
  11.  
Did I miss anything? Or it is completely impossible to print pdf without opening it. Thanks a lot!

P.S. I found this forum is very helpful. It helps me solve many problems, so I posted this message first time here. Thanks for your answer in advance!

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Aug 19 '08

re: print pdf page without opening


I don't know if what you're trying will be possible (never tried it myself), but what I can say is that you should wait for the iframe to enter the DOM before trying to access it. It's not available immediately, so you could use a setTimeout and check its existence before attempting to access and print it.
Newbie
 
Join Date: Sep 2008
Location: Montreal
Posts: 9
#3: Sep 5 '08

re: print pdf page without opening


Mission impossible
The window.print() is not propagated (inherited) in your object pdf !!!!
The pdf objects has own print !!!
Reply


Similar JavaScript / Ajax / DHTML bytes