InfoPath forms are XML files, so to print a web-based form
to PDF you must retrieve the XML of the form and convert it to PDF. Retrieving
the XML of a web-based form can be a challenge since such forms are hosted in a
control on a web page. A web-based form can be hosted by:
Using the InfoPath Forms Services web page to
host the form.
Creating a custom ASP.NET page to host the form.
In both cases, a control named XmlFormView
is used to host the form on a web page. The difference between the two methods
is that while you have total control over a custom web page that you create,
you do not have the same amount of control over the web page that is used by InfoPath Forms Services, since its code-behind is
inaccessible to you. In addition, it is not recommended to modify files that
are used by InfoPath Forms Services, since they might
be overwritten by future upgrades of Forms Server or Microsoft Office
SharePoint Server. It is recommended that you create your own custom ASP.NET
page, which uses an XmlFormView control to host your
The XmlFormView control has a
property named XmlForm,
which gives you a reference to the main data source of the form and allows you
to retrieve the XML of the form. However, the XmlForm
property can only be accessed during one of the following events of the XmlFormView control:
The NotifyHost event is suitable for
setting up communication between the form and the ASP.NET page that is hosting
it. To trigger the NotifyHost
event, you must use the NotifyHost
method of the XmlForm class in an event handler of a
field on the form. You can then hook up the NotifyHost
event to an event handler in the ASP.NET page, retrieve the XML of the form,
and convert the XML to PDF.
The technique presented in this article uses the NotifyHost method and event to enable printing web-based
forms to PDF. An overview of how this technique works is shown in Figure 1 and
is discussed in more detail in subsequent sections.
Figure 1: Overview of printing a web-based form to