Select to view content in your preferred language

PrintTask(url, params?) - Cannot find documentation for tha params options?

4275
5
Jump to solution
05-11-2015 11:32 AM
SubuSwaminathan1
Deactivated User

Are there any sample using the PrintTask class? What does this class provide over the print widget/digit?

Can anyone explain better than what the docs do?

Thanks

Subu

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Subu,

  The Print widget/dijit uses the PrintTask behind the scenes. The print widget/dijit takes care of asking the print service for available printTemplates and some other stuff that you will have to define in your code if you choose to use PrintTask.

Here is a code snippet of how I use it most often:

        var printTask = new PrintTask('http://someserver/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task');
        var template = new PrintTemplate();
        template.exportOptions = {
          width: 740,
          height: (740/oWid) * oHgt,
          dpi: 96
        };
        this.imgHeight = (740/oWid) * oHgt;
        template.format = "jpg";
        template.layout = "MAP_ONLY";
        template.preserveScale = false;
        template.showAttribution = false;
        template.outScale = this.map.getScale();

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

        printResult: function(rsltURL){
          //now do something with the generated image using the returned URL
        }

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Subu,

   I use the PrintTask quite often. I have many custom widgets that do not need to provide a UI like the print widget/dijit does so I just use PrintTask to get an export of the map as a JPG to put into an img element.

0 Kudos
SubuSwaminathan1
Deactivated User

PrintTask | API Reference | ArcGIS API for JavaScript

The esri docs appear to indicate more 'granular control' - I am just wondering what that really means as I cannot find any samples that illustrate that point.

Robert - Are you saying that the PrintTask is the same as the print digit/widget without the UI button or drop-down list? Making sure I am understanding it right.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Subu,

  The Print widget/dijit uses the PrintTask behind the scenes. The print widget/dijit takes care of asking the print service for available printTemplates and some other stuff that you will have to define in your code if you choose to use PrintTask.

Here is a code snippet of how I use it most often:

        var printTask = new PrintTask('http://someserver/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task');
        var template = new PrintTemplate();
        template.exportOptions = {
          width: 740,
          height: (740/oWid) * oHgt,
          dpi: 96
        };
        this.imgHeight = (740/oWid) * oHgt;
        template.format = "jpg";
        template.layout = "MAP_ONLY";
        template.preserveScale = false;
        template.showAttribution = false;
        template.outScale = this.map.getScale();

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

        printResult: function(rsltURL){
          //now do something with the generated image using the returned URL
        }
0 Kudos
MichaelVolz
Esteemed Contributor

What kind of value is the outScale parameter looking for?  Would this be the scale in layout units or map units?

0 Kudos
SubuSwaminathan1
Deactivated User

Michael,

Not very clear documentation from esri on this. For what I was trying to do, I commented out this line from Robert's response -"template.preserveScale = false;" . So went with the default there and then my code worked as I wanted.

If you print the outScale (template.outScale) to your browser console, you will see that the value printed is a map scale - 100,000 from 1:100,000 etc.

But Setting the outScale parameter did not work from me - I was trying to set it to actual map scale and not layout or map units.

0 Kudos