Batch conversion of InfoPath filler forms to PDF via code - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Batch conversion of InfoPath filler forms to PDF via code

Last post 04-20-2014 05:46 AM by barrywhite. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 05-30-2012 09:22 AM

    Batch conversion of InfoPath filler forms to PDF via code

    Hi there,

    I'm attempting to create a simple C# button 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 am creating this within an InfoPath form external to any of the forms being converted (I would rather create a stand-alone program using C# but my references within Visual C# Exp refuse to play nicely)!

    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:

    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);

    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.  Every form within that folder has "View 1" as its view name, and so does the main form with the button. I attempted to use the SwitchView control/function but that failed (didn't know where to how use it)!

    Your help would be most appreciated - thank you!

     

  • 05-30-2012 03:51 PM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    So - offhand, I wonder about creating an XML form variable that you instantiate with your Open method call:

    XmlForm newForm = Application.XmlForms.Open(fileName, XmlFormOpenMode.ReadOnly);

    Then, from there, try to export the current view:

    newForm.CurrentView.Export .... etc.

    I've got no idea if that will help at all, but it may be worth a try.

    The target form that you are opening - is it full trust? MSDN says that the template will need to be full trust to use Export ....

    Hilary Stoupa

  • 05-31-2012 12:46 PM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    Hi Hilary, Thank you for your help! I attempted the modification to the open method but that yielded the same error message. It is a fully trusted XML document (but I will test that a bit further as one of my initial errors attempting to create this was the "Form not fully trusted etc etc"). It is an issue with the view (a Google search seems to confirm that) ...I'll search the net a bit further and see if I've missed anything (I just know its a simple tweak :P)!
  • 05-31-2012 02:05 PM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    The thing is, I know I've seen this error before.... I think when trying to use CurrentView in a loading event. So, I'm thinking what is happening is that your code to try to export to PDF executes too soon. You could try adding something to make it wait a bit, see if that addressed it - Thread.Sleep or something?

    Hilary Stoupa

  • 06-01-2012 12:25 PM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    Thank you again - I attempted the Thread.Sleep but it seemed to pause the entire process and the same error popped up again.

            public void Conversion_Clicked(object sender, ClickedEventArgs e)
            {
                string[] fileEntries = Directory.GetFiles("C:\\Test");
                foreach (string fileName in fileEntries)
                {
                    XmlForm newForm = Application.XmlForms.Open(fileName, XmlFormOpenMode.ReadOnly);
                    Thread.Sleep(1000);
                    newForm.CurrentView.Export(@fileName + ".pdf", ExportFormat.Pdf);
                    Application.ActiveWindow.Close(true);
                }
            }

    Hmmm I'll take a look at possibly using the Print() function, and having the form change the default printer to print to PDF every time it runs...but I really wanted to use the Export function b/c its so much faster...I won't give up on it though as I have quite a few other Office documents that need batch PDF printing!

  • 01-25-2014 10:34 PM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

     Hi there

    Actually ,i have only tried to convert PDF files using a PDF converter.It is hard for me to convert pdf files via code.There are many third party tool for pdf converting.

    But i want to know that if there is a Powerful PDF tool which supports to convert  multipage pdf files to Infopath.I am testing related program for users to convert pdf.

    Thanks for any suggestions.

  • 01-27-2014 02:34 AM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    Hi

    If you are looking at 3rd party PDF Converters aimed at InfoPath, then have a look at the Muhimbi PDF Converter for SharePoint or the generic Muhimbi PDF Converter Services.

    Allows the InfoPath View(s) to be selected and even converts attachments.

    Note that I have worked on this product, so consider me biased.

    Jeroen
  • 04-20-2014 05:46 AM In reply to

    Re: Batch conversion of InfoPath filler forms to PDF via code

    Nana111:

     Hi there

    Actually ,i have only tried to convert PDF files using a PDF converter.It is hard for me to convert pdf files via code.There are many third party tool for pdf converting.

    But i want to know that if there is a Powerful PDF tool which supports to convert  multipage pdf files to Infopath.I am testing related program for users to convert pdf.

    Thanks for any suggestions.

     

     

    Hey, it is all about C# conversion source.. and not the way you are trying to say,, this is not about PDF converter tool.  It's kinda bit skeptical for me to search specific needs and knowing that answer would be specific too, but here comes nothing to do at all. I am not familiar anyway as I am newbie in C#, but I did follow your guide but it ended me up to nothing but irrelevant. You should know who you follow to, do not break the path, as it will lead people like me to nowhere.

     

Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.