print pdf page without opening

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rlu
    New Member
    • Jan 2008
    • 1

    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:

    [CODE=javascript]win=window.open ("","","widt h=5 height=5");
    win.blur();
    win.document.lo cation="http://www.mydomain.co m/mydoc.pdf";
    win.print();
    win.close();
    [/CODE]
    2. use iframe:
    [CODE=javascript]iframe = document.create Element("IFRAME ");
    iframe.setAttri bute("id","test iframe");
    iframe.setAttri bute("name","te stiframe");
    iframe.setAttri bute("src", "http://www.mydomain.co m/mydoc.pdf");
    iframe.style.di splay = "none";
    window.document .body.appendChi ld(iframe);

    var x = document.getEle mentById("testi frame");
    x.focus();
    x.print();
    [/CODE]

    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; Aug 19 '08, 12:16 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • crocodilu2008
      New Member
      • Sep 2008
      • 9

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

      Comment

      Working...