HOW TO
The instructions provided describe how to configure Portal for ArcGIS to print a custom layout from the map viewer. By default, the Print button in the map viewer prints output in a MAP_ONLY layout. After following the steps below, the map viewer Print button generates a PNG based on the custom layout authored in an MXD file. Thumbnails on item details pages still display as MAP_ONLY.
Maps with custom layouts can also be printed in Portal for ArcGIS by creating a web application that uses the print utility service. Web AppBuilder for ArcGIS and several configurable application templates at 10.3.1 (Basic Viewer, Classic Viewer, and Map Tools) contain print widgets that default to the portal’s print service. To print a custom layout with these applications, create a custom print service and configure the print service with the portal.
Code:
import arcpy
import os
import uuid
# Input WebMap json
Web_Map_as_JSON = arcpy.GetParameterAsText(0)
# Use the uuid module to generate a GUID as part of the output name
# This will ensure a unique output name
output = 'WebMap_{}.png'.format(str(uuid.uuid1()))
Output_File = os.path.join(arcpy.env.scratchFolder, output)
# Location of the layout template mxd
templateMxd = r'C:\PrintingScript\CaliforniaExtent.mxd'
if (Web_Map_as_JSON != " "): # This is just to let the script run successfully in Desktop before publishing the result
# Convert the WebMap to a map document
result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd)
mxd = result.mapDocument
# Reference the active data frame
df = mxd.activeDataFrame
# Export the data frame view (df) to create the thumbnail image. This is the equivalent of MAP_ONLY.
if (result.outputSizeHeight == 133 and result.outputSizeWidth == 200):
arcpy.mapping.ExportToPNG(mxd, Output_File, df, result.outputSizeWidth, result.outputSizeHeight, result.DPI)
else:
# Export the page layout to create the print layout image.
arcpy.mapping.ExportToPNG(mxd, Output_File);
# Clean up by deleting the map document reference
filePath = mxd.filePath
del mxd, result
os.remove(filePath)
# Set the output parameter to be the output file of the server job
arcpy.SetParameterAsText(1, Output_File)
Get help from ArcGIS experts
Download the Esri Support App