Print Task templates with the 9.3.1 .NET Web ADF

The 9.3.1 ArcGIS Server Web ADF for .NET introduces an extensibility point to the Print Task that allows you to customize the look of your printouts using template files on the Web server.

A new property called LayoutTemplateFile is introduced to define the template file. This property can point to any file on disk but must be accessible via a web URL. The file may be part of the same application or can reside in a separate application (for example, the aspnet_client folder).

In Visual Studio, select the PrintTask control and you’ll see the new property. Clicking the Browse button allows you to browse to the custom template file.

Viewing the LayoutTemplateFile property for the PrintTask

How do you create a simple custom template?

An easy way to create a template is to modify the ADF’s default template.

  1. Within Visual Studio, right-click your project and choose “Add New Item…” from the menu. When the dialog appears, choose “HTML Page” and give it a suitable name. This will create an HTML document which you can use as the template.
  2. Open the default template file which is typically installed in the ADF runtime folder (Example: C:Inetpubwwwrootaspnet_clientESRIWebADFPrintTaskLayoutTemplatesdefault.htm). This file defines the default appearance and layout of the Print Task output window.
  3. Overwrite the markup of the new page with the contents from default.htm.
  4. Modify the markup and CSS to obtain the output you desire.

What can you do with these custom templates?

Using custom templates, you can:

  • Control the layout of elements and their styles

    In the template file, you can define the position and dimensions of the different elements on the page such as the map title, map image, and legend information. You can style the template page using inline CSS or an externally linked style sheet.

  • Inject dynamic content

    The template file is not restricted to static HTML files but can reference resources which generate dynamic content (such as .aspx files or .ashx files). For example, the current time stamp could be included in the print output using a dynamic page.

  • Control the display of results

    You can control the styling of task results through CSS and you may also choose to render the result entirely, forgoing the default generated table view. If you want to get more advanced, you might add an image generated using the Google Chart API or a report section rendered using a browser plugin like Silverlight.

  • Use JavaScript hooks

    In addition to providing extensibility with respect to layout and rendering, the Print Task also exposes JavaScript events which can be used to completely control and customize the output. This is achieved by having “callback functions” defined in the template file which are invoked at specific stages of the output rendering.

Further reading

The SDK sample Common Print Task demonstrates the above capabilities where a chart is drawn dynamically using the Google Chart API

Contributed by Nikhil Shampur of the ArcGIS Server .NET software development team.

This entry was posted in Services and tagged , , , . Bookmark the permalink.

Leave a Reply

One Comment

  1. sterlingdq says:

    @Hernal-

    The LayoutTemplateFile property is like any other .Net property and should be settable in design time and in runtime (Code behind). You could try re-adding/verifying the assembly reference to make sure you are indeed working with the 9.3.1 assembly version. Deleting and re-adding the Print Task control to the Visual Studio toolbox might help also.

    Another comment is that if you set the LayoutTemplateFile property at runtime using code behind, it needs to be applied before the OnPreRender phase of the page lifecycle.