Print/Write a map in a PDF document.

6071
11
12-20-2014 11:37 PM
El_BoukfaouiReda
New Contributor II

Dear All,

I am working on reports related to tables and statistics.

I am conducting a search through dropdownlist selections and queries which is working just fine:

var selectQuery = new esri.tasks.Query();

selectQuery.where = "NAME_ENGLISH LIKE '" + evt.target.value + "'";

selectQuery.outFields = ["*"];

var upc_fi_selectQuery = new esri.tasks.Query();

upc_fi_selectQuery.spatialRelationship = selectQuery.SPATIAL_REL_CONTAINS;

AttFeatureLayer.selectFeatures(upc_fi_selectQuery, esri.layers.FeatureLayer.SELECTION_NEW, function (features)

{

// do this and that

}

After that I am running a script to write tables in a Windows document as follows (for instance):

var newWin =  window.open("");

newWin.document.write ("<label style='font-family: Trebuchet MS; font-weight:bold; font-size: 18px; color: #C0504D;'>Tourism Ecosystems Zone Details</label>");

newWin.document.write(Rep_T_tbTCA.outerHTML); // writing a table in a pdf document.

newWin.document.write ('<br></br>');

  newWin.document.write("<label style='font-family: Trebuchet MS; font-weight:bold; font-size: 18px; color: #C0504D; page-break-after: always'>Location of the the feature</label>");

  newWin.document.write ('<br></br>');

Till now everything works just fine.

The map now is zoomed to the selected feature.

Now, I need to print the current extent of the map inside the pdf document:

HTML

<div id="map" class="map" align="justify"

  data-dojo-type="dijit/layout/ContentPane">

  </div>

Javascript

....

var mapd = document.createElement("div");

  mapd.id = "map_rep";

  mapd.appendChild(document.getElementById("map"));

  newWin.document.write(mapd);

....

I am getting the following as a response, which is not required result:

[object HTMLDivElement]

I have seen other possibilities involving geoprocessing printing task using ArcGIS Online maps which is not the case for me as I am using a map published as a map service and I have not interest in going through ArcGIS Online.

Please kindly advice !

Specs:

- ArcGIS Server 10.1 Enterprise.

- JS API 3.11

11 Replies
RobertScheitlin__GISP
MVP Emeritus

Tracy,

  Here is some code I use in a custom dialog element to get the map image and replace a static placeholder I have in my dialog with the map image once it is ready and once the image is returned I enable my print button on that dialog.

this.map.infoWindow.hide();
        var oWid = this.map.width;
        var oHgt = this.map.height;
        var printTask = new PrintTask('print service url');
        var template = new PrintTemplate();
        this.imgHeight = (740/oWid) * oHgt;
        template.exportOptions = {
          width: 1542,
          height: (1542/oWid) * oHgt,
          dpi: 200
        };
        template.format = "jpg";
        template.layout = "MAP_ONLY";
        template.preserveScale = false;
        template.showAttribution = false;

        var params = new PrintParameters();
        params.map = this.map;
        params.template = template;
        printTask.execute(params, lang.hitch(this, this.printResult));

printResult: function(rsltURL){
        var mapImg = domConstruct.toDom('<img src="'+rsltURL.url+'" border="0" style="width:740px;height:'+this.imgHeight+'px;"/>');
        domConstruct.place(mapImg, dom.byId('mapImgDiv'), 'replace');
        if(typeof has('android') === 'undefined'){
          domClass.replace(this.printBtnNode, 'myprint-btn', 'myprint-btn-loading');
          domAttr.set(this.printBtnNode, 'title', 'Print Tax Report...');
          this.own(on(this.printBtnNode, 'click', lang.hitch(this, this._printReport)));
        }
      },
TracySchloss
Frequent Contributor

That works for me.  I figured it was a matter of waiting until there was output before proceeding.

0 Kudos