ARCGIS API for JS calls ARCGIS Server custom layout printing service

1. Printing service

1.1 What is PrintingTools service

PrintingTools is a preconfigured service in the Utilities folder that uses one of the predefined map layouts to create printable documents. These layouts include basic designs using 8.5 by 11 inches, 11 by 17 inches, A3 and A4 paper sizes in portrait and landscape orientation. Each layout includes a north arrow, scale bar and scale, legend, date, and title. Output formats supported by the PrintingTools service include PDF, PNG32, PNG8, JPG, GIF, EPS, SVG, SVGZ, TIFF, and AIX.

By default, the PrintingTools service is stopped. If you want to support printing workflows, you must use ArcMap or ArcGIS Server Manager to start the service.

Once the PrintingTools service is started, you can access it using a URL of the form: https://webadaptorhost.domain.com/webadaptorname/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task.

ArcGIS Web API provides several widgets that communicate with the PrintingTools service to obtain printable maps. You provide the URL to the PrintingTools service, and the widget does the rest.

Note:
If the map service is cached, the PrintingTools service may use a resolution that is too low (for example, 96 DPI) for large format or high quality printing. To print at higher resolutions, it is recommended to enable dynamic layers on the cached map service. This allows the print service to obtain map images (via an Export Map request) at the desired resolution (for example, 300 DPI) rather than lower resolution tiles.

1.2 Custom print service

1.2.1 What is Custom Printing Service

In addition to the PrintingTools service included with ArcGIS Enterprise, it may sometimes be necessary to publish other services for web printing. For example, create a service and then configure it to point to your own folder of map layouts.

You should not update the layouts provided with the default PrintingTools service, nor should you add new layouts and republish this service.

To configure your own printing service, you need to publish the geoprocessing service through the Export Web Map tool.

If you want to use your own map layout, you can publish your own service similar to PrintingTools for printing web maps. This can be done in ArcMap 10.1 and later, or in ArcGIS Pro 2.1 and later. You can configure this service to reference your own folder prepared from various map layouts (map documents (.mxd) in ArcMap or layout files (.pagx) in ArcGIS Pro).

You can find instructions for publishing custom printing tools in two topics: Publishing other print services using ArcMap's custom layouts and Sharing a print service web tool with ArcGIS Pro's custom layouts. In an ArcGIS Pro workflow, share web tools to an ArcGIS Enterprise portal powered by a geoprocessing service published to a federated ArcGIS Server site.

These workflows also describe what to do later if you decide to update the layout. Your update method will vary depending on whether you register your layout folder with the server before publishing, this workflow explains both cases.

Note: A custom print service must be published as a synchronous geoprocessing service , and the print service URL must use HTTPS for it to be accepted by the portal as a portal print service.

1.2.2 Update layout template

If you are updating layouts in a layout template folder, you will need to determine the appropriate workflow depending on whether you have registered the layout template folder with the server before publishing (see the "Registering layout templates with ArcGIS Server" section above). It also matters whether you are adding a new layout to a folder or updating an existing one. This is because the geoprocessing task you create keeps the list of layouts in the layout templates folder at execution time.

If the layout template folder is registered to the server before publishing, it means that the server can access the layout. If you update an existing layout file (.pagx) in the folder, your modified layout will be available immediately. However, the server will not see any new layouts you add after publishing the service.

Therefore, you will need to perform a service override to make your changes available to ArcGIS Server users if any of the following conditions apply:

The layout template folder was not registered with the server before publishing the custom print service, which meant that the layouts were copied to the server when publishing.
After you publish your custom print service, you want to add new layout templates to this folder and make them available to users.

The Get Layout Template Info script tool allows adding the Get Layout Template Info task to a print service. This task provides the size of the layout page and the size of the map frame. It also shows whether the following layout elements are available:

  • legend
  • title text
  • copyright text
  • author text
  • custom text element

Legend
Whether you use PrintingTools or a custom print service, legends appear similar in your printouts. When printing a feature service, the legend in the printed document includes only feature legend entries within the map extent, whereas legends for other service types include all feature legend entries regardless of the map extent.

As of 10.7.1, the print service will automatically adjust the legend to only show patches for features that are visible within the current extent. This functionality is available for map services published from ArcGIS Pro to ArcGIS Enterprise 10.7.1 and does not require any additional configuration.

Learn more about working with legend entries in ArcGIS Pro

Unicode characters
The default layout templates in the PrintingTools service do not use fonts that support Unicode characters. So you might have problems with titles or legend entries, especially those with international characters. To resolve this issue, consider publishing a custom print service with your own layout templates, and then setting fonts that support Unicode characters.

When working with legend elements in ArcGIS Pro, you can set a font that supports Unicode characters for the default legend item.
ArcMap does not support changing the font of the default legend entries. Therefore, to change the style of all items in a legend element, an arcpy-based printing service needs to be written.

1.2.3 Overwrite and republish your custom print service

Follow the steps below to override the service and make your updates available:
insert image description here

The options you select override any options set during the first publish process. The layout templates folder (including updates) is copied to the server and replaces the layout templates folder that was placed there when the service was originally published.

2. How to publish custom print service

2.1 Register your layout template folder with ArcGIS Server

We can find the layout template that comes with arcgisserver, as shown below:
insert image description here

insert image description here

Then, when we publish our own printing service, this mxd contains the layout settings for our printing, and we register the prepared ArcMap documents (.mxd) on the server, and these documents contain Web map printing. Different layouts, this folder is the layout template folder.

If the layout template folder is currently located on the server, or is accessible through the server, you should use ArcGIS Desktop to register the folder with ArcGIS Server.

If you cannot put the layout templates folder on the server, or in a location accessible through the server, no action is required. When publishing the service, copy the layout templates folder to the server, making sure the server can access the folder. While this option is easy to configure, it requires more steps when updating layout templates in the future.
insert image description here

2.2 Prepare and publish the service

To publish a service, first run the Export Web Map tool, which contains the default values ​​required by your service. Next, run the Get Layout Template Information script tool. The results are then published as a geoprocessing service.

insert image description here

insert image description here

insert image description here

insert image description here

3. Use printing service

3.1 How to use the print service

There are several ways to generate printable documentation from web applications. ArcGIS Enterprise includes a geoprocessing service called PrintingTools. Web applications can call the PrintingTools service to obtain printable documents. You can also create custom print services using your own layouts other than the default PrintingTools services.

For advanced printing, a Python script can be used to convert a web map into an ArcMap document (.mxd) or ArcGIS Pro project (.aprx), and then export the map or layout within the project to various formats for printing.

Printing can be configured for ArcGIS Enterprise portals, web application templates, ArcGIS Web AppBuilder, and applications created using the ArcGIS web API.
For more information on configuring your portal (including all applications created with Web AppBuilder or a web application template) to print, see Configuring your portal to print maps in the Portal Administrator's Guide.

3.2 Use in portal

To use a custom print service through the ArcGIS Enterprise portal, copy this URL (including the Export Web Map task) and paste it in the Utilities Services dialog to print. Note that the portal only accepts URLs using HTTPS for its print utility service.
insert image description here
We can replace the print service that comes with arcgis with our own print service in the organizational utility of the portal. The following figure shows the print service that comes with the program;
insert image description here

3.3 arcgis api for javascripts

At this point, the new service can be referenced in the print widget provided by ArcGIS Web API. The URL for the print service can be found in your ArcGIS Services Directory.

This code uses the online mapserver, and the print service uses the encapsulated widgets plug-in:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
    <title>Print widget | Sample | ArcGIS API for JavaScript 4.19</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" />

    <style>
      html,
      body,
      #viewDiv {
    
    
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
        overflow: hidden;
      }
    </style>

    <script src="https://js.arcgis.com/4.19/"></script>
    <script>
      require(["esri/Map",
	  "esri/views/MapView",
	  "esri/widgets/Legend", 
	  "esri/widgets/Print", 
	  "esri/layers/MapImageLayer",
	  "esri/WebMap"], 
	  function(Map,MapView,Legend, Print,MapImageLayer, WebMap) 
	  {
    
    
		var map = new Map();
        var view = new MapView({
    
    
          container: "viewDiv",
          map: map
        });
		// Set the renderer on the layer
        var flayer = new MapImageLayer({
    
    
                url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer"
            });
		map.add(flayer);
		var legend = new Legend({
    
    
                view: view,
                layerInfos: [
                    {
    
    
                        layer: flayer
                    }
                ]
            });
        view.when(function() {
    
    
          var print = new Print({
    
    
            view: view,
            // specify your own print service
            printServiceUrl:
              "https://t460p.esrichina.com/server/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
          });

          // Add widget to the top right corner of the view
          view.ui.add(print, "top-right");
        });
      });
    </script>
  </head>

  <body class="calcite">
    <div id="viewDiv"></div>
  </body>
</html>

4 Considerations when preparing to use ArcMap Print Services with ArcGIS Enterprise

(1) When creating layouts in ArcMap for use with ArcGIS Enterprise portals, the following best practices are available:

  • Insert a title and leave the title text blank to fill this title text box with the name of your portal web map when printed. Unsaved web maps print with the title My Map.
  • Insert creator dynamic text to print the user's name.
  • Insert current date dynamic text to show the date the map was printed.
  • Insert current time dynamic text to show when the map was printed.

WARNING:
Do not insert username dynamic text in layouts. This dynamic text is populated with sensitive information about the print service.

(2) Summary of common files for print service error reporting:
1. First try to access the print service through http, such as mapserver that prints http;
http://t460p.esrichina.com/server/rest/services/Folder/testpoint/MapServer
If it can be printed normally, then try the printing service of https;

(3) Errors caused by self-signed certificates
Errors caused by Enterprise self-signed certificates mostly exist in the following scenarios:
1) No local printing service is set for Enterprise
2) The url of the service contained in the json construction string of the webmap to be printed It is https mode
3) The certificate here is a self-signed certificate
4) This certificate is inconsistent with the certificate of the ArcGIS for Server node where PrintingTools is located.
Regarding the unification of certificates, you can refer to the Internet:
Generate a certificate through OpenSSL and let the Chrome browser recognize it as the ultimate security method
https://blog.csdn.net/weixin_44616652/article/details/104834774

Note: After creating a new folder, if an error is reported and there is no permission when registering the server, then we also need to grant arcgis user permissions to the folder;
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_40625478/article/details/110793463