Print from button on form - JScript code - WSH sendkeys - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Print from button on form - JScript code - WSH sendkeys

Last post 08-05-2009 12:53 AM by mcmadhan. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 12-24-2008 01:57 AM

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Print from button on form - JScript code - WSH sendkeys

    Hi,

    I also ask myself how can I have print button on form? I am limited to level 2 security with my forms so sometimes I try to find ways to do 'level 3' security things with level 2 methods.

    Maybe this only works for me but:

    [jScript] 

    function printFormPage()
    {
         var WshShell = new ActiveXObject("WScript.Shell");
         WshShell.SendKeys("^(p)")
    }

    Brings up the print menu! It's a simple send keys, and you can probably guess I use this to also bring up save as and save boxes too.

    If this works for you, you can possibly do many things.

    Good luck!

     

    Filed under:
  • 01-06-2009 03:38 AM In reply to

    Re: Print from button on form - JScript code - WSH sendkeys

    If you use InfoPath 2007 + c#

    - Add button to your form
    - Open the properties dialog box
    - Select Rules and Custom Code
    - Click Edit Form Code 
    - add the following line: thisXDocument.PrintOut();

    Set the Form Security to Full Trust to make sure PrintOut will work

     

    Frederik Van Lierde
    Blue InfoPath Blog  ¦  SilverSands Associate  ¦  Do you follow me already?  ¦  We work smart, not hard


    If this article was helpfull, don't forget to rate it, tnx!
  • 01-14-2009 08:31 AM In reply to

    • admot
    • Top 200 Contributor
      Male
    • Joined on 08-09-2006
    • USA
    • Posts 51

    Re: Print from button on form - JScript code - WSH sendkeys

    The problem with using thisXDocument.PrintOut(); in jscript is that it didn't bring up a dialog window. Haven't tried it in IP2007 and in C#. 

     The "WshShell.SendKeys("^(p)")" does seem to work. Whata know. I've been searching for a clean solution for this for over a year. And here it its. Thanks!

    Don't grow old regretting the things you didn't do.
  • 01-14-2009 08:46 AM In reply to

    Re: Print from button on form - JScript code - WSH sendkeys

    Yes, thanks to Skarn, we have a very nice jscript security workaround for printing via a button. Cool post!

    JScript is not as secure as C#, however, and there's a reason that managed code (aka C# and VB.NET) don't let you do this. So long as you are ok with that, it's all good! :)

    Patrick Halstead
    Project Manager at Qdabra
  • 08-03-2009 06:36 AM In reply to

    Re: Print from button on form - JScript code - WSH sendkeys

    I'm new to Infopath.
    Still don't have a clue about "how to add the mentioned Jscript in Infopath".

    Mentione JScript

    function
    printFormPage()
    {
    var WshShell = new ActiveXObject("WScript.Shell");
    WshShell.SendKeys(
    "^(p)")
    }

    Would someone help me on that (have print button on infopath form - in browser)?

    Thanks,

  • 08-04-2009 08:08 AM In reply to

    • rcant
    • Top 500 Contributor
      Male
    • Joined on 03-24-2008
    • Rochester
    • Posts 27

    Re: Print from button on form - JScript code - WSH sendkeys

     for the button you need a onclck event -- substitute your button name for button_name

     

    function button_name::OnClick(eventObj)

     {
    var WshShell = new ActiveXObject("WScript.Shell");
    WshShell.SendKeys(
    "^(p)")
    }

  • 08-05-2009 12:53 AM In reply to

    Re: Print from button on form - JScript code - WSH sendkeys

    Hi,

    Thanks for replying. I'm new to infopath. Please bare with me for asking too much.

    For the infopath form for which I need this print button now uses C#.net as code behind.
    If I have to convert that to JScript. Would you please let me know how to do that?

    Thanks,
    M

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.