Skip to content
import PrintViewModel from "@arcgis/core/widgets/Print/PrintViewModel.js";
Inheritance:
PrintViewModelAccessor
Since
ArcGIS Maps SDK for JavaScript 4.2

Provides the logic for the Print widget and component.

Known Limitations

See print for a detailed list of known limitations.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

allowedFormats

Property
Type
Formats
Since
ArcGIS Maps SDK for JavaScript 4.15

Specify the print output file format(s) that the user can select based on the options available from the print service. This property can take a string value or an array of string values.

When this value is "all" (default value), all the print service formats are available to be used. When an array of string values is used, only those values that match the options available from the print service will be used. If none of the input string values match those available from the print service, allowedFormats will fallback to default behavior.

See also
Default value
"all"
Example
const print = new Print({
view: view,
printServiceUrl: url
});
print.viewModel.allowedFormats = ["jpg", "png8", "png32"];
view.ui.add(print, {position: "top-right"});

allowedLayouts

Property
Type
Layouts
Since
ArcGIS Maps SDK for JavaScript 4.15

Specify the print output layout(s) that the user can select based on the options available from the print service. This property can take a string value or an array of string values.

When this value is "all" (default value), all the print service layouts are available to be used. When an array of string values is used, only those values that match the options available from the print service will be used. If none of the input string values match those available from the print service, allowedLayouts will fallback to default behavior.

See also
Default value
"all"
Example
const print = new Print({
view: view,
printServiceUrl: url
});
print.viewModel.allowedLayouts = ["a3-landscape", "a3-portrait"];
view.ui.add(print, {position: "top-right"});

browseTemplates

readonly Property
Type
Collection<CustomTemplate>
Since
ArcGIS Maps SDK for JavaScript 4.33

A collection of print templates defined on the Portal.

Print templates are used to apply pre-defined values to existing print options.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

defaultTemplate

readonly Property
Type
CustomTemplate | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.33

The template which defines the default print template.

defaultTemplates

readonly Property
Type
Collection<CustomTemplate>
Since
ArcGIS Maps SDK for JavaScript 4.18

A collection of print templates defined on the Portal.

Print templates are used to apply pre-defined values to existing print options.

effectivePrintServiceUrl

readonly Property
Type
string | null | undefined

The effective URL of the REST endpoint of the Export Web Map Task.

effectiveTemplateCustomTextElements

readonly Property
Type
TemplateCustomTextElements
Since
ArcGIS Maps SDK for JavaScript 4.22

Returns an array of objects of all print templates available on the custom print service to see which templates were published with customTextElements. These values can be overwritten in the UI, or programmatically using the templateCustomTextElements property.

The PrintViewModel calls the Get Layout Templates Info task on the GPServer to discover available templates. If the Get Layout Templates Info task is named differently on the custom print service, then no values will be returned, and it will not be possible to support customTextElements. In this scenario, we recommend republishing the print service to use the standard Get Layout Templates Info name.

error

readonly Property
Type
EsriError | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.33

The Error that occurred during printing.

autocast Property
Type
Collection<FileLink>
Since
ArcGIS Maps SDK for JavaScript 4.33

The collection of links exported from Print.

extraParameters

Property
Type
Record<string, any> | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.20

This option allows passing extra parameters to the print (export webmap) requests.

includeDefaultTemplates

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.18

Indicates whether or not to include defaultTemplates.

Default value
true

loadError

readonlyinherited Property
Type
EsriError | null | undefined
Inherited from: LoadableMixin

The Error object returned if an error occurred while loading.

loadStatus

readonlyinherited Property
Type
"not-loaded" | "loading" | "failed" | "loaded"
Inherited from: LoadableMixin

Represents the status of a load() operation.

ValueDescription
not-loadedThe object's resources have not loaded.
loadingThe object's resources are currently loading.
loadedThe object's resources have loaded without errors.
failedThe object's resources failed to load. See loadError for more details.
Default value
"not-loaded"

loadWarnings

readonlyinherited Property
Type
any[]
Inherited from: LoadableMixin

A list of warnings which occurred while loading.

outSpatialReference

autocast Property
Type
SpatialReference | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.33

The spatial reference used to render the printed map on the server.

portal

autocast Property
Type
Portal
Since
ArcGIS Maps SDK for JavaScript 4.18

It is possible to search a specified portal instance's locator services. Use this property to set this ArcGIS Portal instance to search. This is especially helpful when working with a custom print template.

If this property is set, it is not necessary to set the printServiceUrl property.

See also

portalTemplateIds

deprecatedreadonly Property
Type
string[]
Since
ArcGIS Maps SDK for JavaScript 4.33

An array of portalItem Ids that are used to identify the print templates using layoutItem Id.

printServiceTemplates

readonly Property
Type
Collection<CustomTemplate>
Since
ArcGIS Maps SDK for JavaScript 4.33

A collection of print templates defined on the Portal.

Print templates are used to apply pre-defined values to existing print options.

printServiceUrl

Property
Type
string | null | undefined

The URL of the REST endpoint of the Export Web Map Task. If the portal property is set, it is not necessary to set this property.

printTimeout

Property
Type
number
Since
ArcGIS Maps SDK for JavaScript 4.28

Print timeout value in milliseconds.

Default value
120000

showPrintAreaEnabled

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.30

The initial state of the print area toggle in the UI. When set to true, the print area toggle is enabled by default. When set to false, the print area toggle is disabled by default.

See also
Default value
false

state

readonly Property
Type
State

The view model's state.

Default value
"disabled"

templateCustomTextElements

Property
Type
TemplateCustomTextElements | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.22

An object containing an array of customTextElements name-value pair objects for each print template in a custom print service. Use this property to update the text for custom text elements on the page layout.

The PrintViewModel calls the Get Layout Templates Info task on the GPServer to discover possible customTextElements values for each template. The name of the task must match Get Layout Templates Info, templates must be published with customTextElements, and values must be strings. Values found there will be populated under Advanced options. These values can be overwritten in the UI, or programmatically using this property. To list all print templates available on the print service to see which templates were published with customTextElements, use the effectiveTemplateCustomTextElements property.

Example
const printViewModel = new PrintViewModel({
view: view,
// specify your custom print service
printServiceUrl: "",
// `customTextElements` are defined per print template
// this example has one template with `customTextElements`
templateCustomTextElements: {
// if there were more applicable templates, then we would
// create another object with the template name containing
// an array of more name-value pairs
"Portrait_TextElements": [
// the possible values are defined in the print service
{ "headquarters": "Tampa, Florida" },
{ "division": "NFC South" },
{ "founded": "1976" }
]
}
});

templateOptions

autocast Property
Type
TemplateOptions
Since
ArcGIS Maps SDK for JavaScript 4.33

Defines the layout template options to generate the print page.

templatesInfo

readonly Property
Type
TemplatesInfo | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.33

The service metadata that contains the TemplateOptions.format and TemplateOptions.layout information for the printout.

Example
const print = new Print({
view: view,
printServiceUrl: url
});
view.ui.add(print, {position: "top-right"});
console.log("PrintViewModel templatesInfo Formats: ", print.viewModel.templatesInfo.format.choiceList);
console.log("PrintViewModel templatesInfo Layouts: ", print.viewModel.templatesInfo.layout.choiceList);

updateDelay

Property
Type
number

The time interval in milliseconds between each job status request sent to an asynchronous GP task.

Default value
1000

view

Property
Type
MapView | null | undefined

The view from which Print will operate.

Methods

MethodSignatureClass
addPortalTemplate(portalItem: PortalItem): Promise<void>
applyTemplate(template: CustomTemplate | "map-only" | null | undefined): Promise<void>
cancelLoad
inherited
cancelLoad(): this
createExportedFileLink(fileName: string): FileLink
emit
inherited
emit<Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
export(fileName: string): PrintExport
getLayoutTemplateById(id: string | null | undefined): CustomTemplate | null | undefined
hasEventListener
inherited
hasEventListener<Type extends EventNames<this>>(type: Type): boolean
isFulfilled
inherited
isFulfilled(): boolean
isRejected
inherited
isRejected(): boolean
isResolved
inherited
isResolved(): boolean
load(): Promise<this>
on
inherited
on<Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
print(template: PrintTemplate): Promise<PrintResponse>
removePortalTemplate(template: CustomTemplate): void
toPrintTemplate(templateOptions: TemplateOptions): PrintTemplate
when
inherited
when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>

addPortalTemplate

Method
Signature
addPortalTemplate (portalItem: PortalItem): Promise<void>

Adds a template to a portal.

Parameters
ParameterTypeDescriptionRequired
portalItem

The PortalItem used to create a print template. This template will be added to the browseTemplates collection.

Returns
Promise<void>

Resolves when the template is added.

applyTemplate

Method
Signature
applyTemplate (template: CustomTemplate | "map-only" | null | undefined): Promise<void>

Applies the specified print template to the templateOptions property. This method updates the layout, custom text elements, and other template-specific options based on the provided template. If the template is "map-only", it sets the layout to "map-only" and skips additional processing.

If the provided template is invalid or not supported, the method falls back to the default template (if available) or resets the templateOptions to their initial state.

Parameters
ParameterTypeDescriptionRequired
template
CustomTemplate | "map-only" | null | undefined

The CustomTemplate will be applied.

Returns
Promise<void>

Resolves when the template is applied.

cancelLoad

inherited Method
Signature
cancelLoad (): this
Inherited from: LoadableMixin

Cancels a load() operation if it is already in progress.

Returns
this
Method
Signature
createExportedFileLink (fileName: string): FileLink

Creates a new FileLink object for the given file name. This method generates a unique file name with the appropriate extension based on the selected print template format and updates the internal file name map to track the number of exports with the same name.

Parameters
ParameterTypeDescriptionRequired
fileName

The base name of the file to be exported (without extension).

Returns
FileLink

A FileLink object containing the file name, extension, and export count.

emit

inherited Method
Signature
emit <Type extends EventNames<this>>(type: Type, event?: this["@eventTypes"][Type]): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin
Since
ArcGIS Maps SDK for JavaScript 4.5

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

event
this["@eventTypes"][Type]

The event payload.

Returns
boolean

true if a listener was notified

export

Method
Signature
export (fileName: string): PrintExport

Exports the current print template to a file.

This method generates a file link and initiates the export process using the current print template options. The returned object contains a FileLink instance and a promise that resolves when the export is complete.

Parameters
ParameterTypeDescriptionRequired
fileName

The name of the file to export (without extension).

Returns
PrintExport

An object containing: - link: A FileLink object representing the exported file. - promise: A promise that resolves to the FileLink when the export is complete.

getLayoutTemplateById

Method
Signature
getLayoutTemplateById (id: string | null | undefined): CustomTemplate | null | undefined

Returns a CustomTemplate with the specified id. The associated properties are useful for print considerations.

Parameters
ParameterTypeDescriptionRequired
id

The id of the CustomTemplate.

Returns
CustomTemplate | null | undefined

Returns a CustomTemplate, which contains both layoutTemplateInfo and mapSurroundInfoOptions.

Example
this.viewModel.getLayoutTemplateById(this.templateOptions.id);

hasEventListener

inherited Method
Signature
hasEventListener <Type extends EventNames<this>>(type: Type): boolean
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameters
ParameterTypeDescriptionRequired
type
Type

The name of the event.

Returns
boolean

Returns true if the class supports the input event.

isFulfilled

inherited Method
Signature
isFulfilled (): boolean
Inherited from: EsriPromiseMixin

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).

isRejected

inherited Method
Signature
isRejected (): boolean
Inherited from: EsriPromiseMixin

isRejected() may be used to verify if creating an instance of the class is rejected. If it is rejected, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been rejected.

isResolved

inherited Method
Signature
isResolved (): boolean
Inherited from: EsriPromiseMixin

isResolved() may be used to verify if creating an instance of the class is resolved. If it is resolved, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been resolved.

load

Method
Signature
load (): Promise<this>

This method should be called to load the view model's printing resources.

Returns
Promise<this>

When resolved, the view model has loaded the print service metadata necessary for printing.

on

inherited Method
Signature
on <Type extends EventNames<this>>(type: Type, listener: EventedCallback<this["@eventTypes"][Type]>): ResourceHandle
Type parameters
<Type extends EventNames<this>>
Inherited from: EventedMixin

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters
ParameterTypeDescriptionRequired
type
Type

An event or an array of events to listen for.

listener
EventedCallback<this["@eventTypes"][Type]>

The function to call when the event fires.

Returns
ResourceHandle

Returns an event handler with a remove() method that should be called to stop listening for the event(s).

PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example
view.on("click", function(event){
// event is the event handle returned after the event fires.
console.log(event.mapPoint);
});

print

Method
Signature
print (template: PrintTemplate): Promise<PrintResponse>

Prints (exports) the current MapView according to selected options.

Parameters
ParameterTypeDescriptionRequired
template

The PrintTemplate is used to specify the layout template options which is then used by the PrintTask to generate the print page.

Returns
Promise<PrintResponse>

Resolves to an object with the following properties:

PropertyTypeDescription
urlStringURL to the exported printout.

removePortalTemplate

Method
Signature
removePortalTemplate (template: CustomTemplate): void

Removes Template from browseTemplates.

Parameters
ParameterTypeDescriptionRequired
template

The CustomTemplate will be removed.

Returns
void

Resolves when the template is removed.

toPrintTemplate

Method
Signature
toPrintTemplate (templateOptions: TemplateOptions): PrintTemplate

Helper method to create print templates from a template options object.

Parameters
ParameterTypeDescriptionRequired
templateOptions
Returns
PrintTemplate

when

inherited Method
Signature
when <TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>
Type parameters
<TResult1 = this, TResult2 = never>
Inherited from: EsriPromiseMixin
Since
ArcGIS Maps SDK for JavaScript 4.6

when() may be leveraged once an instance of the class is created. This method takes two input parameters: an onFulfilled function and an onRejected function. The onFulfilled executes when the instance of the class loads. The onRejected executes if the instance of the class fails to load.

Parameters
ParameterTypeDescriptionRequired
onFulfilled

The function to call when the promise resolves.

onRejected

The function to execute when the promise fails.

Returns
Promise<TResult1 | TResult2>

Returns a new promise for the result of onFulfilled that may be used to chain additional functions.

Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same way
let view = new MapView();
view.when(function(){
// This function will execute once the promise is resolved
}, function(error){
// This function will execute if the promise is rejected due to an error
});

Type definitions

PrintExport

Type definition

The printed export.

Property
Type
FileLink

The link for the exported file.

promise

Property
Type
Promise<FileLink>

The promise for the exported file.

SubmitEvent

Type definition
Property
Type
FileLink

An object representing the results of submitting the print.

CompleteEvent

Type definition
Property
Type
FileLink

An object representing the results of the print.