简体   繁体   中英

Rest API generated PDF byte[] JSON content-type to be viewed in Web using angularJS

I am returning a byte[] of PDF content as JSON response from REST API, and trying to render the data in angular JS.

here is my JS code snippet :

if(data.appStatusCode===0){                            
    var jsonObj = JSON.parse(data.payload);
    var reportData = jsonObj.data;                              
    var file = new Blob([reportData], {type: 'application/pdf'});
    var fileURL = URL.createObjectURL(file);
    window.open(fileURL);
 }

and the controller which returns byte[] as payload

@RequestMapping(value = "/janitramwebreport/{janitramid}",
            method = RequestMethod.GET, 
            produces = Constants.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseVO> getReportWebPdf(HttpEntity<?> httpEntity) {

    *//returns byte[] as the payload*
}

when I try to generate PDF in a new window, I get PDF file error message.

In the following link, you should find the answer :

AngularJS Display PDF (byte[]) received from Spring(@RestController) + jasper report

In this link you find how display pdf in a iframe using angularjs. The pdf is received from a API rest using spring and jasper report.

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