Save / Print / Convert / Export an InfoPath form to PDF

Applies to: InfoPath 2007

Add code to the form to programmatically export the current view of the form to PDF or use the Save As PDF or XPS add-in for Microsoft Office 2007 to export a view.

ADVERTISEMENTS

Problem

You have an InfoPath form which you would like to convert into an PDF document.

Solution

Add code to the form to programmatically export the current view of the form to PDF and/or manually use the Save As PDF or XPS add-in for Microsoft Office 2007 to export a view from the form to PDF.

Both these solutions only work for forms that are filled out through the InfoPath client application and not for those filled out through a browser. Both solutions also require you to download and install the Save As PDF or XPS add-in for Microsoft Office 2007.

Method 1: Programmatically export the current view of an InfoPath form to PDF

The InfoPath 2007 object model contains an Export method you can use to export the current view to PDF. To do this, add similar code as the following C# code to the Clicked event handler for a Button control:

this.CurrentView.Export(@"C:\MyView.pdf", ExportFormat.Pdf);

This will save the form as an PDF document with the name MyView.pdf on the local C-drive.

Important remarks:

  1. Since you will be programmatically accessing the local computer, you will have to give the form template Full Trust.
  2. The Export method is not available to browser-enabled forms.
  3. Only one view - the current view - can be exported at a time. You can export other views by making them the current view and calling to code from those views.

Method 2: Use the Microsoft Office Save As PDF or XPS add-in to export a view from an InfoPath form to PDF

You can download the 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS, install it, and use it to export a view from an InfoPath form to PDF.

Please note that this add-in can only be used in the InfoPath Editor and not in the InfoPath Designer, that is, it cannot be used to convert an InfoPath form template into a PDF document, since it is not an InfoPath form template exporter. It can only be used to export an InfoPath form when/after filling out a form in the InfoPath Editor as shown in the following figure.


Figure 1. Using the PDF/XPS add-in for Microsoft Office 2007 to export a view from an InfoPath form to PDF.

Important remarks:

  1. Unlike with the first method, you do not need to give the form template Full Trust for the add-in to work.
  2. This add-in only shows up the InfoPath Form Editor and not in the InfoPath Form Designer.
  3. This add-in is not available to forms displayed in a browser.
  4. Only one view - the current view - can be exported at a time. You can export other views by switching to them and thereby making them the current view.
 


Related InfoPath Articles:

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services