function advancedPrint(printScale) { require(["esri/SpatialReference", "esri/tasks/PrintTask", "esri/tasks/PrintTemplate", "esri/tasks/PrintParameters"], function (SpatialReference, PrintTask, PrintTemplate, PrintParameters) { var printURL = dataLink + "/Test/AdvancedPrint/GPServer/AdvancedPrint" var printTask = new PrintTask(printURL, { async: true }); var formatOpt = getFormat(); var printLayout = getLayout(); var sr = new SpatialReference(102748); var printParams = new PrintParameters(); printParams.map = map; printParams.outSpatialReference = sr; printParams.extraParameters = { mapExtent: map.extent, printToScale: printScale }; var printTemplate = new PrintTemplate(); printTemplate.format = formatOpt; printTemplate.layout = printLayout; // "Letter ANSI A Landscape"; printTemplate.preserveScale = false; printTemplate.layoutOptions = { titleText: dijit.byId("txtPrintTitle").value, authorText: dijit.byId("txtPrintAuthor").value, copyrightText: "Copyright 2014", scalebarUnit: "Miles" }; printParams.template = printTemplate; // Progress bar var i = 0; var progressBar = dijit.byId("progressBar"); var progressGo = setInterval(function () { progressBar.set("value", i++ % 100); }, 300); setTimeout(function () { clearInterval(progressGo); }, 10000); // Execute Print Task printTask.execute(printParams, printComplete); }); } function printComplete(result) { window.open(result.url); var progressBar = dijit.byId("progressBar"); progressBar.label = "Print Complete"; }
Solved! Go to Solution.
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 = '//gisvm1/resources/Layout_Templates/' # The input format for output outputFormat = arcpy.GetParameterAsText(1) if outputFormat == '#' or not outputFormat: outputFormat = "PDF" # The input layout template templateMxd = arcpy.GetParameterAsText(2) if templateMxd == '#' or not templateMxd: templateMxd = "Letter ANSI A Landscape" # Extra Parameters # Extent mapExtent = arcpy.GetParameterAsText(3) # Scale printToScale = arcpy.GetParameterAsText(4) # Convert the WebMap to a map document templateMxd = os.path.join(templatePath, templateMxd + '.mxd') 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] # Set data frame scale if printToScale and printToScale != '#': df.scale = printToScale # 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 = 'ap_{}'.format(str(uuid.uuid1())) Output_File = os.path.join(arcpy.env.scratchFolder, output) # Export the WebMap if outputFormat == "PDF": Output_File = Output_File + ".pdf" arcpy.mapping.ExportToPDF(mxd, Output_File) elif outputFormat == "JPG": Output_File = Output_File + ".jpg" arcpy.mapping.ExportToJPEG(mxd, Output_File) # Clean up - delete the map document reference filePath = mxd.filePath del mxd, result os.remove(filePath)