Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript pdf.js“回馈”;InvalidPDException:无效的Pdf结构“;_Javascript_Java_Angular_Pdfjs - Fatal编程技术网

Javascript pdf.js“回馈”;InvalidPDException:无效的Pdf结构“;

Javascript pdf.js“回馈”;InvalidPDException:无效的Pdf结构“;,javascript,java,angular,pdfjs,Javascript,Java,Angular,Pdfjs,我目前有一个后端java服务,可以使用itext将html转换为PDF。我将pdf作为字节[]返回给客户端(Angular 5)。但是,当我尝试在其上运行getDocument函数时,最终得到了“无效的pdf结构”。我不相信pdf结构实际上是无效的。我上传了我的html模板到一个在线pdf转换器,它工作得很好 这是我从后端得到的: 这是我的pdfjs代码: class MyDocumentsProvider{ downloadPdf():any{ return this.h

我目前有一个后端java服务,可以使用itext将html转换为PDF。我将pdf作为字节[]返回给客户端(Angular 5)。但是,当我尝试在其上运行getDocument函数时,最终得到了“无效的pdf结构”。我不相信pdf结构实际上是无效的。我上传了我的html模板到一个在线pdf转换器,它工作得很好

这是我从后端得到的:

这是我的pdfjs代码:

class MyDocumentsProvider{
      downloadPdf():any{
    return this.http.get(environment.webappServer+"/get1098E", {responseType:'arraybuffer'}).map(
      (res) =>{
          return res;
        }
      )
  }
}
this.myDocumentsProvider.downloadPdf().subscribe((res)=>{
        PDFJS.disableWorker = true; //<-- removing this does nothing

        PDFJS.getDocument(res).then((pdf)=>{
          this.showLoader = false;
            this.pdf = pdf;
            this.pagesTotal = pdf.numPages;
            pdf.getPage(this.pageNum).then((page) => {
                this.handlePages(page);
          this.writeFile();
            })
        }).catch((err)=>{
            this.showError = true;
        console.error(err);
        })
    },((err)=>{
      this.showError = true;
      console.error(err);
    }))
}
我已经用直接链接到pdf文件的方法测试了这段代码,它可以正常工作

这是一些java代码:

@RequestMapping(value="/testPdf",  headers="Accept=*/*", method = RequestMethod.GET)
    public ResponseEntity<?> testPdf() throws IOException{


        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.add("Content-Type","application/octet-stream;charset=UTF-8"); //<-- this was added later on.  Did nothing....
        ResponseEntity <byte[]> arr = pdfService.htmlTemplateToPdf()
        return new ResponseEntity<>(arr,responseHeaders, HttpStatus.OK);

    }
@RequestMapping(value=“/testPdf”,headers=“Accept=*/*”,method=RequestMethod.GET)
public ResponseEntity testPdf()引发IOException{
HttpHeaders responseHeaders=新的HttpHeaders();
添加(“内容类型”、“应用程序/八位字节流;字符集=UTF-8”);//而不是:

return this.http.get(environment.webappServer+"/get1098E", {responseType:'arraybuffer'}).map(
  (res) =>{
      return res;
    }
  )
我刚刚删除了响应类型:'arraybuffer'。 然后我获取响应并手动将其转换为类型化数组(Uint8Array)。
我猜响应类型:arraybuffer正在归还一些损坏的东西。

嗨。你能展示一下你是如何转换它的吗?非常感谢!
return this.http.get(environment.webappServer+"/get1098E", {responseType:'arraybuffer'}).map(
  (res) =>{
      return res;
    }
  )