Convert InfoPath Form to PDF in SharePoint

Information

Stay informed about InfoPath deprecation and explore alternatives with our PDF converter solutions. Watch the recording of our latest webinar and learn how to convert your InfoPath documents using Power Automate, Nintex workflows, SharePoint Designer, and code.

In this guide you’ll learn how to convert InfoPath Forms to PDFs in SharePoint using Muhimbi Document Converter. You can convert specific views in InfoPath to PDF. Most of the features available are for ‘real’ InfoPath forms that are stored in a Forms or Document library. This guide can be used in SharePoint Online or On-premises deployments.

What’s includes in this article:

  • Converting InfoPath documents to PDF Using MS SharePoint Designer

  • Converting InfoPath Forms based List Items to PDF

  • Converting InfoPath forms to PDF using MS SharePoint Forms Services

Selecting InfoPath Views to Export to PDF

Muhimbi Document Converter allows you to select specific views to export. It is a very useful feature as quite often different views are used for exporting a form to PDF. Sometimes using the Print View is good enough, but other times you need to export a different view or multiple views to PDF format. There are even occasions where different views are exported depending on the state of the data entered in the form.

In this scenario we have an Employee Review form with the following three views:

  1. Employee Data Entry (default view): This is a view used for populating the data in the MS SharePoint List using the InfoPath client or Forms Services. This is the default view.

  2. Employee Data Entry (print view): : A special view that is optimized for printing to a network laser printer. This is specified as the print view.

  3. _MuhimbiView (PDF Export view): A separate view that is used to export the InfoPath form to PDF format as it contains some information that should only show up in exported PDF files. If there is a view that you want to convert to PDF, then you can achieve this by starting the name of the view “_MuhimbiView”, as per screenshot below. The Muhimbi Document Converter will automatically detect all views that start with this name, export them and merge them together into a single PDF file.

Note: You can hide these views from the end user by marking them as such in the properties of the view.

pdf export view

This is a handy feature of Muhimbi Document Converter if you know beforehand that you will always be exporting the same view(s) to PDF format.

Determine at Runtime InfoPath Views to Export

There are times when you need to export different views depending on the state of the data. To achieve this, you can do the following steps:

Let us design an Employee Expense Claim form, where we need a PDF to be generated once the employee creates the expense claim. A second PDF needs to be generated once the manager approves the claim.

In this scenario, our Expense Claim form consists of the following Views:

  1. Expense Claim (default): Used by the employee to report expenses.

  2. Expense Claim (approve claim): Used by the manager to add comments and additional information for approval.

  3. Expense Claim (PDF Export report):The view that is used to export the form to PDF format before the manager has reviewed the form.

  4. Expense Claim (PDF Export approve):The view that is used to export the form to PDF format after the manager has reviewed the form.

pdf export approve

We can implement this by adding a (hidden) text box named “_MuhimbiViews” (case sensitive and using the default ‘my’ namespace) to any of the views and populating it with the name of one or more comma-separated view names. The Muhimbi Document Converter will automatically pick up these names and export them to PDF format. If multiple views are specified, then they are automatically concatenated together.

In addition to adding the “_MuhimbiViews” text field to the form, all the developer of the form needs to do is add a little bit of logic to the Submit event to specify in the “_MuhimbiViews” field which specific view name(s) to export.

View Prioritization Rules

To determine which view or views to export, Muhimbi Document Converter uses the following prioritization rules:

  • When using the web services interface, any ConversionViews specified in the ConverterSpecificSettings property will be converted. If this property is not set, then the following rules will be used to determine which views to convert to PDF.

  1. If a field named “_MuhimbiViews” is found anywhere in the InfoPath form, then the field’s content is used to determine which views to export.

  2. If the previous field does not exist, is empty, or the specified view name does not exist, then the converter looks at all view names that start with “_MuhimbiView”.

  3. If none of the previous options apply, then the view marked as the Default View is exported.

  • Regardless of how a view or views are selected for export, if the selected view has a Print View specified, then that view is given priority.

  • Be aware when using Muhimbi’s View selection features in combination with InfoPath’s ‘Print multiple views’ facility, as the latter is always given priority when converting to PDF.

  • When the final PDF file is assembled, then all selected views are included first, followed by any converted attachments.

Converting InfoPath documents to PDF Using MS SharePoint Designer

One of the more popular features of the Muhimbi Document Converter for SharePoint is the ability to control which view or views to convert to PDF. It is even possible to specify which views to convert depending on the form’s current status.

The views to convert can be specified during design time, or at run time using a little bit of custom code or InfoPath rules. You can also control which views to convert using MS SharePoint Designer workflow. The example provided below uses MS SharePoint Designer workflow. But this works equally well in the Nintex workflow as well.

Creating the InfoPath Form

  1. Navigate to the MS SharePoint List where you want to design the Infopath form.

  2. Go to Site Settings → Form Options and click Customize the current form using Microsoft Infopath and click OK button.

    customize current form

  3. InfoPath Designer for the list opens

  4. Create a Text box and name it ‘_MuhimbiViews’.

    create text box

  5. On Page Design tab select New View.

  6. Name the new view ‘PDFView’.

  7. Change the Title at the top to ‘PDF View’.

  8. Select the fields you like to see in this view and design the Form View accordingly.

  9. Click FilePublish.

Initial Test

To test that all steps have been carried out correctly and that the Document Converter is working as expected carry out the following steps:

  1. Open the new Form Library in SharePoint and fill out a new form. Don’t enter any data, just save it.

  2. Convert the file that was just generated from the context menu. When the PDF is opened you’ll see Edit Item View, which is the default view.

  3. Fill out another form, but this time enter PDFView. Save it under a new name.

  4. Convert the file we just generated from the context menu. When the PDF is opened you’ll see PDF View.

Creating the Workflow

  1. From the Library ribbon in MS SharePoint select Workflow Settings → Create a workflow in SharePoint Designer.

  2. Name the workflow whatever you like.

In this workflow you will need to set the value of the _MuhimbiViews field before carrying out the conversion. The workflow does not persist the value of the changed field before executing the conversion step, and so we need to ensure the values are updated accordingly before this step. You can do this in two ways:

Using an Impersonation Step

  1. Position the cursor before Step 1 and click Impersonation Step button in the ribbon.

  2. Position the cursor inside the Impersonation Step and add a ‘set field in current item’ action.

  3. ‘Use this action to set the value of the ‘_MuhimbiViews’ field to ’’Edit item; PDFView’.

  4. Position the cursor after the Impersonation Step and click Step button to add a new step.

  5. In this new step add the ‘Convert Document’ action and fill in the blanks.

  6. Publish the workflow and execute it on a previously filled out form.

The resulting PDF should contain Edit item and PDFView (in that order).

Using Pause for Duration

The steps below assume the default, empty, workflow state and not the workflow entered as part of the previous use case.

  1. Position the cursor inside the first Step and add a ’set field in current item’ action.

  2. ‘Use this action to set the value of the ‘_MuhimbiViews’ field to ’’Edit item; PDFView’.

  3. Add the ‘Pause for duration’ action as the next step and let it pause for one minute. You can add the duration based on lots of factors including the number of instances running and the configuration of the server. Use higher numbers for lower server configuration and where the number of running instances is higher.

  4. Add the ‘Convert Document’ action and fill in the blanks.

  5. Publish the workflow and execute it on a previously filled out form.

It may take a while to execute due to the Pause action, but the resulting PDF should contain Edit item and PDFView (in that order).

A third option exists, which is to specify Converter Specific Settings using the XML Override facility in the ‘Convert Document’ Workflow activity.

For any further questions or comments please contact us directly.

Converting InfoPath Forms based List Items to PDF

Note: When converting HTML to PDF, please make sure you are running the latest version (8.3 or higher) of the Muhimbi Document Converter as that version comes with a much improved HTML Converter.

The Muhimbi Document Converter comes with extensive InfoPath support to deal with InfoPath attachments and Dynamic View Selection. However, most of the facilities provided are for ‘real’ InfoPath forms that are stored in a Forms or Document library.

MS SharePoint also allows the List Item Data Entry Form to be customized using InfoPath, but the data filled out using this facility is not stored as real InfoPath Forms and therefore cannot be converted using Muhimbi’s PDF converter.

As the List Items are rendered as HTML, even when customized via InfoPath, you can use the many HTML to PDF facilities provided by the Muhimbi Document Converter for MS SharePoint to convert InfoPath based List Items to PDF.

When using MS SharePoint 2010 or later, the results will improve dramatically when leaving out the SharePoint ribbon, branding and logo by adding ‘&IsDlg=1’ to the URL of the list item that is being converted.

If you need to convert a specific view, then add ’&DefaultView=[viewname]’ to the URL.

HTML is not a format that is suited for output on printed media (including PDF). We do our very best to make things work and render the PDF as well as possible. Unfortunately, we cannot make any guarantees, especially where it comes to third party products that are not under our direct control.

Converting InfoPath forms to PDF using MS SharePoint Forms Services

To achieve the best possible conversion fidelity Muhimbi Document Converter requires InfoPath to be installed on the conversion server. This works great, but in some environments which are mainly externally hosted, this is not always possible. The Document Converter for SharePoint comes with support for converting InfoPath forms to PDF format using InfoPath Forms Services, which is included with the Enterprise version of SharePoint 2007 & 2010.

Please note that what is described in this article is not the recommended way to convert Forms Services forms. The recommended way is to use our standard InfoPath converter to convert those kinds of forms. The HTML Conversion option described here is merely a last resort if all other options fail.

This way of converting Infopath Forms to PDF using MS SharePoint Forms Service can be very useful for some environments, but there are some limitations when using this:

  1. In order for this to work correctly, InfoPath Forms services are required. So, this conversion process doesn’t run on the base WSS3 or MS SharePoint Foundation versions.

  2. It only works with Forms that are Browser enabled.

  3. Dynamic View Selection and conversion of Attachments features are not available, although it is possible to specify the name of the View to convert.

Our traditional approach that uses InfoPath on the server does not have these limitations.

imageFrom Browser based form (left) to PDF Document (right). Click here to open the full PDF file.

Let’s show you how to use Form Services in combination with the Document Converter for SharePoint to convert InfoPath Documents. Some familiarity with both InfoPath and MS SharePoint is assumed.

  1. Make sure you have the appropriate privileges to create workflows on a site collection.

  2. Start InfoPath, select ‘Customize a Sample’ and double click ‘Sample – Expense Report’.

  3. Click File menu and select Publish and go through the usual steps to publish the form to a new SharePoint Library named Expenses.

  4. In the new Expenses document library, fill out a form and save it as Form1.xml.

  5. Create a new workflow using MS SharePoint Designer.

  6. On the Workflow definition screen, associate the workflow with the new Expenses list, tick the boxes next to both ‘Automatically start….’ options and proceed to the next screen.

  7. Add the Convert HTML to PDF action, and click ‘this url / html’ and enter the path to your site collection followed by Muhimbi’s InfoPathPrint.aspx page, e.g. *http://moss/sites/Finance/\_layouts/Muhimbi.PDFConverter/InfoPathPrint.aspx

In the same String Builder dialog, add the xmlLocation query string parameter. Click Add Lookup button and select ‘Server Relative URL’ for the Current Item. The final result should look like the following screenshot.

add lookup

  1. Close the String Builder and click ‘this file’ option. Assuming we want to write the converted PDF files to the Shared Documents library enter Shared Documents/[%Expenses:Name%].pdf. You can insert the underlined text using Add or Change Lookup button, as just typing it in will not work.

  2. Optionally, you can also change the orientation of the page to ‘Landscape’. You don’t need to specify the username or password, as by default the credentials the Document Conversion Service runs under will be used for authentication with the aspx page.

  3. Save and Publish the workflow to activate it.

You can add a new form or update an existing one in the Document Library. After a few seconds, the Workflow Status should change to ‘Completed’. Once complete the converted PDF document can be opened from the Shared Documents library.

If your InfoPath form contains multiple views then you can select which view to convert by concatenating &ViewName=your_view_name to the URL of InfoPathPrint.aspx.

In summary, if it is not possible to install InfoPath on the server in your environment, or if your forms look better in Forms Services compared to the full InfoPath client, then you can use this method to convert InfoPath documents to PDF format using InfoPath Forms Services.

Additional Resources

Knowledge Base Articles

Troubleshooting Articles

Blog articles

Information

We recently released the Muhimbi Document Converter Xtension for Nintex Automation Cloud. You can download it here or learn more about available Muhimbi deployments for Nintex on our product page.

In this guide you’ll learn how to convert InfoPath Forms to PDFs using Nintex Workflows. We provide details on how you can control which view or views to convert to PDF and how you can specify which views to convert depending on the form’s current status.

We also provide details on how to specify the views to convert during design time or at run time using a little bit of custom code or Nintex forms rules. You can also control which views to convert using Nintex workflow or Nintex for O365 in MS SharePoint Online. The example provided below uses the Nintex workflow. But this works equally well in the MS SharePoint Designer workflow as well.

In this example, we create a workflow to retrieve all files modified during the current day and convert them to PDF. Ideally, you would schedule this workflow to run off-peak to batch process all new and modified files

sharepoint designer workflow

Nintex Dialog for the new PDF Conversion Action

The Nintex Convert File to PDF Action can use Nintex Lookups and Workflow Variables and can be used to convert items other than the ones that triggered the workflow, which makes it ideal for converting entire sets of documents.

Prerequisites

Before we build the workflow, please ensure all prerequisites are in place. It is also assumed that the reader has some knowledge of building Workflows using Nintex Workflow.

  1. Make sure the Document Converter for SharePoint version 4.1 (or newer) is installed in line with chapter 2 of the included Administration Guide.

  2. Naturally, Nintex Workflow will need to be installed as well. Nintex Workflow versions 2007, 2010, 2013, and 2019 are supported.

  3. Make sure the Muhimbi.PDFConverter.Nintex.WebApp SharePoint Feature is activated on the relevant Web Application using SharePoint Central Administration.

  4. You will need to have the appropriate privileges to create workflows.

Creating the Infopath Form

  1. Navigate to the MS SharePoint List where you want to design the Infopath form.

  2. Go to Site Settings → Form Options and click Customize the current form using Microsoft Infopath and click OK button.

    site settings form options

  3. InfoPath Designer for the list opens

  4. On Page Design tab, select New View.

  5. Name the new view ‘PDFView’ or any name of your convenience.

  6. Change the Title at the top to ‘PDF View’ so you know the exact view that has been exported.

  7. Select the fields you like to see in this view and design the Form View accordingly.

  8. Click FilePublish.

Initial Test

To test that all steps have been carried out correctly and that the Document Converter is working as expected carry out the following steps:

  1. Open the new Form Library in SharePoint and fill out a new form. Don’t enter any data, just save it.

  2. Convert the file that was just generated from the context menu. When the PDF is opened you’ll see Edit Item View, which is the default view.

  3. Fill out another form, but this time enter PDFView. Save it under a new name.

  4. Convert the file we just generated from the context menu. When the PDF is opened you’ll see PDF View.

Creating the Nintex Workflow

To get started, create a new workflow and choose the blank template. You can download the complete workflow in NWF format and reuse it for your environment.

nintex workflow

Make sure the workflow doesn’t start automatically and add the workflow variables listed in the following screenshot.

workflow variables

Please ensure that the appropriate data types are assigned (They are listed between round brackets behind each variable name). The names are largely self-describing, but some additional information is provided below:

  • Source Item ID: By default, the item that triggered the workflow is converted to PDF format. However, as we are iterating over multiple items we need to specify the ID of the item to convert in this variable. In SharePoint 2010 / 2013 select Integer as the Type, not List Item ID.

  • Source List ID: The Document Converter assumes the item that is being converted is located in the same list the workflow is attached to. However, if this is not the case, then the ID (a GUID) of the list will also need to be specified. In this example, everything is located in the same list, so this variable is not actually used.

  • Source Files: As we are potentially converting multiple files, we need to define a variable of type Collection to hold the list of files we will be iterating over.

  • Generated PDF Item ID: Once a file has been converted to PDF, you may want to carry out additional actions on this new file, for example, checking it in. Once converted, the ID of the PDF is automatically stored in this variable. In SharePoint 2010 / 2013, select Integer as the Type, not List Item ID. This example uses the (Legacy) Convert to PDF Workflow Activity, if you use the newer Convert Document activity then please take into account that the Generated PDF Item ID is of type Text. If you wish to pass this ID into a secondary activity then you may need to convert it to the correct data type using the Convert Value Workflow Activity. An example can be found here.

  • Generated PDF List ID: As the Document Converter allows files to be written to different document libraries, and even completely different Site Collections, you may want to know the ID of the destination list.

Adding the workflow actions

We are now ready to add the actions to the workflow. Begin by adding a Query List action, which will allow us to retrieve all files modified today and store the results in the Source Files collection.

add workflow actions

You can fill out the settings for this action as in the screenshot listed above. You may want to add an additional filter rule to check that Content Type is not equal to Folder or Document Set.

Continue by adding the For Each action to the workflow. Specify the collection’s name to iterate over and the variable’s name to store the Item’s ID in.

specify collection name

The next set of actions will all need to be added inside the For Each action, to make sure they are executed separately for each file in the list.

We want to ensure that we only invoke the Document Converter for files that are not in PDF format. So, add a condition and check that the file type equals ‘pdf’ as per the following screenshot:

file type equals pdf

Add the Convert file to PDF action listed under the Muhimbi PDF section to the No branch of the condition (type is not pdf). Fill it out as per the leftmost image in the following screenshot.

convert file to pdf

Document Converter integrates with Nintex Workflow 2007, 2010 & 2019

You may want to leave the Destination Path empty, which will write the PDF File to the same location as the source file. For more information about the Destination Path or any of the other fields, hover the mouse over the small information icons.

The workflow is now done. You may want to add some tracking information using the Log In the History List action. In our example we use the following:

  • Last action in the No branch:
    List ID: {WorkflowVariable:Generated PDF List ID} - List Item ID: {WorkflowVariable:Generated PDF Item ID}

  • Last action in the Yes branch:
    Already in PDF Format: {WorkflowVariable:Source Item ID}

Running the Workflow

Finalize the workflow by saving and publishing it, after which it is ready to be executed.

You can either run the workflow manually or schedule it to run at a time of your choice. You will observe that the InfoPath document will be converted to PDF in the target document library.