0

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.

2 Answers2

0

Did you look at:

AngularJS: Display blob (.pdf) in an angular app

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

I think this has been answered already.

Community
  • 1
  • 1
sauce
  • 592
  • 4
  • 9
  • 25
  • I have tried all those methods, but none of those works for me. I'm adding byte[] of the PDF to BO Object and sending the object to Web after changing to JSON. As you can see the response of my API is "application/json" – Unnikrishnan S Aug 25 '16 at 03:32
-1

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.

Angeldev
  • 164
  • 1
  • 4