Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old August 18th, 2008, 08:14 PM
rlu rlu is offline
Newbie
 
Join Date: Jan 2008
Posts: 1
Default print pdf page without opening

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!

Last edited by acoder; August 19th, 2008 at 01:16 PM. Reason: Added [code] tags
Reply
  #2  
Old August 19th, 2008, 01:56 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,964
Default

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.
Reply
  #3  
Old September 5th, 2008, 03:23 AM
Newbie
 
Join Date: Sep 2008
Location: Montreal
Posts: 8
Default

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.