How to convert an infopath file pdf RRS feed

  • Question

  • Hi,


    I have  a requirement to convert an infopath file to pdf.It's very urgent, friends.

    I have no idea about. Is there any way of doing so through code?..


    Thanks in advance...


    Friday, March 2, 2007 5:02 PM

All replies

  • Of course it can be done in code. But it involves a lot of code and quit some experience with both xsn and pdf. If you need it urgently try googling wether such a converter already exists or forget about it.
    Wednesday, March 7, 2007 12:28 PM
  • 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...



    Thursday, March 8, 2007 5:57 AM
  • Now I'm not really sure what you want. Do you want to convert a infopath document(xsn) to pdf or do you want to convert a filled out form into something printable.
    Thursday, March 8, 2007 9:32 AM
  • Hi

    An filled out form comes to our application. The template form is >xsn.We need to convert tothe filled out form to  pdf. That's the actual requirement.



    Thursday, March 8, 2007 11:05 AM


              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.

    using Microsoft.Office.InfoPath;

    using Microsoft.Office.InfoPath.FormControl

    // 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

    XPS Microsoft.Office.InfoPath.ExportFormat.Xps

    MHT Microsoft.Office.InfoPath.ExportFormat.Xps


    Thursday, March 22, 2007 2:39 PM
  • coolmadhan123,

      can you explain the form control better? Thanks. Still working hard on how to do this in infopath 2007.

    thanks in advance.


    Thursday, March 29, 2007 9:02 PM
  • Hi Mikedopp,


              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.


    Programmatic Approach


     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






    Friday, March 30, 2007 9:14 AM
  • 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.

    Friday, March 30, 2007 1:32 PM
  • 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.

    Tuesday, April 3, 2007 4:13 PM
  • Thank you for your help. Just to clarify. Is there a way to export or save the form as a pdf and save it to a sharepoint url within a submit button without activex/com ? Let me know.
    Thanks again.
    Tuesday, April 3, 2007 4:30 PM
  • 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.
    XDocument.View.Export("C:\\MyView.pdf", "PDF");

    More at
    Thursday, April 12, 2007 2:29 PM
  • I have browser enabled infopath forms saved in a form library. I need to export these forms to pdf at run time so that to send those pdfs as attchemnt in email.


    Will form control will work in this scenario?


    Any Ideas?



    Thursday, December 27, 2007 6:52 AM
  • MOSS_Sharepoint

    Did you find a solution for this? I'm also having this problem.

    Thanks for your reply
    Wednesday, March 3, 2010 2:05 PM
  • Hi Mikedopp,

    i am doing something similar in Infopath 2007. where in the edit form code would i place that entry

    Thursday, March 18, 2010 9:50 AM
  • Hi,

    Do you got any solution?



    Tuesday, April 13, 2010 5:03 AM
  • Hi,

    You may use any image capturing program, such as SNAGIT




    Friday, May 14, 2010 12:55 AM
  • hello there,

    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$


    Sunday, May 16, 2010 2:19 PM
  • Can you please tell me how to use A-PDF from code, I am trying to use it from code and it hangs in waitforexit line(I am calling it from .net environment)




    Monday, June 14, 2010 3:53 AM
  • 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)

    Tuesday, June 29, 2010 4:35 PM
  • Hi, sory for the late replay, if a-pdf hangs it means that form is not opening correctly (focus is set to some popup window), please try to copen your xml using infopath and check if infopath opens it without any errors/updates/popups/



    Tuesday, October 5, 2010 7:19 AM
  • Hi Micvos

    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  lala.waghmode@gmail.com


    Tuesday, February 22, 2011 11:31 AM
  • When I try this, the formControl1 is null.  If I try formControl1 = new FormControl(), I get an exception.  What am I doing wrong here ?



    Wednesday, March 2, 2011 8:07 PM
  • 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
    Friday, March 25, 2011 4:15 AM
  • For something like this why not just print it to cutepdf or pdf creator?
    • Proposed as answer by Derek.Wilkes Tuesday, July 5, 2011 11:42 AM
    Friday, April 1, 2011 6:21 PM
  • Hi motnis,

    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 :

    1. Parse your InfoPath XML
    2. Process the XML to generate a PDF whith itextpdf library

    Hope this helps.

    Kind regards,


    • Proposed as answer by XristosK Thursday, September 29, 2011 2:39 PM
    Friday, April 1, 2011 9:02 PM
  • Install Solid PDF Reader http://soliddocuments.apposite.com.hk/products.htm and print to pdf while in infopath
    • Proposed as answer by Derek.Wilkes Tuesday, July 5, 2011 11:42 AM
    Wednesday, April 13, 2011 12:40 AM
  • Try http://www.a-pdf.com/infopath-to-pdf/index.htm.  This application quickly converts InfoPath to PDF, and supports batch jobs.
    Thursday, August 22, 2013 3:13 PM