HOW TO

Configure Portal for ArcGIS to print a custom layout from the map viewer

Last Published: April 26, 2020

Summary

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.

Procedure

This workflow uses a Python script to create a custom print service configured with Portal for ArcGIS. The sample script refers to a template MXD file for the custom layout that the map viewer uses for printing, and the script ensures that thumbnails are generated with a MAP_ONLY layout.

  1. In ArcMap, create an MXD with a layout view. This becomes the layout used when printing in the map viewer. The map viewer print output image size is 670 by 500 pixels.
  2. Save the following sample Python code as a .py file and edit the templateMxd path to refer to the location and name of the MXD created in Step 1.

    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)


  3. In the Catalog window, create a new toolbox. Right-click the toolbox and add the Python script.
  4. Set the script to have a required input string parameter named, 'Web_Map_as_JSON'.
    [O-Image] Toolbox_Parameter_1
  5. Additionally, set the script to have a derived output file parameter called 'Output_File'. Click Finish.
    [O-Image] Toolbox_Parameters_2
  6. Double-click the script to run it, adding a single blank space in the Web_Map_as_JSON input parameter.
    [O-Image] Single_Space
  7. Once the script has finished running, open the Geoprocessing Results window and right click to share the script output as a geoprocessing service. Use a connection that allows for the publication of services to the server.
    [O-Image] publish
  8. In the Service Editor, under Parameters, specify the Execution Mode as Synchronous. Describe the input parameter and publish the service.
  9. Once the service has been successfully published, navigate to the ArcGIS REST Services Directory and copy the geoprocessing service URL, including the script task.
  10. Logged in to the portal as a member with administrative privileges, select to edit the organization's settings. Under Utility Services, paste the geoprocessing service URL in the Printing dialog box and save the changes.
  11. Click the Print button in the map viewer. The custom layout is now displayed in the print preview page.

Article ID:000012389

Software:
  • Portal for ArcGIS
  • ArcGIS Server

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic