Export InfoPath-form to pdf-file with individual name - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Export InfoPath-form to pdf-file with individual name

Last post 05-31-2016 01:57 PM by John1006. 38 replies.
Page 2 of 3 (39 items) < Previous 1 2 3 Next >
Sort Posts: Previous Next
  • 10-19-2010 09:45 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    PDF export will not work on browser enabled forms.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-24-2010 02:28 PM In reply to

    • SeanW
    • Not Ranked
    • Joined on 08-15-2010
    • Posts 2

    Re: Export InfoPath-form to pdf-file with individual name

    The code works perfectly, but is it possible to eport the PDF using the higher quality mode via code?

  • 02-02-2011 03:19 PM In reply to

    • Kallie
    • Not Ranked
    • Joined on 02-02-2011
    • Posts 1

    Re: Export InfoPath-form to pdf-file with individual name

    Does anyone know how to fix the issue of the export only showing up in portrait vs landscape?

     

    It is not as simple as changing the print view, I have tried that. I have set page widths as well. Nothign works. Have heard it was an issue wehn SP2 came in... but that was a long time ago.

  • 02-10-2011 03:26 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    Hilary,

    I can't thank you enough.  Your C# code for converting an Infopath form to PDF works perfectly.  The only problem I have now is that the PDF and XPS conversion loses most of my data and half of the form is cut off.

    The only solution I can find is to have the form converted to MHT format.  I can do this both manually and by modifying your code to save it to my local drive and it comes out perfectly.  But that's not good enough for me.  I need to save the converted form to a MOSS SharePoint folder.  I can do this fine when I export as a PDF or XPS using your code so I know its not an issue with Full Permission and Signatures as I have those all enabled as necessary.

    Here is what I have for exporting as a PDF.  This works fine with no errors.  I just lose half the information from the form.

    //Declare our variables

    string fileName;

    XPathNavigator nameNode;

    XPathNavigator nameNode2;

     

    //Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name

    nameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager);

    nameNode2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field4", NamespaceManager);

    fileName = nameNode.Value + "_" + nameNode2.Value +".pdf";

    //Do the work -- notice we use the variable fileName as part of the path for the file.

    this.CurrentView.Export(@"http://moss.mysharepoint.com/.../mycompletedforms/" + fileName, ExportFormat.Pdf);

     

    Then I try to change a couple of points to convert the form to MHT like this:

     

    //Declare our variables

    string fileName;

    XPathNavigator nameNode;

    XPathNavigator nameNode2;

     

    //Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name

    nameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", NamespaceManager);

    nameNode2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field4", NamespaceManager);

    fileName = nameNode.Value + "_" + nameNode2.Value +".mht";

    //Do the work -- notice we use the variable fileName as part of the path for the file.

    this.CurrentView.Export(@"http://moss.mysharepoint.com/.../mycompletedforms/" + fileName, ExportFormat.Mht);

     

    Here are the errors I get.

     

    System.Runtime.InteropServices.COMException
    InfoPath cannot export the form.
       at Microsoft.Office.Interop.InfoPath.SemiTrust.View.Export(String bstrURL, String bstrFormat)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat)
       at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format)
       at PDF_Test.FormCode.CTRL4_5_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

     

    Like I said, I can change the export path to my local hard drive and it works perfectly for the MHT export.  I can also manually export the form using 'File - Export to.. - Web' and direct it to the SharePoint site and it works perfectly fine that way too.  I just need it to work when the button is clicked inside the form.

    I certainly appreciate any help that you or anyone can give on this issue.

     

    Thomas Grover

    Intel Automation Equipment Specialist

  • 02-10-2011 10:42 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    You could try creating a print view for your form that won't cut off bits on export.

    Here's an MSDN page on the error you are getting. I'd try a try / catch around the line that does the export, and set a breakpoint on the catch so that you can get more detail on the error.

     

    Hilary Stoupa

  • 05-19-2012 10:05 AM In reply to

    • swamy
    • Not Ranked
      Male
    • Joined on 05-13-2012
    • Bangalore
    • Posts 9

    Re: Export InfoPath-form to pdf-file with individual name

    hi,

     I am facing a same issue, I am able to export and save PDF file into SharePoint Document library directly,

    But, I am not able to export and save MHT file directly into SharePoint Document library when click on button.

    Error :

    at Microsoft.Office.Interop.InfoPath.SemiTrust.View.Export(String bstrURL, String bstrFormat)\r\n   at Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.Export(String bstrURL, String bstrFormat)\r\n   at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format)\r\n   at Formtemplate6.FormCode.SRApproval_Print_Clicked(Object sender, ClickedEventArgs e) in line 49\r\n   at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)\r\n   at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)"

    Note : I am able to export and save MHT file in Local drive

     

  • 07-08-2012 11:24 PM In reply to

    • u_n728
    • Not Ranked
    • Joined on 07-09-2012
    • Posts 2

    Re: Export InfoPath-form to pdf-file with individual name

    Hi Hilary,

    I am completly new to Infopath. I have added a submit button and made the changes as you have said in your post. But when I fill the form in the preview mode. I get the following error

     System.NotSupportedException
    The given path's format is not supported.
       at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
       at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
       at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
       at Microsoft.Office.InfoPath.Internal.XmlFormHost.CheckFileWritePermission(String fileLocation)
       at Microsoft.Office.InfoPath.Internal.ViewHost.Export(String fileLocation, ExportFormat format)
       at LCV_REQ.FormCode.Print_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
     

    Please help me.

    Regards,

    Nitin.

    The Analyst
  • 07-09-2012 08:19 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    Well, the error indicates that the path you are trying to export to is invalid. It would be impossible for me to know why without seeing the code. Have you tried running in debug?

    Hilary Stoupa

  • 07-09-2012 07:06 PM In reply to

    • u_n728
    • Not Ranked
    • Joined on 07-09-2012
    • Posts 2

    Re: Export InfoPath-form to pdf-file with individual name

    Hi Hilary,

    I changed the path in the code to make it simple and tried submitting the form again in preview mode again, I got the following error.

    System.NullReferenceException
    Object reference not set to an instance of an object.
       at LCV_REQ.FormCode.Print_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    I am not able to understand what the error is. If you want to see the what should I do to send you the code..as I said I am completely new to infopath.

    The following is all I have in the section which I believe is the code section of InfoPath.

    Imports Microsoft.Office.InfoPath

    Imports System

    Imports System.Windows.Forms

    Imports System.Xml

    Imports System.Xml.XPath

    Imports mshtml

     

    Namespace LCV_REQ

    Public Class FormCode

    ' Member variables are not supported in browser-enabled forms.

    ' Instead, write and read these values from the FormState

    ' dictionary using code such as the following:

    '

    ' Private Property _memberVariable() As Object

    ' Get

    ' _memberVariable = FormState("_memberVariable")

    ' End Get

    ' Set

    ' FormState("_memberVariable") = value

    ' End Set

    ' End Property

    ' NOTE: The following procedure is required by Microsoft Office InfoPath.

    ' It can be modified using Microsoft Office InfoPath.

    Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup

    AddHandler DirectCast(EventManager.ControlEvents("Print"), ButtonEvent).Clicked, AddressOf Print_Clicked

    End Sub

    Public Sub Print_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs) 'Declare our variable

    Dim fileName As String

    Dim nameNode As XPathNavigator

    'Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name

    nameNode = MainDataSource.CreateNavigator().SelectSingleNode("test", NamespaceManager)

    fileName = nameNode.Value + ".pdf"

    'Do the work -- notice we use the variable fileName as part of the path for the file

    Me.CurrentView.Export("C:\" + fileName, ExportFormat.Pdf)

    End Sub

     

    End Class

    End Namespace

    Sorry to bother you so much, your help on this is much appreciated.

    Regards,

    Nitin. 

     

    The Analyst
  • 07-10-2012 10:03 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    In the code sample, we were using the value of a node for the file name. In your code, you have:

    nameNode = MainDataSource.CreateNavigator().SelectSingleNode("test", NamespaceManager)

    Which will most likely result in "nameNode" being null - do you have a form field you'd like to use for the name?

    For testing purposes, you could just change this line:

    fileName = nameNode.Value + ".pdf"

    To a value for the file name:

    fileName = "test.pdf"

    for example.

    Hilary Stoupa

  • 11-23-2012 06:13 AM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    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;

    use the above name spaces and add the following dlls to your solution

    System.Windows.Forms.dll

    microsoft.mshtml.dll ---- Download from the microsoft site

    then it will work

    Filed under:
  • 12-19-2012 12:10 PM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

     I've had the exact same problem.  I don't see anywhere in the API to set the resolution to the "Standard"? 

     

                  finaldoc.Save(p + '\\' + splitatlevel.Last() + "_Final.xml");
     
                  formControl1.Open(p + '\\' + splitatlevel.Last() + "_Final.xml");
                  formControl1.XmlForm.CurrentView.ForceUpdate();
     
                  Application.DoEvents();
     
                  MessageBox.Show(splitatlevel.Last());
     
                  formControl1.XmlForm.CurrentView.Export(p + '\\' + splitatlevel.Last() + "_Final.pdf", Microsoft.Office.InfoPath.ExportFormat.Pdf);
                  formControl1.Close();
    Anyone else have any API or COM insight on programmatically setting the pdf quality?  

     

  • 04-17-2013 01:06 AM In reply to

     Hi Hillari ,

    i have to convert  xsn file to pdf format  can you guide me

    i am work in third party pdf conveter muhbumbi

    but i did not find a specefic way to convert it

  • 02-14-2014 03:48 PM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

     Hi Hilary,

     

    I am new in Infopath and Visual Studio. I have followed your guide, But I have below error in  C# Code:

     

    using Microsoft.Office.InfoPath;
    using Microsoft.Office.Interop.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.IO;
    using System.Windows.Forms;
    using mshtml;
    using System.Windows;


    namespace Form9
    {
        public partial class FormCode
        {
            // Member variables are not supported in browser-enabled forms.
            // Instead, write and read these values from the FormState
            // dictionary using code such as the following:
            //
            // private object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft InfoPath.
            // It can be modified using Microsoft InfoPath.
            public void InternalStartup()
            {
                ((ButtonEvent)EventManager.ControlEvents["CTRL210_5"]).Clicked += new ClickedEventHandler(CTRL210_5_Clicked);
                ((ButtonEvent)EventManager.ControlEvents["CTRL211_5"]).Clicked += new ClickedEventHandler(CTRL211_5_Clicked);
            }

            public void CTRL210_5_Clicked(object sender, ClickedEventArgs e)
            {

                //PrintDocument pd = new PrintDocument();
                //pd.Print();

            }

            public void CTRL211_5_Clicked(object sender, ClickedEventArgs e)
            {
          

                Declare our variables
                string fileName;
               XPathNavigator nameNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:textField", NamespaceManager);

                Set the values. Replace "/my:myFields/my:textField" with the xpath to the field that has the value you want as the file name
          
               fileName = nameNode.Value + ".pdf";
              Do the work -- notice we use the variable fileName as part of the path for the file.
                this.CurrentView.Export(@"C:\" + fileName, ExportFormat.Pdf);
              
          

              
                
               
               
            }
        }
    }

     

     Could you please help me?

     

  • 04-01-2014 11:29 PM In reply to

    Re: Export InfoPath-form to pdf-file with individual name

    Hi, First off all thanks a lot for your great support. Can you please assist me with very small query. I want to save my Infopath 2010 form as pdf when click on save button. For this I have copied the C# code but its showing error: Error 1 'Microsoft.Office.InfoPath.View' does not contain a definition for 'Export' Error 2 The name 'ExportFormat' does not exist in the current context Please let me know if i need to add any namespace or anything else. Thanks, Ankit
Page 2 of 3 (39 items) < Previous 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.