Thanks micvos. Finally I got a single reply from this forum.This is for the first time I need to wait for many days for a reply in this forum.
Thanks for your mind. Let me give some more details. Infopath form templates has .xsn. But when we fill the form and save it, it is stored as .xml.
can u suggest any method for converting this .xml with xsl to pdf?
I already got one add-in from microsoft which can do the same. But I want to do it in a button click.This is not possibile with add-in, because , we need to go to file menu and click on 'Export to pdf' option.
I am now thinking in a way to use crystalreport for the same. Can you give any input?
thanks in advance...
U can get help regrading how to Add the Form Control to the Visual Studio 2005 Project in this link http://msdn2.microsoft.com/en-us/library/ms406041.aspx.
Install 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS u can get addin from this link
After adding the FormControl to the windows application and installing Microsoft Add-in.
This code helps to conver the infopath(*.xml) file to the PDF.
// file refers the source file path
// finalFilename is the destination file path
MessageBox.Show("Confirm of exporting Document" + finalFileName);
FormControl1.XmlForm.CurrentView.Export(finalFileName + ".pdf", Microsoft.Office.InfoPath.ExportFormat.Pdf)
instead of PDF there are two option available
By default there is no option to convert the infopath file to PDF. So Microsoft gives addin to overcome the issue you can download the 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS from this link http://www.microsoft.com/downloads/details.aspx?familyid=4D951911-3E7E-4AE6-B059-A2E79ED87041&displaylang=en
Once you installed then there is a option in the file menu export to PDF and XPS in the Infopath 2007.
Add the Form Control to Windows Application
Form control is a COM object, so by default it will not available in toolbox. So the First step is to add the Form control to the toolbox under the general tab.
These are the below steps to add a FormControl on the Toolbox.
1) Toolbox -> Go to General Tab -> Right click on it
2) Select ChooseItems you will get window (Choose Toolbox items) click Browse button
3) Go to path ("E:\Program Files\Microsoft Office\Office12") most probably this may the path oterwise go to loaction where the Office 2007 is installed
4) There you can find the Microsoft.Office.InfoPath.FormControl.dll select the dll
5) Know you cand find the FormControl under the tab of .Net FrameWork Components(select the FormControl and Click OK)
6) Use can see FormControl in the General tab.
7) Drag and drop in Windows Application
In the Button click Event
1) FormControl1.Open(SourceInfopath) (ie Opening a infopath form in FormControl)
2) Application.DoEvents() (try with Application.DoEvents() if u get error like View is not ready then place a MessageBox and just pop
some Message)3) FormControl1.XmlForm.CurrentView.Export(Destinationpath, Microsoft.Office.InfoPath.ExportFormat.Pdf )
you can ask what is the use of the second line. Here is the trick lies FormControl is the COM Object and it takes time to load. So we are giving some time to complete the Formload operation(By giving DoEvents() or by prompting MessageBox). FormControl1.open() doesn't return anything we don't have any option to know wheather FormControl loaded the infopathForm.
Most of us can get View is not ready error this is beacuse of the above reason. Because formcontrol takes time to load within that period we may try to Export operation. So in this case we may get View is not ready to avoid use the above operation
If Some one find the better way of tackling the above said error let me know
A low tech way to convert an Infopath file to pdf is to copy & paste the form into MS Word, "save as" html then use Adobe Acrobat to convert the new file to a pdf. Most of the fields function properly and save properly. You may need to add text boxes since those don't seem to carry over. This method is a little cumbersome and not real fast but does work. If your form is large, you may need to copy and paste into several smaller documents. But you can combine them in the final Acrobat version.
So let me clarify just for my understanding. I will need to create a activex/com component to do the saving as a pdf? Also is there a way to use the submit button to export/save the pdf programatically to a sharepoint url?
Once again thank you for your all your help.
Forgive my lack of knowledge of this.
Ok so in reply to my own question. Here is a better way without a active x com object.
I know I am sorry for the jscript but here it goes.
Add this to the onclick event and have full trust enabled.
You may use any image capturing program, such as SNAGIT
I had the same problem with infopath to pdf conversion, i tried to use microsoft Microsoft Save as PDF or XPS, but i had a lot of problems with page breaks, positioning of an elements, tables etc. I tried also to use xslt extracted from XSN file to convert it to html and then to pdf - this was to complicated and i had some weird results. I tried also external components ( i tried all that google returns from search :) ). Thing is that all this methods are good in case of small and not complicated infopath forms. My form printout has up to 100 pages, a lot of pictures, attachements tables, and runtime evaluated expression boxes (for multilanguage support). Finally i used InfoPathToPdf.exe from a-pdf, and i just run it from my code. It uses just a virtual priter and INFOPATH - maybie it is not so elegant - but it works ! I find it as the best solutiuon for infopath to pdf conversion on the market and it costs something about 30$
This code has worked for me. I added a button called "Print" to my InfoPath form and programmed the following against it (VB.Net):
Public Sub Print_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
Dim filename As String
Dim nameNode As XPathNavigator
nameNode = MainDataSource.CreateNavigator().SelectSingleNode("insert the XPath to the field on which you want the name of the pdf based on", NamespaceManager)
filename = nameNode.Value + ".pdf"
Me.CurrentView.Export("C:\" + filename, ExportFormat.Pdf)
Check out the following posts:
- Batch print InfoPath Forms using the PDF Converter for SharePoint
- Converting InfoPath forms including all attachments to a single PDF file
- Controlling which views to export to PDF format in InfoPath
- Using SharePoint Forms Services to convert InfoPath forms to PDF format
- Converting Office files to PDF Format using a Web Services based interface
- Using the PDF Converter from a SharePoint workflow
- Proposed as answer by XristosK Thursday, September 29, 2011 2:38 PM
I am getting problem at convert a infopath template to XMl using vsta.
one another Q. if i want to conert preprinted form means any paper form which i had scan & import to
infopath then how to edit that one or directly convert in XML
if got some stuff mail me firstname.lastname@example.org
I don't know the method about code, maybe there is proper one can fix the problem.
I just want to show my way to export as pdf file. I think the "save as PDF/XPS" feature can't deal with the infopath so well as there are many tables, images, blabla... So actually you can use a print driver-PDF Creator
For the infopath file is printable files. In the print dialog, choose he pdf creator as the virtual printer, tick the print to file checkbox.
Then it will be added to pdf creator and you can further define the settings like security and compression to get expected files. Then wait for the output opened in the adobe reader.
Of course capture it as image file then export to pdf file is feasible by the creator but it's time-consuming if have a bunch file to go.
Never too old to learn
If you are trying to generate a pdf from the xml, you could use http://itextpdf.com/ to generate your pdf on the fly.
The basic logic will be :
- Parse your InfoPath XML
- Process the XML to generate a PDF whith itextpdf library
Hope this helps.
- Proposed as answer by XristosK Thursday, September 29, 2011 2:39 PM