简体   繁体   中英

ArcGIS API for JavaScript - PrintTask dosen't work

I have to use the ArcGIS API for JavaScript to show a PDF report, I'm using that API because the report is created from my ArcGIS server, this is my scenario.

JS Code:

function printReport(){
   var printTask = new PrintTask({
      url: ptReport,
      mode: "async"
   })
   var template = new PrintTemplate({
      format: "pdf",
      exportOptions: { 
        dpi: 96 
    },
    outputSize:[800, 1100],
    layout: "",
    layoutOptions: {
        titleText: "", 
        authorText: ""
      }
   });  
   var params = new PrintParameters({
      view: view,
      template: template,
      extraParameters: {
         "pPerdidaCablesConectores" : "1 dB",
         "pOtrasPerdidas" : "0 dB"           
       }
   });      
   printTask.execute(params).then(sendRequestPrint, showError);
}
function sendRequestPrint(data){        
   console.log(data.value); //it always is void
}

When I run the printReport method it work fine,in fact, the report is created in the server, I know it because I'm analysing the responses that come from the ArcGIS server:

enter image description here

All work fine at this point, however, when the sendRequestPrint method is runned, the response always come void.

What's happening, why whether the report is created it doesn't come in the response?

Please review the PrintTask complete function parameters. the returned type is DataFile .

https://developers.arcgis.com/javascript/3/jsapi/datafile-amd.html

The PrintTask internally parses the response from the server and returns a different object. You should simply be using like below

function sendRequestPrint(data){        
    console.log(data.url);
}

This behavior is by design. You should listen for the onComplete event, inspect the DataFile object and make another request to the returned url to get your pdf. This is something that you already do in your code.

See the PrintTask documentation for examples: https://developers.arcgis.com/javascript/3/jsapi/printtask-amd.html

In the image you posted the url for your document is at <>.value.url.

So your callback should be something like:

function sendRequestPrint(data){        
   var url = data.value.url;

   // make a request to get the pdf
   // do other stuff...

}

You may want to use the Print dijit to automate this process for you and not deal with the PrintTask directly: https://developers.arcgis.com/javascript/3/jsapi/print-amd.html

I tried

function sendRequestPrint(data){        
    console.log(data.url); 
}

and it work

Thanks alot guys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM