Java Spring boot Angular2,返回JSON格式的PDF

Java Spring boot Angular2,返回JSON格式的PDF,java,spring,angular,spring-boot,filesaver.js,Java,Spring,Angular,Spring Boot,Filesaver.js,我有一个SpringBootRESTAPI,它必须返回PDF。我已将PDF转换为字节数组,然后在将其返回到客户端之前将其编码为base64 以下是我的界面: @ApiOperation(value = "Update an existing form", notes = "Update an existing form ", response = Void.class, tags={ }) @ApiResponses(value = { @ApiResponse

我有一个SpringBootRESTAPI,它必须返回PDF。我已将PDF转换为字节数组,然后在将其返回到客户端之前将其编码为base64

以下是我的界面:

@ApiOperation(value = "Update an existing form", notes = "Update an existing form ", response = Void.class, tags={  })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "form response", response = Void.class),
            @ApiResponse(code = 200, message = "unexpected error", response = Void.class) })
    @RequestMapping(value = "/forms/{formId}/submissions/{submissionId}/pdf",
            method = RequestMethod.GET)
    ResponseEntity<Resource> pdf(
            @ApiParam(value = "Id of the form that needs to be updated", required = true) @PathVariable("formId") Long formId,
            @ApiParam(value = "Id of the submission that needs to be updated", required = true) @PathVariable("submissionId") Long submissionId,
            @ApiParam(value = "token to be passed as a header", required = true) @RequestHeader(value = "token", required = true) String token
    );
我在有效负载中收到的PDF如下所示:

当我打开下载的PDF时,它只包含一个空页面,而真正的PDF包含文本。知道发生了什么吗?我觉得这是关于编码的



解决方案

我不得不在我的服务中更改我的GET请求。我已经将它添加到我的请求
responseType:ResponseContentType.Blob

return this.http.get(this.formsUrl + "/" + formId + "/submissions/" + submissionId + "/pdf", {headers: headers, responseType: ResponseContentType.Blob})
        .toPromise()
        .then(res => res)
        .catch(this.handleError);
return this.http.get(this.formsUrl + "/" + formId + "/submissions/" + submissionId + "/pdf", {headers: headers, responseType: ResponseContentType.Blob})
        .toPromise()
        .then(res => res)
        .catch(this.handleError);

解决方案

我不得不在我的服务中更改我的GET请求。我已经将它添加到我的请求
responseType:ResponseContentType.Blob

return this.http.get(this.formsUrl + "/" + formId + "/submissions/" + submissionId + "/pdf", {headers: headers, responseType: ResponseContentType.Blob})
        .toPromise()
        .then(res => res)
        .catch(this.handleError);
return this.http.get(this.formsUrl + "/" + formId + "/submissions/" + submissionId + "/pdf", {headers: headers, responseType: ResponseContentType.Blob})
        .toPromise()
        .then(res => res)
        .catch(this.handleError);