0

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?

3 Answers 3

0

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

I tried

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

and it work

Thanks alot guys.

1 Comment

Pls mark the correct answer, rather than posting one yourself. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.