How to export an InfoPath Form as a PDF from within a WinForm hosted FormControl?
I have a C# WinForm app that (among other things) hosts an InfoPath FormControl to allow users to fill out some forms. The save method provided in the WinForm app, in addition to saving the form XML, also exports the form as a PDF so that a PDF copy can be sent out via email.
All worked well when we were using InfoPath 2007. Since the company is now upgrading all machines with Office, from 2007 to 2010, I need to update the app to work with InfoPath 2010. After changing the required references everything seemed to be working fine, until the save function attempted to export the form to a PDF. The code to export the form, (which worked previously when using 2007), is shown below:
this.view.OutputForm.XmlForm.CurrentView.Export(pdfFile, Microsoft.Office.InfoPath.ExportFormat.Pdf);
OutputForm is a Microsoft.Office.InfoPath.FormControl object. When the Export method is called this exception is thrown:
InfoPath has en开发者_C百科countered an error. The operation failed.
InfoPath cannot export the form. No such interface supported
at Microsoft.Office.Interop.InfoPath.SemiTrust.View.Export(String bstrURL, String strFormat)
at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat)
at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format) ...
I can't imagine that this functionality has just been ripped from the hosted InfoPath 2010 FormControl, has it? I really hope that is not the case.
Are there any InfoPath wizards here that can point me in the right direction, (what I'm missing or an alternate solution)?
Based on the input from Artur Mustafin I'm open to hearing about alternate solutions to generating the PDF from the InfoPath Form.
A note for anyone else coming across this I found this thread on social.msdn.microsoft.com where Bruce Song states that:
...it is a known issue from the Microsoft internal bug check system and the product group is trying to fix it.
It seems, that you are using the Office Add-In for 2007 office which is extending support with PDF 2.0 file format.
You need to (re)install and update version of that add-in build for Office 2010. And everything will work seamlessly again.
Regards, Artur Mustafin
Follow the white command line at google.com followed by SaveAsPDFandXPS...
P.S.
Additionally, your Addins for Office 2007 will not work anymore for Office 2010 because COM interfaces, API has changed, some behavior of existing methods are not longer supported, other interfaces are introduced. Stay tuned on Microsoft Connect.
Hope it will help.
精彩评论