Problem: You want to print some or all of the data from an InfoPath form to PDF.
You can create a print view that can be used specifically to print form data to PDF and then assign this view as the print view of another view that is used to fill out the form.
1 - Create a new InfoPath Filler form
2 - Create a new view and call it PrintToPDF
3 - Create custom fields, add those fields to both the default and the PrintToPDF view.
4 - Customize the PrintToPDF view and make sure that no borders for the controls appears. One way to do this is to use "Calculated Values" as much as possible instead of regular Text Boxes. Another way is to simply hide the borders under properties.
5 - Go back to the default view, click on properties and under the Print Settings tab select PrintToPDF in the drop-down under the Designate Print View section. Once this is done you have configured the default view to use PrintToPDF view as its print view.
6 - Add a button and under it's clicked event handler add the following code"
Dim formName As String = CurrentView.Window.Caption
CurrentView.Export("c:\temp\" & formName & ".pdf", ExportFormat.Pdf)
7 - Give the form template Full Trust. Save and build the project.
8 - Once you click on the button you will see that a PDF was created under the temp folder.
The Export() method is not available for InfoPath browser forms. For browser forms you can use a different technique that will be shown later that saves the form as a PDF in a SharePoint document library.
No comments:
Post a Comment