Save / Print / Convert / Export an InfoPath form to PDF
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.
You have an InfoPath form which you would like to convert into an PDF document.
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 will save the form as an PDF document with the name MyView.pdf on the local C-drive.
- Since you will be programmatically accessing the local computer, you will have to give the form template Full Trust.
- The Export method is not available to browser-enabled forms.
- 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.
- Unlike with the first method, you do not need to give the form template Full Trust for the add-in to work.
- This add-in only shows up the InfoPath Form Editor and not in the InfoPath Form Designer.
- This add-in is not available to forms displayed in a browser.
- 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:
- Printing InfoPath 2007 Web-based Forms to PDF
- Use Word 2007 to programmatically convert an InfoPath 2007 form to PDF
- Convert an InfoPath form to Word and PDF in SharePoint 2010
- Publish InfoPath 2010 form as PDF without code
- Converting browser-enabled forms to PDF or HTML in SharePoint
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.