GeoEnrichment Service - Create Report

963
2
05-28-2014 12:33 PM
DonCaviness
New Contributor III
I am working with the Create Report functionality of the GeoEnrichment service and I have run into an issue I'm not sure how to solve.  I can make the request to create the report using the esri.request class.  I am successful in submitting and generating the a pdf report, however I'm not sure how to display the pdf.  The result is a report is encoded as a binary byte-stream.

The result of the CreateReport method is a binary byte-stream where the PDF or Excel report are returned directly. The calling application will have to handle the response and present and/or save the binary output.


Does anyone know or can point me in the right direction as to how I can display this pdf in a browser window. I have been unable to locate any documentation in any of the Esri help for the GeoEnrichment or JavaScript API.
0 Kudos
2 Replies
VenkataSrikanth_Dasari
Occasional Contributor

Identify the latest downloaded file from the downloads folder and then open in a browser by using

window.open method in Javascript..

Cheers,
Srikanth Dasari

0 Kudos
by Anonymous User
Not applicable

Alternatively, you can use the blob type with your esriRequest like this (it will download the file and the user can click to open in browser):

esriRequest({ 
    handleAs: 'blob',
    content: myArgs,
    url: 'https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver/geoenrichment/createrepo...'
}).then(function(response) {
    if (response instanceof Blob) {
        var blob = new Blob([response], { type: 'application/pdf' });
        if (navigator.msSaveBlob) { // IE 10+
            navigator.msSaveBlob(blob, 'myfile.pdf');
        } else {
            var link = document.createElement("a");
            var url = URL.createObjectURL(blob);
            link.setAttribute("href", url);
            if (link.download !== undefined) { // feature detection
                // Browsers that support HTML5 download attribute
                link.setAttribute("download", this.fileName);
            }
            link.style = "visibility:hidden";
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
});
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍