By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,644 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,644 IT Pros & Developers. It's quick & easy.

print pdf page without opening

P: 1
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!
Aug 18 '08 #1
Share this Question
Share on Google+
2 Replies


acoder
Expert Mod 15k+
P: 16,027
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.
Aug 19 '08 #2

P: 9
Mission impossible
The window.print() is not propagated (inherited) in your object pdf !!!!
The pdf objects has own print !!!
Sep 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.