Common Print task


Purpose
This sample demonstrates how to implement custom print templates for the PrintTask. The ability to define such templates enables extensive customization of the arrangement, content, and appearance of print page elements.
 
This sample includes the following templates, each of which can be used with the Default.aspx page:
  • Simple.htm—Illustrates specifying the arrangement and appearance of print page elements through the use of Hypertext Markup Language (HTML) and Cascading Style Sheets (CSS).
  • ServerTimestamp.aspx—Demonstrates how to include a timestamp that is initialized in the code behind when the print page is loaded.
  • ClientTimestamp.htm—Demonstrates how to use JavaScript to initialize a timestamp when the print page is loaded.
  • CustomLegend.htm—Illustrates the use of one of the JavaScript functions specified by the PrintTask (setLegend) to create a custom-formatted legend via JavaScript.
  • GoogleChartResults.htm—Illustrates the use of one of the JavaScript functions specified by the PrintTask (setTaskResults) along with the Google Chart application programming interface (API) to include a chart of task results on the print page.

How to use

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/California/California.mxd.
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web Application Developer Framework (ADF) for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNet. This folder contains the Common_PrintTask CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_PrintTask_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the Common_PrintTask_<language> folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Microsoft Visual Studio 2008 or 2010, and open the solution for the version of Visual Studio you're using. The Visual Studio version is appended to the solution file name. For example, the Visual Studio 2008 solution file for the Common_PrintTask_CSharp sample is Common_PrintTask_CSharp2008.sln and is located in the c:\inetpub\wwwroot\Common_PrintTask_CSharp folder.
  8. In Solution Explorer, right-click the page you want to view and select Set As Start Page.
  9. This sample is configured to use the California map service, and it is assumed that this service is running on the local machine (localhost). You can create this service by publishing the map document located at <ArcGIS install location>\DeveloperKit10.0\Samples\data\California\California.mxd. For instructions on how to publish a map document to ArcGIS Server, see the Publishing a GIS resource to the server topic in the ArcGIS Server Help.
  10. If the California service is not running on the local machine, specify the proper location by following the steps in the Specify the California service location section below.
  11. The templates in this sample are associated with the PrintTask on the Default.aspx page. Initially, the sample uses the Simple.htm template. You can change the template by following the steps in the Setting the template used with the PrintTask section below.
  12. Save the project.
  13. Click the Debug drop-down menu and click Start Debugging.

Specify the California service location
  1. Open the Default.aspx page in Visual Studio Design view.
  2. Open the properties dialog box for the MapResourceManager control.
  3. Click the ResourceItems property and click the ellipsis button that appears. The ResourceItem Collection Editor dialog box opens.
  4. Specify the parameters for the California service and click OK.
  5. Click OK again and save the project.

Setting the template used with the PrintTask
  1. Open the Default.aspx page in Visual Studio Design view.
  2. Select PrintTask1.
  3. In the properties window, click the LayoutTemplateFile property and click the ellipsis button that appears. The Select URL dialog box opens.
  4. Click the template you want to view from the PrintTemplates directory and click OK.
  5. Save the project.

At run time
  1. Browse to the application uniform resource locator (URL) (for example, http://localhost/Common_PrintTask_CSharp) or start the application from Visual Studio.
  2. Click the Find button on the Query Attributes Task.
  3. On the Print Task, check the California Cities check box.
  4. Click the Create Print Page button. A print page opens. Note the layout and appearance of the map elements and how they correspond to the selected layout. If the GoogleChartResults template file is being used, the print page will include a pie chart with a drop-down list below it.
  5. Choose a field from the drop-down list. The chart updates to classify the cities by the selected field.

Common_PrintTask_CSharp\Default.aspx Web page containing a print task used to demonstrate the print templates.
Common_PrintTask_CSharp\Default.aspx.cs Code behind the .aspx page.
Common_PrintTask_CSharp\PrintTemplates\Simple.htm Contains HTML and CSS specifying a custom arrangement and appearance for a print page.
Common_PrintTask_CSharp\PrintTemplates\ServerTimestamp.aspx Print template that includes a timestamp populated through Web-tier code.
Common_PrintTask_CSharp\PrintTemplates\ServerTimestamp.aspx.cs Code behind the .aspx page. Initializes the timestamp.
Common_PrintTask_CSharp\PrintTemplates\ClientTimestamp.htm Print template that includes a timestamp populated by client-tier (JavaScript) code.
Common_PrintTask_CSharp\PrintTemplates\CustomLegend.htm Print template that illustrates creation of a custom legend through use of a print task JavaScript function.
Common_PrintTask_CSharp\PrintTemplates\GoogleChartResults.htm Print template that illustrates creation of an interactive chart through use of a print task JavaScript function and the Google Chart API.
Download the C# files
Common_PrintTask_VBNet\Default.aspx Web page containing a print task used to demonstrate the print templates.
Common_PrintTask_VBNet\Default.aspx.vb Code behind the .aspx page.
Common_PrintTask_VBNet\PrintTemplates\Simple.htm Contains HTML and CSS specifying a custom arrangement and appearance for a print page.
Common_PrintTask_VBNet\PrintTemplates\ServerTimestamp.aspx Print template that includes a timestamp populated through Web-tier code.
Common_PrintTask_VBNet\PrintTemplates\ServerTimestamp.aspx.vb Code behind the .aspx page. Initializes the timestamp.
Common_PrintTask_VBNet\PrintTemplates\ClientTimestamp.htm Print template that includes a timestamp populated by client-tier (JavaScript) code.
Common_PrintTask_VBNet\PrintTemplates\CustomLegend.htm Print template that illustrates creation of a custom legend through use of a print task JavaScript function.
Common_PrintTask_VBNet\PrintTemplates\GoogleChartResults.htm Print template that illustrates creation of an interactive chart through use of a print task JavaScript function and the Google Chart API.
Download the VB.NET files

Download the files for all languages