Welcome to ESRI Blogs

Print Task Sample

In this post, Bryan Baker comments on a new sample you can use to add a Print task to your Web ADF applications: 

A sample print task for the Web ADF for the Microsoft .NET Framework is now available at the ESRI Developer Network website. This sample allows users to do simple printing of a map and task results. ESRI plans to include printing in the upcoming 9.3 version, but this sample should get you started with printing from the Web ADF. The sample works in the Web ADFs for both ArcGIS Server and ArcIMS.

The sample task prints all resources and services in the Map control, including graphics layers and scalebar. It merges the resources into a single image that the browser displays in a new window. If the user has generated task results, such as with a query or identify, the user may also choose to print those results as a table below the map. The sample also allows entering a custom title. It does not currently support printing other items in the website, such as the table of contents or overview map.

In the website, the Map may be zoomed to any location, and other map properties may be set, such as turning layers on/off or displaying highlights from task results. If other tasks, such as a QueryAttributes task, have been added, the print task displays a list of results from those tasks to print. From the Print task dialog, the user may set a print title and task results to print (if any have been generated in the website). Clicking Print in the dialog pops up a new browser window with the title, map and task results (if any). The user may then print the page with their usual printing methods, to any available printer.

Some additional highlights:

  • The user may choose print size, resolution and scale. Resolution (e.g., 300 dpi) is accomplished via standard HTML in the browser.
  • The administrator can configure properties of the task, such as the default print page title, the maximum print size, whether to allow printing task results, and whether to print the scale bar on the map.

Installing the sample Print Task

You can install and use the sample task as-is, or customize it for your own use. To install the task you need to:

  1. Make sure the Web ADF is already installed, with Service Pack 1 or higher applied.
  2. Unzip the downloaded file.
  3. Register the task with the .NET global assembly cache.
  4. (Optional) Add the task to the Visual Studio toolbox.
  5. (Optional) Add the task to Manager.

Details for these steps are in the instructions at the EDN website, and also in the Readme.doc file accompanying the sample. The sample includes the source code for the task, which can be customized. (Note: If you downloaded the EDN sample before the date of this post, you should revisit the EDN site for updated instructions for adding the task to Manager.)

The instructions on EDN include the path to the ArcGIS Server Manager. To add the task to the ArcIMS Web Manager, follow the same instructions, except add the appropriate entry into the Tasks.xml file for the ArcIMS Web Manager, which by default is in C:\Inetpub\wwwroot\ArcIMS\Manager\Applications\App_Data.

If you install a service pack for the Web ADF, you will need to reinstall the task into Manager. Uninstalling the task must be done manually; see the readme document for details.

Adding the sample Print Task to a Website

After you install the task, you can add it to a Web ADF web page, using either Manager or Visual Studio. In Manager, you should see the Print task in the list of available tasks when you create or edit a website. Add it to the list of tasks in the website, then configure it (you must click Configure for any task, even if you just keep the default settings). The configuration settings allows you to set properties such as the maximum allowed size and resolution and default title for the print page. When you save the website, the print task should appear in the menu of tasks in the website.

The Print task appears in the left menu of the Web mapping application

From Visual Studio, add the Print task like other tasks, usually into a TaskManager. Set the Print task's results container to a TaskResults control on the page, using the "smart tag" in the upper right of the task. You can set other properties in the Properties window of Visual Studio. You can set the task's Visible property to false if desired, and make sure a Menu or TreeView control is buddied to the TaskManager so the user sees a list of tasks to open.

The task currently requires that the web page include a Map control. If no Map control is present, an error will occur. The code could be customized to allow for a page with only tasks, such as a query task, with no map. Also, please note that the task will not work with ArcGIS Online services (currently in beta), since those services currently deliver maps only as cached tiles (this task requests new map images for printing).

This task does not use the layout of any ArcGIS Server service in the website. If you want to print using an MXD-based layout, you might want to check out Ismael Chivite's sample posted at ArcScripts that prints layouts.

We'd welcome your comments on this sample. The download page for the sample includes a user comments section. We'll also post periodic updates to the sample based on feedback.

You can try out the task yourself by printing a map from this example web application.

Published Wednesday, May 16, 2007 4:15 PM by sterlingdq

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Print Task Sample

I think you should add support for adding a legend dynamically for layers that are turned on.  Also, The text map title is kind of hokey, editing the title in the page layout looks nicer crisper.  

What would be really nice would be if you could change the size of the paper, and the map would stretch to fit the page size.  Almost like setting it to 100% width 100% height instead of a static pixel height and width.  When using the page layout arc objects, the page size changes but the objects do not stretch to fit - they stay the same size as they were created in the page layout of the mxd.  

Thursday, May 17, 2007 10:10 AM by sgourley

# re: Print Task Sample - legend and sizing

We're looking into adding legend and other items for printing in 9.3. The issue right now is that the controls do not have an export-to-image method, so for a legend, you'd have to construct it by iterating through the resources and layers and outputting the swatches and labels.

On the auto-sizing question, the sample creates a standard web page, rather than a PDF or other document. Web pages do not have a paper-page size per se - that is determined by how you choose to print the page. So it would not really be feasible to specify a page size in this context. The sample's map-width size in real units (inches/cm) partially addresses that issue.

Please keep in mind that this is a sample, not a finished product, though hopefully it will help users as-is without having to tackle code. Developers are welcome to customize and extend it for their own needs.

Thursday, May 17, 2007 10:37 AM by bb1769

# re: Print Task Sample

If the page URL already has a variable in the query string, the control will not display the map because it appends another "?" at the front instead of an ampersand, so the URL wouldn't be valid for the image. Can this be modified? ex. http://mymap.com/default.aspx?map=hydrology... when printing from the above URL, the "?getmap.." querystring is appended to the end of that, when it should be "&getmap" instead...
Friday, May 18, 2007 1:15 PM by Brent S

# re: Print Task Sample

I believe there is a possible bug in the task. If I run the task with a selected polygon feature, the selection aligns with features properly - the first time. However, if I run the task again - and change the scale - the selection graphic is no longer aligned with the map features. Is this me or does this happen to others as well?
Tuesday, May 22, 2007 10:32 AM by GregK

# re: Print Task Sample

In response to my earlier post, the place to modify the url to place an ampersand instead of a question mark if your map url already includes a query string is in the GenerateAndStoreMap() procedure in PagePrinter.vb (line 259). It would probably be best to examine the current URL to see whether a query string exists, and then append the correct character based on that.

Monday, June 04, 2007 9:17 AM by gigemboy

# re: Print Task Sample

Thanks for the task; this will prove to be helpful. However, we are disappointed to learn that printing is not included out of the box with ArcGIS Server. Telling clients to wait until the next release to print a map is not acceptable. Did ESRI forget that users tend to want to print maps?
Monday, June 04, 2007 5:17 PM by Scott

# re: Print Task Sample

I am having the same issue as GregK. If a polygon feature is selected and I try to print the resulting page shows the selected parcel moved significantly to the right. Is there a solution to this?
Tuesday, June 12, 2007 9:09 AM by Matt L

# Server GIS - What content has been added or updated recently?

SP3 - Continued updates and improvements to the ADF API Reference Programming language(s): C# or VB.Net

Wednesday, August 08, 2007 2:08 PM by EDN Website Blog

# Error in WizardPage.aspx

I am gettin the following error when I try to edit tasks or create a new web application. Any thoughts? An error has occurred at: http://localhost/ArcGIS/Manager/Applications/WizardPage.aspx?siteName=Cumberland&hostName=CCPASR60&path=\\CCPASR60\c$\inetpub\wwwroot\Cumberland\. '<', hexadecimal value 0x3C, is an invalid attribute character. Line 10, position 1.
Wednesday, September 19, 2007 12:50 PM by Justin

# re: Print Task Sample

Does this one print out legend? Thanks.
Monday, October 08, 2007 2:58 PM by Joe

# re: Print Task Sample

How would you go about executing this task programmatically? Without using the floating panel control? Thanks
Monday, October 08, 2007 3:12 PM by Adam

# re: Print Task Sample - Legend

Joe - this print task sample does not include a legend. That's a fairly complex thing to do, since the Web ADF can use services from a variety of sources (ArcGIS Server, ArcIMS, WMS, ArcWeb Services). The good news is that the 9.3 Print task will include a legend.
Tuesday, October 09, 2007 11:24 AM by Bryan Baker

# re: Print Task Sample

I notice when the print preview page is generated, I can only print in portrait, which cuts off my map and task results. Anyone know where to alter the code to allow the user to chose, or to just enable the browser preferences? Thanks!
Thursday, October 11, 2007 7:37 AM by Shannon

# re: Print Task Sample - orientation

Shannon - browser security prevents web applications from setting the orientation or size of the Printer page. The user needs to set the print orientation and other settings when they go to print. The best approach is probably to add a message somewhere that lets the user know to set the print orientation etc. before printing.
Friday, October 12, 2007 9:50 AM by Bryan Baker

# re: Print Task Sample - executing programmatically

Adam - you should be able to call the task programmatically by calling the JavaScript function that the task's submit button calls. That function is called PrintTaskSendRequest, and it takes three arguments: the ID of the task's submit button, the callback function string, and the ID of the Map control.

The easiest way to get the full call to this function is to copy it from the Submit button for the print task. To find it, view the source of the browser page (in IE, Page-View Source), and search for the "btnSubmit". "btnSubmit" is the server-side ID of the button. In the <input> tag for this button, you'll see the onclick attribute, which will look something like this:

onclick="PrintTaskSendRequest(this, "WebForm_DoCallback('TaskManager1$PrintTask_CSharp2',argument,processCallbackResult,context,postBackError,true)", "Map1");return false;"

You can copy this call to PrintTaskSendRequest and use it elsewhere on the page, either as the onclick for another button, or within your own JavaScript function (in which case, just use the PrintTaskSendRequest(...) part, not the 'return false').

Monday, October 15, 2007 10:34 AM by Bryan Baker

# re: Print Task Sample

If 9.3 will have a more functional print task feature, what are we looking at as far as an upgrade path. My company has spent a year re-developing our 9.1 application in 9.2. Will I be spending another year to re-write for 9.3 or will this be a minor upgrade compared to the 9.1 to 9.2 release? The major time killer was the move to using the callback framework. Also, I have noticed that printing images from ArcWeb Services and ArcGIS Online is not available. Any idea when it will be? My application is overlaying local data (ArcGIS Server local) with two online data sources and not being able to print what the user is seeing in the map control is not acceptable. For me and anyone else consuming ArcWeb Services and ArcGIS Online, there basically is no print functionality at all.
Tuesday, October 16, 2007 2:35 PM by David

# Compatibility with GridResults

Any chance that anyone has modified this PrintTask to work with Tom Brenneman's custom GridResults?
Friday, November 02, 2007 11:13 AM by Randy

# re: Print Task Sample

Is there a way to print the results/attributes from a TreeViewPlus control
Wednesday, November 28, 2007 2:02 PM by Victoria

# re: Print Task Sample

Is it possible to change the pixellimit or image memory limit for a map service in ArcGIS Server to allow for a larger print size?
Thursday, November 29, 2007 5:52 AM by Alex

# re: Print Task Sample

Check out this link i found. It talks about using javascript to print. the article is written for java adf but we can use the same concept with .net adf too. i am impressed. http://arkblog.wordpress.com/2007/12/19/print-made-easy/
Friday, December 21, 2007 1:08 PM by sam

# re: Print Task Sample

I am trying to use the print task on an application that uses services from ArcGIS Online. I get an "Error in the callback" message unless I turn off the services from ArcGIS Online. Any way around this?
Thursday, December 27, 2007 9:25 AM by tim

# re: Print Task Sample

Tim- As mentioned near the end of the post, this task will not work with ArcGIS Online services because the task requests a new image from the server. ArcGIS Online services are configured to return only pre-rendered tiles and will not respond to the ExportMapImage request used by the Print Task.

Thursday, December 27, 2007 9:49 AM by sterlingdq

# [转载]关于自定义任务(Tasks)的心得

Wednesday, February 13, 2008 6:17 AM by 【曾华清】

# re: Print Task Sample

Will this tool work with SP4?
Friday, February 22, 2008 9:05 AM by bbehling

# re: Print Task Sample - SP4

The print task sample should work with SP 4. When service packs are installed, there are also policy files installed that allow components from earlier versions to work with the later version numbers. If you find problems, let us know.

Friday, February 22, 2008 9:45 AM by bb1769

# re: Print Task Sample

Hi all, This sample is working with SP4, but its throwing callback exception when user types in Arabic title, while opening print page window. Any help to solve this problem will be appreciated.

Regards

Wednesday, February 27, 2008 7:50 AM by syednaimath

# re: Print Task Sample

Hi,

We're getting this error:

Error file generated by LayoutSOE

 Template:D:\GIS\XX\XXXX\ArcServer\XXXXXX Print Layout.mxd

 Output File:D:\gisoutput\arcgisoutput\367a8884-eb02-41dc-9e28-d65d987adef4.pdf

Error on function 'Export. Error description: Value does not fall within the expected range.

The error occurs after the layout "generates successfully" in the Results panel.  I'm curious as to whether you've seen this error before.  Thanks

Monday, March 03, 2008 7:35 AM by marracci

# re: Print Task Sample (follow-up)

Seems that we figured out what might be causing the trouble.  We updated the map service's representative .mxd locally instead of on the arcGIS Server.  Unfortunately, we updated to SP4 locally, yet the Server is still on SP2.<br><br> When we uploaded the SP4 .mxd to the server and restarted the map service, the print function's end result failed.<br><br>  We got around this by re-editing a vintage SP2 .mxd directly on the server (thank you <i>Archive</i>) and re-starting the service.<br><br>  <b>Short story:</b> never mix Service Packs, ESRI hasn't figured out how to create them in a symbiotic way.

Tuesday, March 04, 2008 8:20 AM by marracci

# re: Print Task Sample

I noticed someone already asked in November but thought I'd check again. Anyone get this to work with Tom Brenneman's custom GridResults?
Tuesday, March 25, 2008 2:56 PM by RDolormente

# re: Print Task Sample

I have a problem running applications with this task. If I run the app in debug mode from VS, all works fine, but if I run the app from browser the error appears: The map resource 'xxx' is not a mapResourceLocal or it was not found in the map. at ESRI.APL.LayoutSOETask.GetLayoutTemplates() at ESRI.APL.LayoutSOETask.OnPreRender(EventArgs e) Any ideas/experience? Thanks
Friday, April 04, 2008 6:51 AM by gnevan

# re: Print Task Sample

I have the same issue as another developer at: http://forums.esri.com/Thread.asp?c=158&f=1701&t=231407

Is there an issue with the Print Task, IE7, or HP printers?

We are currently using SP2 on ESRI software, but I have no problems in Firefox.

I really would like to know what causes this.

Thanks,

Chris

Monday, April 28, 2008 2:45 PM by csergent06

# re: Print Task Sample

Another HP print problem in the forums:

http://forums.esri.com/Thread.asp?c=93&f=1731&t=243729

Chris

Monday, April 28, 2008 2:59 PM by csergent06

# re: Print Task Sample

Monday, April 28, 2008 3:09 PM by csergent06

# re: Print Task Sample

Hi,

The print preview window in Firefox does not have a print button. Try opening the example application mentioned above in firefox. Create a print preview page. I get a print button in IE but not in Firefox.

Thanks,

Chris

Tuesday, June 03, 2008 4:13 PM by arvinder2005

# re: Print Task Sample

Hi, When I try the example Web Application, it looks like changing the scale does not affect the result map, i.e. it always return the same map, no matter which scale I gave. Why is that ? Thanks, Miri
Sunday, July 27, 2008 4:39 AM by Miri Eshel

# re: Print Task Sample

How will this sample work with cached map services? In my case, the resulted image has a white border on the right for a certain image size. Seems like the portion cannot be rendered. Is there any workaround?
Wednesday, April 08, 2009 1:53 AM by How Weixian

# re: Print Task Sample

Hi, how will this sample work with cached map services? it seems tat it is unable to get some portion of the map when image size exceeds 16 inch.
Wednesday, April 08, 2009 6:15 PM by Sam

# re: Print Task Sample

Did anybody find the solution to the HP problem. My map image will not print with a HP printer using IE7, but it does work with FireFox.
Monday, June 15, 2009 2:14 PM by vicki magnis

# re: Print Task Sample

We solved our problems by using the HP's PCL driver, not the PS one.
Wednesday, June 17, 2009 8:24 AM by Charlie

# re: Print Task Sample

Will this tool work with 9.3.1?
Monday, July 06, 2009 10:12 PM by Iverson

# re: Print Task Sample

i am also looking for 9.3.1. Is it possible to get code of Simple Print Task for 9.3.1 I want to change the Map template according to size selection.
Friday, July 10, 2009 9:19 AM by Pragnesh

# Print Task: Graphics Layer

Im trying to use print Tasks with a graphics, and im having trouble. Looking at the code, It looks as if you have to name certain layers (in the graphics service) to certain things: Like 'Polygon' for polygons, etc, but this doesnt seam to work. Im wondering if anyone knows of documentation to getting graphics working. Maybe im just missing something?
Monday, July 13, 2009 1:16 PM by Chris

Leave a Comment

(required) 
required 
(required)