Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Printing PDF in browser window

    Hi,
    On click of a button, i am opening a PDF doc in the browser window. I want to seamlessly issue the print command when the page is opened so that the user does not see the pdf ; rather he should be directly taken to the print settings screen.

    I tried using the below code ...

    var win = window.open(<pdf doc url>);
    win.print();
    win.close();

    This opens the pdf in a new window but does not issue the print command.
    The domain name for both the base page url and the pdf url is the same (localhost).

    Any ideas on this will be highly appreciated!!

    Regards,
    Jacob

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Have you tried

    window.open(<pdf doc url>);
    window.print();
    window.close();

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by Philip M View Post
    Have you tried

    window.open(<pdf doc url>);
    window.print();
    window.close();
    That will print the window that opens the pdf.

    You won't be able to call the print() method (or any other method for that matter) of the window object if that window contains non-HTML page.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You need the JavaScript within the PDF if you want that to happen.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •