AnsweredAssumed Answered

trouble with export webmap to pdf

Question asked by troger80 on Oct 7, 2014

Hey having trouble getting a geoprocessing tool to export to pdf from a webmap correctly. I followed the tutorial ArcGIS Help 10.1 to create the geoprocessing tool and publish it. I access the tool using the geoprocessing widget in the flex viewer. The tool allows me to select a location to save the pdf and creates the pdf file but it does not create a pdf of the webmap.  Instead it creates a pdf of the template mxd file I used. Not

sure why it isn't reading any of the information from the webmap? Any help would be awesome Thanks.


import arcpy

import os

import uuid



# Input WebMap json

Web_Map_as_JSON = arcpy.GetParameterAsText(0)



# The template location in the server data store

templateMxd = '//CML/Facilities Management Application/map_temp/Landscape2.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]



# Remove the service layer

# This will just leave the vector layers from the template

for lyr in arcpy.mapping.ListLayers(mxd, data_frame=df):

    if lyr.isServiceLayer:

        arcpy.mapping.RemoveLayer(df, lyr)


# 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

arcpy.mapping.ExportToPDF(mxd, Output_File)



# Set the output parameter to be the output file of the server job

arcpy.SetParameterAsText(1, Output_File)



# Clean up - delete the map document reference

filePath = mxd.filePath

del mxd, result