Print is not working in WebAppBuilder

2940
16
03-29-2018 05:51 AM
mohannainar1
New Contributor III

1. It says "No Access-Control-Allow-Orgin" , my mapservice is not secured . I am using the web adaptor URL for print task . 

2. ArcGIS Server and application both are running same machine. 

3. I tried including this is code (esriConfig.request.corsEnabledServers.push("https://myserver");) in startup function of the widget , same error message I am getting. 

Below is code am using for printing 

_onBtnPrintClicked: function(){
var legendLayer = new LegendLayer();
legendLayer.layerId = "WidgetName";
legendLayer.subLayerIds = [0];
legendLayer.subLayerIds = [1];
var url = "https://servername/arcgis/rest/services/ExportWebMap5/GPServer/Export%20Web%20Map";
var printTask = new PrintTask(url);
var params = new PrintParameters();
var template = new PrintTemplate();
template.format = "PDF";
template.layout = "Layout";
template.layoutOptions = {//"legendLayers": [legendLayer], // empty array means no legend
"titleText": "Map Print",
"authorText": "xxxxxx",
"copyrightText": "yyyyy",
"scalebarUnit": "Kilometers",
"customTextElements": [{"titleID": "Map Reports"}, {"genderID": "All"}]
};
template.preserveScale = false;
debugger;
template.exportOptions = {
width:500,
height:600,
dpi:96
};
params.map = this.map;
params.template = template;
printTask.on("error",lang.hitch(this, this._printResultError));
printTask.execute(params, lang.hitch(this, this._printResult));
},

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus

Mohan,

   So do you have anything but the base map that is suppose to print in your web map?

0 Kudos
mohannainar1
New Contributor III

Basemap and dynamically created layer (output of some process) . I want to print both but only dynamically created layer is appearing in print , base map coming as blank. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mohan,

  What happens when you use the print widget and not your custom print code?

0 Kudos
mohannainar1
New Contributor III

Robert,

My basemap is cached service, and its working from the print widget but not from custom print code. Whereas if I keep my basemap other than cached service (i.e. non-cached service), I can see the base map from custom print code.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

esrimohan   As mentioned above, I am having general issues with my cached basemaps not printing (10.5.1 in my case....my 10.2.2 serevice print just fine).    I am working with tech support and have found a few things.  Just in case these help you at all.  FYI - we have several basemaps that we cache, and then turn off the layers in the mxd since the cache is what we want to use.  So, check these things...

- Make sure all the layers in the mxd for your cache map service turned on (checked).  

- Make sure all the datasources for your cached service still available

- if you have a mix of raster and vector data in the cached service, make sure they are all using the same spatial reference.

As mentioned, our 10.2.2 services work fine.  Some of our cached services no longer have access to the source, which is ok since we just need the cache.  We also have our services in the same SR as the raster layer, but had a few vector layers that projected on the fly.  Again, it didn't matter in 10.2.2 since it would print from the cache.

Now it seems that the print itself is trying to be dynamic. I'm hoping they will have a workaround to force the print from the cache.  I hope to know more in a few days.

This is all independent of the actual ArcGIS Print Service used (the out-of-the-box or custom, or the version), and independent of the API used.  That is, we tested using the REST endpoint to take any API like JavaScript out of the equation.  It also is independent of external vs internal-only, web-adaptor or not, etc.  It appears to be the way the services and their caches are dealing with printing.

II'm not sure if this is relevant to your situation, but wanted to pass this along.  Once I have a resolution, I will post on the thread link I mentioned above.

mohannainar1
New Contributor III

I cross verified the mxd file

1.All  layers are turned on.

2. Datasources are valid

3.We have only one type of data(Vector)

We will wait for your response.

0 Kudos
mohannainar1
New Contributor III

Hi Rebecca ,did you get any update ?

0 Kudos