require(["esri/rest/support/PrintTemplate"], (PrintTemplate) => { /* code goes here */ });
import PrintTemplate from "@arcgis/core/rest/support/PrintTemplate.js";
esri/rest/support/PrintTemplate
Defines the layout template options used by print and the PrintViewModel.print() method to generate the print page.
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
When | PrintTemplate | ||
The name of the class. | Accessor | ||
Define the map width, height and dpi. | PrintTemplate | ||
When true, the feature's attributes are included in feature collection layers even when they are not needed for rendering. | PrintTemplate | ||
The output format for the printed map. | PrintTemplate | ||
When | PrintTemplate | ||
When | PrintTemplate | ||
The layout used for the print output. | PrintTemplate | ||
A custom layout hosted as a portal item. | PrintTemplate | ||
Defines the layout elements. | PrintTemplate | ||
The optional map scale of the printed map. | PrintTemplate | ||
The name of the report template. | PrintTemplate | ||
A custom report template hosted as a portal item for report printing. | PrintTemplate | ||
This object links the various report elements to their data source. | PrintTemplate | ||
Define whether the printed map should preserve map scale or map extent. | PrintTemplate | ||
When | PrintTemplate |
Property Details
-
attributionVisible
attributionVisible Boolean
-
When
false
, the attribution is not displayed on the printout. This only applies when the layout value ismap-only
. Reference our policies on Licensing & Attribution for specific attribution requirements.- Default Value:true
-
exportOptions
exportOptions Object
-
Define the map width, height and dpi. Required when
layout = 'map-only'
. See the object specification table below for available options to set for exportOptions.- Properties
-
width Number
Map width. Default value is 800. If the
dpi
value is modified, then thewidth
andheight
will be modified proportional to thedpi
change. If thewidth
value is modified independently, thedpi
andheight
values will not be modified.height NumberMap height. Default value is 1100. If the
dpi
value is modified, then thewidth
andheight
will be modified proportional to thedpi
change. If theheight
value is modified independently, thedpi
andwidth
values will not be modified.dpi NumberResolution in dots per inch. Default value is 96. If the
dpi
value is modified, then thewidth
andheight
will be modified proportional to thedpi
change.
-
forceFeatureAttributes
forceFeatureAttributes Boolean
-
When true, the feature's attributes are included in feature collection layers even when they are not needed for rendering. By default they are removed to reduce the request size. Only applicable to custom print services which use the feature attributes, for example to display a table of features and their attributes.
- Default Value:false
-
format
format String
-
The output format for the printed map.
Possible Values:"gif" |"jpg" |"png8" |"png32" |"tiff" |"pdf" |"svg" |"svgz" |"aix" |"eps"
- Default Value:"png32"
-
includeCharts
includeCharts Boolean
Since: ArcGIS Maps SDK for JavaScript 4.28PrintTemplate since 4.20, includeCharts added at 4.28. -
When
true
, charts will be included in the printout request. Charts are stored inside an operational layer definition.Use this property with layoutOptions.elementOverrides. The required properties are:
elementName
,sourceChartId
,sourceLayerId
.The
elementName
can be found from theGet Layout Templates Info
task on the GPServer. ThesourceChartId
can be found in theid
property of thecharts
property of the operational layer. ThesourceLayerId
can be found in theid
property of the operational layer. The default value of thevisible
property can be found from theGet Layout Templates Info
task on the GPServer. This must be set totrue
for the printed charts to display if the default isfalse
. Lastly, thefilterType
property is read from theGet Layout Templates Info
task on the GPServer and does not require a value, but it can also be overwritten. Possible values are:all
,visible
, andselected
.Known Limitations
- The print template must be configured to support charts.
- This capability is only available with ArcGIS Server version 11.2 or later.
- Currently, charts can only be printed when published as part of a FeatureLayer hosted on ArcGIS Enterprise.
- Default Value:false
- See also
Exampleconst template = new PrintTemplate({ layout: "A4 Portrait with Chart", format: "png32", includeCharts: true, layoutOptions: { elementOverrides: { "line_chart_frame_1": { "sourceLayerId": "188dad6022b4-layer-2", "sourceChartId": "Chart 168786106706" }, "bar_chart_frame_2": { "sourceLayerId": "188dad6022b4-layer-2", "sourceChartId": "Chart 168786109405" } } } });
-
includeTables
includeTables Boolean
Since: ArcGIS Maps SDK for JavaScript 4.26PrintTemplate since 4.20, includeTables added at 4.26. -
When
true
, tables will be included in the printout request. A table is a non-spatial dataset in a feature service or map service.Note that for the table to display in the printout, the print template must be configured to support tables.
- Default Value:false
- See also
-
layout
layout String
-
The layout used for the print output. When the value is
map-only
or is empty, the output map does not contain any page layout surroundings (for example, title, legend, scale bar and so forth). The print service provides out-of-the-box templates listed in possible values. The server administrator can add additional templates to the print service.Possible values are listed below:
Value Description map-only Map does not contain any layout elements. Only map image is printed. a3-landscape A3 Landscape a3-portrait A3 Portrait a4-landscape A4 Landscape a4-portrait A4 Portrait letter-ansi-a-landscape Letter ANSI A Landscape letter-ansi-a-portrait Letter ANSI A Portrait tabloid-ansi-b-landscape Tabloid ANSI B Landscape tabloid-ansi-b-portrait Tabloid ANSI B Portrait Possible Values:"map-only" |"a3-landscape" |"a3-portrait" |"a4-landscape" |"a4-portrait" |"letter-ansi-a-landscape" |"letter-ansi-a-portrait" |"tabloid-ansi-b-landscape" |"tabloid-ansi-b-portrait"
- Default Value:"map-only"
-
layoutItem
layoutItem PortalItem
Since: ArcGIS Maps SDK for JavaScript 4.25PrintTemplate since 4.20, layoutItem added at 4.25. -
A custom layout hosted as a portal item. To use this property, the print service must be hosted on an ArcGIS Server that is federated with the same portal as the portal item.
Known Limitations
This capability is only available with ArcGIS Enterprise 11.1 or later.
Examplelet item = new PortalItem({ id: "affa021c51944b5694132b2d61fe1057" }); // specify your own print service const printURL = "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"; const template = new PrintTemplate({ layoutItem: item }); const params = new PrintParameters({ view, template }); print.execute(printURL, params).then(printResult, printError);
-
layoutOptions
layoutOptions Object
-
Defines the layout elements. It's an object with the following properties:
- Properties
-
optional The text used for the map title if the specified layout contains a title text element.
optional The text used for the author if the specified layout contains an author text element.
optional The text used for the copyright if the specified layout contains a copyright text element.
optional Default Value:MilesThe unit used for the scalebar.
Possible Values:"Miles"|"Kilometers"|"Meters"|"Feet"
legendLayers LegendLayer[]|null|undefinedAn array of LegendLayer containing the ids of the layers that will be included in the legend. GraphicsLayer will not appear in the legend. If
legendLayers
is not specified, all layers wherelegendEnabled
istrue
, except GraphicsLayer, will be present in the legend. To specify that no layers will be included in the legend, setlegendLayer = []
.optional An array of name-value pair objects. Use this property to update the text for custom text elements on the page layout. Values must be strings. The custom text elements must exist in the print service. All out-of-the-box print service layout templates contain a text element named
date
that gets populated by default with the system date-time, but can be overwritten.optional An object containing optional elements from the print service that can be updated.
ExamplelayoutOptions: { titleText: "My Print", authorText: "Sam", copyrightText: "My Company", scalebarUnit: "Miles", // the following text elements must // exist in the print service to appear customTextElements: [ {"description": "My description"}, {"location": "My Location"}, {"date": "11/11/2020, 11:11:20 AM"} ], elementOverrides: { "North Arrow": { "visible": true } } }
-
outScale
outScale Number
-
The optional map scale of the printed map. Only applies when
scalePreserved
istrue
. IfoutScale
is 0, then the printed map will use the scale of the input map.- Default Value:0
-
report
report String
Since: ArcGIS Maps SDK for JavaScript 4.28PrintTemplate since 4.20, report added at 4.28. -
The name of the report template. Also requires a value to be set for reportOptions to print. Typically, a report will be printed with a map in a multi-page
pdf
file, but the layout property must be set to something other thanmap-only
for the map to be printed with the report.There is no
report_only
template. To only print a report without a map, set the appropriate value for report, and either set layout tomap-only
, or do not set a value forlayout
. A value is not required forlayout
since it defaults tomap-only
.When publishing a print service with reports, the print service provides possible names for out-of-the-box report templates. Possible values can be found from: the report template parameter at the
Export Web Map
task on the GPServer, theGet Report Templates Info
task on the GPServer, or from a custom report template hosted as a portal item using reportItem. If reportItem property is set, report will be ignored.Some possible values are listed below:
Value Description attribute-list-letter-ansi-a-landscape "Attribute List Letter ANSI A Landscape" attribute-list-letter-ansi-a-portrait "Attribute List Letter ANSI A Portrait" attribute-list-with-group-letter-ansi-a-landscape "Attribute List With Group Letter ANSI A Landscape" attribute-list-with-group-letter-ansi-a-portrait "Attribute List With Group Letter ANSI A Portrait" page-per-feature-letter-ansi-a-landscape "Page per Feature Letter ANSI A Landscape" page-per-feature-letter-ansi-a-portrait "Page per Feature Letter ANSI A Portrait" Known Limitations
- Currently, reports can only be printed in
pdf
format. - The print template and the print service must be configured to support reports.
- This capability is only available with ArcGIS Server version 11.2 or later.
Possible Values:"attribute-list-letter-ansi-a-landscape" |"attribute-list-letter-ansi-a-portrait" |"attribute-list-with-group-letter-ansi-a-landscape" |"attribute-list-with-group-letter-ansi-a-portrait" |"page-per-feature-letter-ansi-a-landscape" |"page-per-feature-letter-ansi-a-portrait"
Exampleconst template = new PrintTemplate({ layout: "A4 Landscape", report: "Theme Parks A4 Landscape", format: "pdf", reportOptions: {} });
- Currently, reports can only be printed in
-
reportItem
reportItem PortalItem
Since: ArcGIS Maps SDK for JavaScript 4.28PrintTemplate since 4.20, reportItem added at 4.28. -
A custom report template hosted as a portal item for report printing. Also requires a value to be set for reportOptions to print.
To use this property, the print service must be hosted on an ArcGIS Server that is federated with the same portal as the portal item. If this property is set, it will take precedence over the report property.
Typically, a report will be printed with a map in a multi-page
pdf
file, but the layout property must be set to something other thanmap-only
for the map to be printed with the report. To only print a report without a map, set the appropriate value for reportItem, and either set layout tomap-only
, or do not set a value forlayout
. A value is not required forlayout
since it defaults tomap-only
.Known Limitations
- Currently, reports can only be printed in
pdf
format. - The print template and the print service must be configured to support reports.
- This capability is only available with ArcGIS Enterprise version 11.2 or later.
Exampleconst template = new PrintTemplate({ layout: "map-only", format: "pdf", reportItem: {id: "9a7aefd5bcd24bf7891264e0c5ecgbb8"}, reportOptions: {} });
- Currently, reports can only be printed in
-
reportOptions
reportOptions Object
Since: ArcGIS Maps SDK for JavaScript 4.28PrintTemplate since 4.20, reportOptions added at 4.28. -
This object links the various report elements to their data source. To be used with a valid report or reportItem value.
This property requires the developer to know the names and values of the report elements and their data sources, as well as how they are organized in the report template.
Known Limitations
- Currently, reports can only be printed in
pdf
format. - The print template and the print service must be configured to support reports.
- This capability is only available with ArcGIS Server version 11.2 or later.
Exampleconst template = new PrintTemplate({ layout: "A4 Landscape", report: "Theme Parks A4 Landscape", format: "pdf", reportOptions: { "reportSectionOverrides": { "Related Report": { "fieldElements": { "Related Field 1":"AttractionName", "Related Field 2":"Description" }, "fieldLabelElements": { "Related Field Label 1":"Name", "Related Field Label 2":"Description" }, "groupSections": { "[related-report-name]: Group Header: [group-field-value]":"AttractionType" }, "relatedId":"R0L1Parks_ReportL0_ReportBase", "sourceId":"18a86753b0-layer-2" }, "Report Section":{ "fieldElements":{ "Field 1":"Website", "Field 2":"City", "Field 3":"State", "Field 4":"OpeningTime", "Field 5":"ChildPrice", "Field 6":"AdultPrice" }, "groupSections":{ "Group field: [group-field-value]":"Name" }, "name":"USA Theme Parks", "sourceId":"12a387780ai-layer-1", "statisticElements":{ "Count Statistic 1":"Name" } } } } });
- Currently, reports can only be printed in
-
scalePreserved
scalePreserved Boolean
-
Define whether the printed map should preserve map scale or map extent. If
true
, the printed map will use theoutScale
property or default to the scale of the input map. Iffalse
, the printed map will use the same extent as the input map and thus scale might change.- Default Value:true
-
showLabels
showLabels Boolean
-
When
true
, labels will be shown on the layout.- Default Value:true
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Returns true if a named group of handles exist. | Accessor | ||
Removes a group of handles owned by the object. | Accessor |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, addHandles added at 4.25. -
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");