Select to view content in your preferred language

Configuring Custom Print Template in ArcGIS Pro for use through JSAPI?

7443
10
Jump to solution
08-13-2019 03:03 PM
Arne_Gelfert
Frequent Contributor

I have a need for a custom map layout when printing from JSAPI web map. But I haven't been successful in publishing a custom template in ArcGIS Pro that works when called using the Javascript API (JSAPI).

Using the Print widget with the regular PrintingTools, as shown in this ESRI sample, works fine:

var print = new Print({
      view: view,
      // specify your own print service
      printServiceUrl:"https://myserver.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task",
      container: document.createElement("div")
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The widget open the window on the left and gives me all the default layout printing options. I would like to create a custom layout.

Next, I've followed the instructions here and here, to create a *.pagx layout file in ArcGIS Pro  (would be MXD in ArcMap) and share (publish) through Portal. The instructions read: 

...To create and share the web tool with ArcGIS Enterprise, the folder containing your layout templates must be accessible to ArcGIS Server. If the folder is accessible to the server, you can register it with the server; otherwise, copy the folder's contents to the server from ArcGIS Pro when you share the web tool.

So in steps 5 and 9, ...

5. For the Layout Templates Folder parameter, click the browse button and browse to the folder where your layouts are stored.

...

9. Choose the same Layout Templates Folder that you specified when running the Export Web Maptool in step 5

...I've left the field blank, and then checked "Copy all data" (Step 12) to copy the template to the server during Sharing. There are no errors during the sharing process. I get this and then ...

...see the item in Portal. When I reference the REST URL for the new print service in JSAPI...

var print = new Print({
      view: view,
      // specify your own print service
      printServiceUrl:"https://myserver.com/arcgis/rest/services/Custom_GP_Services/New_Custom_print_test/GPServer/Export%20Web%20Map", 
      container: document.createElement("div")
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I get this jocular bit of messaging:

Anyone seen this before? There are no JS errors in the console. So I have little to go on.

Troubleshooting at the print service REST page, as shown here, creates PDF output but it's not based on my custom template.

Output:

0 Kudos
1 Solution

Accepted Solutions
TanuHoque
Esri Regular Contributor

I really thought the registering a folder with Server wasn't necessary of the template was to be stored in Portal.

Yes, your understanding is correct.

If a folder is not registered with the server, data from that folder gets copied to the server during publishing.

Downside to this approach is that every time you make any changes, you need to republish your service.

If you don't want to republish your service, when data gets updated, make sure you registered the folder.

note: as you already know that this concept is not unique to print service or geoprocessing service, it is true for map, feature and all other services.

having said that step# 5 & 9 are not about registering folder with the server, it is about telling both 'Export Web Map' and 'Get Layout Templates Info' tools where to look for those layout templates you created. If you don't provide that folder, it will look for them in the default location.

I'm only seeing the default template when the Print widget opens

  1. if you go to Export Web Map task inside your print service REST resources end point, does it list your layout templates in there?
  2. How about executing Get Layout Template Info task, does the returned result show correct list?
  3. Are you using portal Map Viewer or WAB print widget?
    1. if it portal map viewer, did you update URL for the Printing in Organization >> Settings >> Utility Services?
    2. for WAB print widget, did you update its source URL

View solution in original post

0 Kudos
10 Replies
TanuHoque
Esri Regular Contributor

So in steps 5 and 9, ...

...I've left the field blank, and then checked

when you leave them blank, it uses default layout templates. For your print service to use your own layout templates, you must have the folder, containing .pagx files, chosen in both step#5 and #9

Troubleshooting at the print service REST page, as shown here, creates PDF output but it's not based on my custom template.

you need to provide a layout template name in the "Layout Template" text box.

0 Kudos
Arne_Gelfert
Frequent Contributor

Re: 5 and 9, I thought the options were save in folder and share folder with server, or save in Portal (copy all data over). I was trying to do the latter, so there would be no folder name for fields 5 and 9. Or did I completely misunderstood the workflow here?

As for layout template, great! I'll try that. I just went with the sample I found on some troubleshooting page. Let's see if this helps. Stay tuned.

0 Kudos
TanuHoque
Esri Regular Contributor

step 5 & 9 are where you need to specify where your .pagx are stored.

if you don't want them copied (e.g. you want to republish after every time you modify any of those templates. note: when you add a new template you must republish), then that folder must be registered to the server

0 Kudos
Arne_Gelfert
Frequent Contributor

Okay, I really thought the registering a folder with Server wasn't necessary of the template was to be stored in Portal. That was my interpretation of the documentation referenced above. I've gone ahead and created/registered a server folder, and then identified that folder as the layout template folder during publishing. But all to no avail. I'm only seeing the default template when the Print widget opens. Is it something I need to configure differently when I instantiate the widget in my JS code? Will take another look at the API documentation.

0 Kudos
TanuHoque
Esri Regular Contributor

I really thought the registering a folder with Server wasn't necessary of the template was to be stored in Portal.

Yes, your understanding is correct.

If a folder is not registered with the server, data from that folder gets copied to the server during publishing.

Downside to this approach is that every time you make any changes, you need to republish your service.

If you don't want to republish your service, when data gets updated, make sure you registered the folder.

note: as you already know that this concept is not unique to print service or geoprocessing service, it is true for map, feature and all other services.

having said that step# 5 & 9 are not about registering folder with the server, it is about telling both 'Export Web Map' and 'Get Layout Templates Info' tools where to look for those layout templates you created. If you don't provide that folder, it will look for them in the default location.

I'm only seeing the default template when the Print widget opens

  1. if you go to Export Web Map task inside your print service REST resources end point, does it list your layout templates in there?
  2. How about executing Get Layout Template Info task, does the returned result show correct list?
  3. Are you using portal Map Viewer or WAB print widget?
    1. if it portal map viewer, did you update URL for the Printing in Organization >> Settings >> Utility Services?
    2. for WAB print widget, did you update its source URL
0 Kudos
Arne_Gelfert
Frequent Contributor

Tanu, thanks again! I think we're getting somewhere.. clearly the custom template is not being added.

1) No. Custom template is not an item in the choice list.

2) No. Results set does not include custom template.

3) I'm running simple JSAPI app outside or WAB or Portal

Must still be doing something wrong during publishing.

0 Kudos
Arne_Gelfert
Frequent Contributor

Okay, finally got it working. As Tanu suggested, you can't do this without specifying a Layout Templates folder. The more I think about that makes sense. You want the widget calling the print service to have a place to search for which templates are available. Having left the field blank, I was defaulting to the built-in ESRI templates.

What I was missing after setting up the folder was to uncheck the "Copy All Data". After unchecking and resharing, it all worked.

All in all, the process is not as convoluted as the documentation suggests. After doing it a few times, it almost starts making sense. The documentation could be better.

TanuHoque
Esri Regular Contributor

Arne Gelfert‌ good to know that it works now.

The documentation could be better.

We'd like to hear your suggestions on how to make the help better or at least which part you found hard to understand. And we will try to make it better. Thanks a lot

0 Kudos
MichaelVolz
Esteemed Contributor

In a print service created from ArcMap, I just need to add a template mxd to the registered folder and stop and start the service for a new template to show up.

In a print service created from Pro, do I really need to republish the service to see a new pagx template in the registered folder as opposed to just stopping and starting the custom print service?

0 Kudos