Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/support
esri/workers
Class: PrintTask

require(["esri/tasks/PrintTask"], function(PrintTask) { /* code goes here */ });

Description

(Added at v2.6)
The PrintTask class generates a printer-ready version of the map using an Export Web Map Task available with ArGIS Server 10.1 and later. The PrintTask class is used when you want more granular control of the user interface for example, if you want to provide users the ability to define what appears on the printed page. View the Print widget for an out-of-the-box widget that provides a simple user interface for printing maps. The PrintTask requires an ArcGIS Server 10.1 or higher Export Web Map Task.

Known limitations:

  • VectorTileLayer printing requires ArcGIS Server 10.5.1 or later. Using ArcGIS Server 10.5.1, the PrintTask will create a client-side image for the VectorTileLayer in the printout. For printing secure VectorTileLayers with ArcGIS Server 10.5.1 or 10.6.0, the PrintTask will also create a client-side image for the VectorTileLayer in the printout. This has some limitations related to large size printing quality and a dependency on browser window height/width ratio.

Samples

Search for samples that use this class.

Constructors

NameSummary
new PrintTask(url, params?)Creates a new PrintTask object.

Properties

NameTypeSummary
urlStringThe url to the Export Web Map Task.

Methods

NameReturn typeSummary
execute(printParameters, callback?, errback?)DeferredSends a request to the print service resource to create a print page using the information specified in the printParameters argument.

Events

[ On Style Events | Connect Style Event ]
All On Style event listeners receive a single event object. Additionally, the event object also contains a 'target' property whose value is the object which fired the event.

Events

NameEvent ObjectSummary
complete
{
  result: <DataFile>
}
Fired when the print operation is complete.
error
{
  error: <Error>
}
Fired when an error occurs while executing the print task.
Constructor Details

new PrintTask(url, params?)

Creates a new PrintTask object.
Parameters:
<String> url Required URL to the Export Web Map Task. Requires ArcGIS Server 10.1 or later.
<Object> params Optional Parameters for the print task. See the options table below for details on the parameters.
params properties:
<Boolean> async Optional Set to true if the print service is an asynchronous geoprocessing service.
Sample:
require([
  "esri/tasks/PrintTask", ... 
], function(PrintTask, ... ) {
  var url ='http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task';
  var printTask = new PrintTask(url);
  ...
});
Property Details

<String> url

The url to the Export Web Map Task. Requires ArcGIS Server 10.1 or later.
Method Details

execute(printParameters, callback?, errback?)

Sends a request to the print service resource to create a print page using the information specified in the printParameters argument.
Return type: Deferred
Parameters:
<PrintParameters> printParameters Required A PrintParameters object that defines the printing options.
<Function> callback Optional The function to call when the method has completed.
<Function> errback Optional An error object is returned if an error occurs during task execution.
Sample:
require([
  "esri/map", "esri/tasks/PrintTask", "esri/tasks/PrintParameters", ... 
], function(Map, PrintTask, PrintParameters, ... ) {
  var map = new Map( ... );
  var printTask = new PrintTask( ... );
  var params = new PrintParameters();
  params.map = map;
  
  printTask.execute(params, printResult);
  ...
});
Event Details
[ On Style Events | Connect Style Event ]

complete

Fired when the print operation is complete. (Added at v3.5)
Event Object Properties:
<DataFile> result A DataFile that contains the url of the printed image.

error

Fired when an error occurs while executing the print task. (Added at v3.6)
Event Object Properties:
<Error> error Error message returned in a JavaScript error object.
Show Modal