Select to view content in your preferred language

Print task causes severe ArcGIS for Server log messages

1417
3
01-17-2017 10:31 AM
NhuMai
by
Deactivated User

I've tried to implement a print widget using the print task very closely following this tutorial. However, it is very slow (~60 seconds to export an A3 pdf with default dpi) and I notice the following severe ArcGIS for Server logs:

Has anyone seen this type of vague log?

The python script used:


import arcpy
import os
import uuid

# The template location in the registered folder (as UNC path)
templatePath = '//ourserver/ourtemplatepath

# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)

# Format for output
Format = arcpy.GetParameterAsText(1)
if Format == '#' or not Format:
 Format = "PDF"

# Input Layout template
Layout_Template = arcpy.GetParameterAsText(2)
if Layout_Template == '#' or not Layout_Template:
 Layout_Template = "A3 Paysage"

# Extra parameter - georef_info
Georef_info = arcpy.GetParameterAsText(3)
if Georef_info == '#' or not Georef_info:
 Georef_info = "False"

# Convert Georef_info string to boolean
if Georef_info.lower() == 'false':
 Georef_info_bol = False
elif Georef_info.lower() == 'true':
 Georef_info_bol = True

# Get the requested map document
templateMxd = os.path.join(templatePath, Layout_Template + '.mxd')

# Convert the WebMap to a map document
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument

# Reference the data frame that contains the webmap
# Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap"
df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]

# ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap".
# Lets rename it to something more meaningful.
df.name = Layout_Template




# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.{}'.format(str(uuid.uuid1()), Format)
Output_File = os.path.join(arcpy.env.scratchFolder, output)




# Export the WebMap
if Format.lower() == 'pdf':
 arcpy.mapping.ExportToPDF(mxd, Output_File, georef_info=Georef_info_bol)
elif Format.lower() == 'png':
 arcpy.mapping.ExportToPNG(mxd, Output_File)




# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(4, Output_File)




# Clean up - delete the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)


The javascript used to export the maps:


require([
 "esri/layers/FeatureLayer",
 "esri/dijit/Print",
 "esri/tasks/PrintTemplate",
 "esri/tasks/PrintTask",
 "esri/tasks/PrintParameters",
 "esri/tasks/GeometryService",
 "esri/tasks/ProjectParameters",
 "esri/geometry/Point",
 "esri/SpatialReference",
 "esri/request",
 "esri/config",
 "dijit/registry",
 "dijit/form/ComboBox",
 "dijit/form/Button",
 "dijit/form/CheckBox",
 "dojox/form/BusyButton",
 "dojo/store/Memory",
 "dojo/_base/array",
 "dojo/dom",
 "dojo/on"
], function(
 FeatureLayer,
 Print, PrintTemplate,
 PrintTask, PrintParameters,
 GeometryService,
 ProjectParameters,
 Point, SpatialReference,
 esriRequest, esriConfig, registry,
 ComboBox, Button, CheckBox, BusyButton, Memory,
 arrayUtils, dom, on
) {
 
 //var printUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task";
 var printUrl = "http://ouragsserver/arcgis/rest/services/SPE_Tools/SPE_Print_Tool_Adv/GPServer/Script";
 
 esriConfig.defaults.io.proxyUrl = "http://ourwebserver/Java/proxy.jsp";
 esri.config.defaults.io.timeout = 300000; //60 seconds = 60000
 
 setScalesCombo();
 
 var scaleCheckBox = new CheckBox({
 checked: false,
 onChange: function (val) {
 //dom.byId('one').innerHTML = val ? 'checked' : 'unchecked';
 if (scaleCheckBox.checked) {
 //params.template.preserveScale = true;
 dijit.byId("scale_select").attr("disabled",false);
 console.log("checked");
 }
 else {
 //params.template.preserveScale = false;
 dijit.byId("scale_select").attr("disabled",true);
 console.log("unchecked");
 }
 }
 }, 'scale_check');
 
 
 var printButton = new BusyButton({
 busyLabel: "Impression...",
 label: "Imprimer",
 timeout: 50000,
 onClick: printMap
 }, "print_button_bis").startup();
 
 
 function printMap(){
 var printMap = new esri.tasks.PrintTask(printUrl);
 var params = new esri.tasks.PrintParameters();
 var template = new esri.tasks.PrintTemplate();
 document.getElementById("print_status").innerHTML = "Impression en cours...";
 document.getElementById("output_url").innerHTML = "";
 
 var layout = dojo.byId("printLayoutId");
 var index = layout.selectedIndex;
 var selectedValue_layout = layout.options[index].value;
 var format = dojo.byId("format");
 var index = format.selectedIndex;
 var selectedValue_format = format.options[index].value;
 
 
 var lat = window.myMap.extent.getCenter().getLatitude().toFixed(2);
 var long = window.myMap.extent.getCenter().getLongitude().toFixed(2);
 
 var latLong = "Latitude : " + lat + " - Longitude : " + long;
 
 var X;
 var Y;
 
 var rgpfSixSudSR = new SpatialReference ({
 wkid : 3297
 });
 
 var wgsGCSEightFourSR = new SpatialReference ({
 wkid : 4326
 });
 
 var geometryService = new GeometryService("http://ourserver/arcgis/rest/services/Utilities/Geometry/GeometryServer");
 var inputPoint = new Point(lat, long, wgsGCSEightFourSR);
 var prjParams = new ProjectParameters ();
 prjParams.geometries = [inputPoint];
 prjParams.outSR = rgpfSixSudSR;
 
 geometryService.project(prjParams, function (outputpoint) {
 console.log('Conversion completed');
 X = outputpoint[0].x;
 Y = outputpoint[0].y;
 //console.log('X : ' + X ' and Y : ' + Y);
 
 });
 
 var center = "X : " + X + " - Y : " + Y;
 
 //params.template.layoutOptions.customTextElements.centerLatLong = latLong;
 //params.template.layoutOptions.customTextElements.centerXY = center;
 
 console.log(latLong);
 console.log(center);
 
 
 params.map = window.myMap;
 
 if (scaleCheckBox.checked) {
 params.template = {
 layout: selectedValue_layout,
 format: selectedValue_format,
 preserveScale: true,
 layoutOptions: {
 customTextElements : [
 {
 centerLatLong: latLong
 }
 // {
 // centerXY: center
 // }
 ]
 // legendLayer: [legendLayer]
 }
 }
 console.log("checked");
 }
 else {
 params.template = {
 layout: selectedValue_layout,
 format: selectedValue_format,
 preserveScale: false,
 layoutOptions: {
 customTextElements : [
 {
 centerLatLong: latLong
 }
 // {
 // centerXY: center
 // }
 ]
 // legendLayer: [legendLayer]
 }
 }
 console.log("unchecked");
 }
 
 
 
 //window.myMap.on('extent-change', showExtent());
 
 
 
 printMap.execute(params, printResult);
 
 // dojo.connect(printMap,'onComplete',function(result){
 // window.open(result.url);
 // })
 
 
 function printResult(result){
 console.log(result.url);
 document.getElementById("print_status").innerHTML = "";
 document.getElementById("output_url").href = result.url;
 document.getElementById("output_url").innerHTML = "Impression";
 var printWindow = window.open(result.url);
 
 
 };
 };
 
 function setScalesCombo() {
 var scaleStore = new Memory({
 data: [
 {name:"100", id:"100"},
 {name:"200", id:"200"},
 {name:"500", id:"500"},
 {name:"1000", id:"1000"},
 ]
 });
 
 var scaleSelect = new ComboBox({
 id: "scale_select",
 style: {width: "150px"},
 name: "scale_select",
 placeHolder: "Choisir une échelle",
 store: scaleStore,
 disabled: true,
 onChange: function(value){
 //document.getElementById("value").innerHTML = value;
 mapScale = value;
 window.myMap.setScale(mapScale);
 }
 }, "scale_select");
 scaleSelect.startup();
 }
 
});

Added to html body like this:

<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Impressions'">

<select name="printLayout" id="printLayoutId">
 <option value="A3_paysage">A3 Paysage</option>
 <option value="A3_portrait">A3 Portrait</option>
 <option value="A4_paysage">A4 Paysage</option>
 <option value="A4_portrait">A4 Portrait</option>
 <!-- <option value="Letter ANSI A Landscape" selected>Letter ANSI A Landscape</option>
 <option value="Letter ANSI A Portrait">Letter ANSI A Portrait</option>
 <option value="Tabloid ANSI B Landscape">Tabloid ANSI B Landscape</option>
 <option value="Tabloid ANSI B Portrait">Tabloid ANSI B Portrait</option> -->
 </select>
 <br>
 <select id="format">
 <OPTION value="PDF">PDF</OPTION>
 <OPTION value="PNG">PNG</OPTION>
 </select>
 <br>
 <br>
 <!-- <input type="checkbox" id="check_scales" checked
 data-dojo-type="dijit/form/CheckBox"
 data-dojo-props="checked: true"> -->
 <div id="scale_check"></div>
 <label for="scale_check">Imprimer à l'échelle</label>

<div id="scale_select" class="comboClass"></div>

<button id="print_button_bis" type="button"></button>
 <p id="print_status"></p>
 <a id="output_url" href="#"></a>
 <!--<input type="button" id="print" value = "Print" onclick="printMap();"/>-->


 </div>
0 Kudos
3 Replies
MichaelVolz
Esteemed Contributor

Are you trying to print complex data (vector data with many vertices or imagery)?  If so, you might want to try testing on a simpler data set and see how long it takes to print that out in comparison?

0 Kudos
NhuMai
by
Deactivated User

It does seem to take less time when removing layers--understandable. However, the end user will need to print about as much as I'm testing, plus, I hadn't noticed this slowness when using the out of the box print widget on the same amount of layers. I think there's something wrong with the gp script, but I'm not sure where to start looking considering the vague error message.

0 Kudos
MichaelVolz
Esteemed Contributor

Maybe it has something to do with the setup of your proxy.  In my application that was started from an ESRI sample the proxy was:

esriConfig.defaults.io.proxyUrl = /proxy (Shorthand for ESRI's proxy)

which I changed to:

http://"MyServerName"/Proxy/proxy.ashx 

Your sample has a proxy:

"http://ourwebserver/Java/proxy.jsp";

Did you use that same proxy when the application was using the out of the box print widget?

0 Kudos