locked
Batch Conversion of InfoPath filler forms to PDF via code RRS feed

  • Question

  • Hi there,

    I'm attempting to create a simple program that can convert a # of InfoPath forms to PDF (60+).  My knowledge of C# is basic but I would really like to take a stab at this as it would diminish quite a bit of administration time (and the use of any third-party off-the-shelf solutions).

    I receive the following error (I was able to find a few solutions to it but none seem to cooperate with my code very well):

    "InfoPath cannot execute any view-related object model calls. The view is not ready."

    Here is the code I currently have:

    using Microsoft.Office.InfoPath;
    using System;
    using System.Windows.Forms;
    using System.Xml;
    using System.Xml.XPath;
    using mshtml;
    using System.IO;
    using System.Windows;
    
    namespace Testing
    {
        public partial class FormCode
        {
            public void InternalStartup()
            {
                ((ButtonEvent)EventManager.ControlEvents["Converion"]).Clicked += new ClickedEventHandler(Converion_Clicked);
            }
    
            public void Converion_Clicked(object sender, ClickedEventArgs e)
            {
                string[] fileEntries = Directory.GetFiles("C:\\Test");
    
                foreach (string fileName in fileEntries)
                {
                    Application.XmlForms.Open(fileName, XmlFormOpenMode.ReadOnly);
                    //MessageBox.Show(fileName);
                    Application.ActiveWindow.XmlForm.CurrentView.Export(@fileName + ".pdf", ExportFormat.Pdf);
                    Application.ActiveWindow.Close(true);
                }
            }
        }
    }
    

    The error takes place when it attempts to export; I'm attempting to open each form, export to PDF, close, and repeat.

    The following post was helpful: http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/9f43f377-dfd6-4c6e-a361-315bf30f3c91 but I still get the same hiccup.  Thank you for your help!

    Monday, May 28, 2012 7:08 PM

All replies

  • hi,

    do you have a people picker in view? it`s a problematic control. prepare views for export without it

    Tuesday, May 29, 2012 8:31 PM
  • Hi Alexandru,

    Thank you for the response!

    I do not believe I inserted any peoplepicker controls (also, the form is not web-based and neither are the XML forms being converted) - the code above is the only code available in the form, and only a single button will be available for the user to click.  The user will dump the xml files into a predetermined folder (i.e. C:\XML), and use this form to convert every available one in there to PDF.

    Thank you again!

    Wednesday, May 30, 2012 1:14 PM