4

I have created a geoprocessing service, which can print a webmap(JSON) to a PDF or PNG. The ArcGis for Server and ArcGis for Desktop are running on my workstation. The Website, which host my webmap are also on this workstation. This worked fine until I updated my workstation from windows 7 to windows 10.

This is the code, which I used to create the geoprocessing service.

# Esri start of added imports
import sys, os, arcpy
# Esri end of added imports

# Esri start of added variables
#g_ESRI_variable_1 = os.path.join(arcpy.env.packageWorkspace,u'v103\\WorldTopo_103Templatev2_288k_to_1k.mxd')

g_ESRI_variable_1 = r'\\BRUNI\registered_folder\_Printer\templates'

# Esri end of added variables

#Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
#Type "copyright", "credits" or "license()" for more information.
import arcpy
import os
import uuid

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

# The template location in the server data store
templatePath = g_ESRI_variable_1

Format = arcpy.GetParameterAsText(1)

author = arcpy.GetParameterAsText(3)

map_title = arcpy.GetParameterAsText(4)

templateMxd = os.path.join(templatePath, arcpy.GetParameterAsText(2) + '.mxd')

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

title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")[2]
title.text = map_title

title = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")[0]
title.text = "Autor: "  + author

mxd.save()

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

# Export the WebMap
if Format.lower() == "pdf":
    arcpy.mapping.ExportToPDF(mxd, Output_File)
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(5, Output_File)

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

The main part of the code is from an esri tutorial.

And this is my local hosted website.

<!DOCTYPE>
<html>
  <head>
    <title>Webmap Printing</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
    <script src="https://js.arcgis.com/3.16/"></script>
    <script type="text/javascript" language="Javascript">
    require(["esri/config"], function(esriConfig) {   esriConfig.defaults.io.corsDetection = false; }); 
      dojo.require("esri.map");
      dojo.require("esri.tasks.PrintTask");
      dojo.require("esri.layers.FeatureLayer");
      var printTask, params;
      require([
      "esri/layers/ArcGISDynamicMapServiceLayer",
      "esri/layers/ArcGISTiledMapServiceLayer",
      "esri/map",
      "dojo/parser",
      "dojo/domReady!",
      "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane",
      ], function(ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer, Map){
            var map = new esri.Map("map", {
                basemap: "streets",
                center: [8.85, 47.1925],
                zoom: 15
            });
            var lachen_av;
                lachen_av = new ArcGISDynamicMapServiceLayer("http://showcase.geocom.ch/arcgis/rest/services/GNSDemo/lachen_av/MapServer");
                map.addLayer(lachen_av);

            var lachen_wat;
                lachen_wat = new ArcGISDynamicMapServiceLayer("http://showcase.geocom.ch/arcgis/rest/services/GNSDemo/lachen_wat/MapServer");
                map.addLayer(lachen_wat);


        var printUrl = "http://localhost:6080/arcgis/rest/services/Printscript2/GPServer/Printscript";

        printTask = new esri.tasks.PrintTask(printUrl, {
          async : true
        });;

        params = new esri.tasks.PrintParameters();
        params.map = map;

    });

      function print() {

        var layout = dojo.byId("size");
        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 author = dojo.byId("autor");

        var map_title = dojo.byId("map_title");

        var width;
        var height;

        console.log(selectedValue_Layout);
        if(selectedValue_Layout == "A4_temp") {
            width = 210,
            height = 297
        } else if (selectedValue_Layout == "A3_temp") {
            width = 297,
            height = 420
        } else if (selectedValue_Layout == "A2_temp") {
            width = 420,
            height = 594
        } else if (selectedValue_Layout == "A1_temp") {
            width = 594,
            height = 841
        } else if (selectedValue_Layout == "A0_temp") {
            width = 841,
            height = 1189
        }
        console.log(width);
        console.log(height);
        params.template = {
          format : selectedValue_format,
            layout : selectedValue_Layout,
          // Abgeändert, da die Service Parameter falsch gesetzt wurden
          //format : selectedValue_Layout,
          //layout : selectedValue_format,
            exportOptions : {
                width : width,
                height : height,
                dpi : 96
            }
        }
        params.extraParameters = {
            author : author.value,
            map_title : map_title.value
        }

        printTask.execute(params, printComplete);
      }

      function printComplete(result) {
        window.open(result.url);
      }

    </script>
  </head>
  <body class="claro">
    <div id="map" style="width:1000px; height:600px; border:1px solid #000;"></div>
    <br>
    <select id="size">
        <OPTION value="A4_temp">A4</OPTION>
        <OPTION value="A3_temp">A3</OPTION>
        <OPTION value="A2_temp">A2</OPTION>
        <OPTION value="A1_temp">A1</OPTION>
        <OPTION value="A0_temp">A0</OPTION>
    </select>
    <br>
    <br>
    <select id="format">
        <OPTION value="pdf">PDF</OPTION>
        <option value="png">PNG</option>
    </select>
    <br>
    <br>
    <input type="text" id="autor" placeholder="Autor" />
    <br>
    <br>
    <input type="text" id="map_title" placeholder="Map Titel"/>
    <br>
    <br>
    <input type="button" id="print" value="Print" onclick="print();"/>
  </body>
</html>

Now if I try to print my webmap, this error message comes out:

enter image description here

In addition it creates an empty error report and the server log says:

Instance of the service 'Printscript2.GPServer' crashed. Please see if an error report was generated in 'C:\arcgisserver\logs\BRUNI.ESRI-DE.COM\errorreports'. To send an error report to Esri, compose an e-mail to ArcGISErrorReport@esri.com and attach the error report file. The containing process for 'Printscript2' job 'j7a8082331f5842f3b079133bb33e9901' has crashed.

With this logcode from the log, I dont get any helpful informations. The permissions to the ressources should be also okay.

Can anyone help ?

Update

If I run the script before I publish it as a GP, it works fine. But when I run the published GP from Arcmap, it fail too

Executed GP from Arcmap

closed as off-topic by PolyGeo Jun 28 '16 at 7:51

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.