require(["esri/map", "esri/dijit/Print", "esri/tasks/PrintTemplate"],
function(Map, Print, PrintTemplate) {
var map = new Map("mapDiv", {
center: [14.049, 55.485],
zoom: 3,
basemap: "streets",
logo: false
});
// configure the print task
// see here for more info:
// https://developers.arcgis.com/en/javascript/jsapi/printtemplate.html
var t = new PrintTemplate();
t.layout = "Letter ANSI A Portrait";
t.label = "Portrait (Image)";
t.format = "jpg";
t.layoutOptions = {
legendLayers: [],
scaleBarUnit: "Meters",
titleText: "Demo Title",
authorText: "author text",
copyrightText: "copyright text",
};
t.exportOptions = {
width: 640,
height: 480,
dpi: 96
};
// including only one element into the template array
// will render out only a button, it will otherwise be
// a dropdown selectbox.
var templates = [];
templates.push(t);
// Print-widget from the Dojo Toolkit
// see here for more info:
// https://developers.arcgis.com/en/javascript/jsapi/print.html
printer = new Print({
map: map,
templates: templates,
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
}, dojo.byId("printButton"));
// listeners - added in ArcGis version 3.6
printer.on('print-complete', function(evt){
console.info(evt);
console.log('The url to the print image is : ' + evt.result.url);
});
printer.on('print-start', function(){
console.log('The print operation has started');
});
printer.on('error', function(error){
console.log('The print operation has failed: ' + error);
});
// render the widget gui
printer.startup();
});
<div id="printButton"></div>
<div id="claro">
<div id="mapDiv"></div>
</div>
#mapDiv{
height: 480px;
width: 500px;
}
External resources loaded into this fiddle: