In ArcGIS JavaScript 3.x, there was an event for print-complete.
https://developers.arcgis.com/javascript/3/jsapi/print-amd.html#events
Does 4.x have that? Or is there a way to see when the print widget has completed?
I noticed the Print widget in 4.x has the method 'hasEventListener()' but I can't figure out how it works.
Thanks!
Solved! Go to Solution.
Daniel,
Here's a bit of a workaround, because I don't know why the PrintViewModels state never changes to "complete".
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1, maximum-scale=1,user-scalable=no"
/>
<title>Print widget - 4.12</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
/>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<script src="https://js.arcgis.com/4.12/"></script>
<script>
require([
"esri/views/MapView",
"esri/widgets/Print",
"esri/WebMap",
"dojo/aspect",
"esri/core/watchUtils"
], function(MapView, Print, WebMap, aspect, watchUtils) {
var webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "d6d830a7184f4971b8a2f42cd774d9a7"
}
});
var view = new MapView({
container: "viewDiv",
map: webmap
});
view.when(function() {
var print = new Print({
view: view,
// specify your own print service
printServiceUrl:
"https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
});
watchUtils.when(print, 'viewModel', function(){
aspect.after(print.viewModel, "print", function(deferred){
return deferred.then(function(rslt){
console.log("Print complete");
});
});
});
// Add widget to the top right corner of the view
view.ui.add(print, "top-right");
});
});
</script>
</head>
<body class="calcite">
<div id="viewDiv"></div>
</body>
</html>
If you're using the print widget, you could read the state of the PrintViewModel, and when the print completes, the state should change to complete.
I am using the Print widget.
Would the same problem exist? It still needs an event finish in order for me to look at when the PrintViewModel changed status. What would the code look like for something like that?
Thanks!
Daniel,
Here's a bit of a workaround, because I don't know why the PrintViewModels state never changes to "complete".
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1, maximum-scale=1,user-scalable=no"
/>
<title>Print widget - 4.12</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.12/esri/themes/light/main.css"
/>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<script src="https://js.arcgis.com/4.12/"></script>
<script>
require([
"esri/views/MapView",
"esri/widgets/Print",
"esri/WebMap",
"dojo/aspect",
"esri/core/watchUtils"
], function(MapView, Print, WebMap, aspect, watchUtils) {
var webmap = new WebMap({
portalItem: {
// autocasts as new PortalItem()
id: "d6d830a7184f4971b8a2f42cd774d9a7"
}
});
var view = new MapView({
container: "viewDiv",
map: webmap
});
view.when(function() {
var print = new Print({
view: view,
// specify your own print service
printServiceUrl:
"https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
});
watchUtils.when(print, 'viewModel', function(){
aspect.after(print.viewModel, "print", function(deferred){
return deferred.then(function(rslt){
console.log("Print complete");
});
});
});
// Add widget to the top right corner of the view
view.ui.add(print, "top-right");
});
});
</script>
</head>
<body class="calcite">
<div id="viewDiv"></div>
</body>
</html>
Thanks Robert! That does the trick.
Actually, it doesn't work. The print would "complete" but when I click the link to the pdf it errors.
The link it gives is "<website>/undefined".
Daniel,
It works fine for me. Maybe you are unaware that the print server does not maintain the output file for an extended period of time. The Server deletes all files in the output folder at a certain age interval.
ArcGIS Server periodically deletes (or cleans) old unneeded files from the jobs, output, and system directories to prevent them from taking more disk space than necessary.
Directory | Cleanup mode | Maximum file age |
---|---|---|
jobs | Time since last modified | 360 minutes (6 hours) |
Server directories—ArcGIS Server Administration (Windows) | ArcGIS Enterprise
That's not it. I click the link as soon as the export is finished.
Daniel,
I don't get that at all on my end. Are you using your own print service or something?
Yes, it's a custom print service