mikedopp.net

doppNet
posts - 56, comments - 8, trackbacks - 1

InfoPath 2007 Printing and exporting to pdf using jscript

So I got a wild hair like I do and thought hey I know jscript and infopath loves jscript...

I guess. I and my fellow developers devised a bullet proof way to do all of these on one button click.**applause** **cheering** **crying**
Check this out...
Make sure Infopath 2007 form is set to full trust with a signed cert (self signed so you don't have to buy anything else.) Also make sure that every machine that touches this form has the "Allow Fully Trusted forms to run on this computer" or the pdf and printing function will not work.

**A warning about jscript it is very sensitive so make sure you put capitals and lower case letters where they should go.**
First of all lets create the onclick event next lets add our functions.
Lets start off with the export to pdf feature.

   1:  {
   2:         XDocument.View.Export("C:\\MyView.pdf", "PDF");
   3:            }  
   4:  Easy yes? Very Easy.
   5:  Now lets print
   6:  {
   7:       XDocument.PrintOut();
   8:       }    
   9:  More Easy code.
  10:  Put it all together and...
  11:  if (XDocument.Errors.Count > 0)
  12:  {XDocument.UI.Alert("Required information is missing.")
  13:  return;
  14:  }
  15:  if (eventObj.ReturnStatus = true);
  16:  {XDocument.UI.Alert("Form was uploaded succesfully.");
  17:  }
  18:  try
  19:  {
  20:  Application.ActiveWindow.Close(true);
  21:  }
  22:  catch(e)
  23:  {
  24:  XDocument.UI.Alert(e.description);
  25:  }

This tells you  that you have successfully uploaded/saved the form and closes infopath.

   1:  function YourButton::OnClick(eventObj)
   2:  {
   3:       {
   4:         XDocument.View.Export("C:\\MyView.pdf", "PDF");
   5:       }
   6:      {
   7:       XDocument.PrintOut();
   8:       }    
   9:          if (XDocument.Errors.Count > 0)
  10:  {XDocument.UI.Alert("Required information is missing.")
  11:  return;
  12:  }
  13:  if (eventObj.ReturnStatus = true);
  14:  {XDocument.UI.Alert("Form was uploaded succesfully.");
  15:  }
  16:  try
  17:  {
  18:  Application.ActiveWindow.Close(true);
  19:  }
  20:  catch(e)
  21:  {
  22:  XDocument.UI.Alert(e.description);
  23:  }
  24:  }

So here is the code put together. Enjoy!
Still waiting for some answers from the MVP's
Hello guys are you there?

Print | posted on Thursday, April 19, 2007 3:31 PM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 2 and type the answer here:

Powered by: