我正在使用 dropzone 将文件发送到 springboot api,该 api 处理这些文件并返回 pdf 响应,我想将其显示在我的角度前端上。一切正常,直到显示 pdf 为止,当它呈现一个空白 pdf(具有正确的页数)以及控制台中的警告时:
\n\nWarning: Indexing all PDF objects pdf.worker.min.js:1\nWarning: Invalid stream: "FormatError: Bad FCHECK in flate stream: 120, 239"\nRun Code Online (Sandbox Code Playgroud)\n\n我知道 pdf 本身没有损坏,因为当我向 API 发出 get 请求以检索同一 pdf 的存储版本时,它没有损坏并且呈现良好。
\n\n我尝试过使用 TextEncoder:
\n\nlet enc = new TextEncoder();\nthis.masterPdf = enc.encode(event[1])\nRun Code Online (Sandbox Code Playgroud)\n\n使用文件读取器:
\n\n var\xc2\xa0reader\xc2\xa0=\xc2\xa0new\xc2\xa0FileReader();\n\xc2\xa0\xc2\xa0reader.onload\xc2\xa0=\xc2\xa0function()\xc2\xa0{\n var\xc2\xa0arrayBuffer\xc2\xa0=\xc2\xa0this.result;\n self.masterPdf =\xc2\xa0new\xc2\xa0Uint8Array(arrayBuffer);\n console.log(self.masterPdf);\n self.masterShow = true;\n }\n var blob = new Blob([event[1]], {type:\'application/pdf\'});\n reader.readAsArrayBuffer(blob);\nRun Code Online (Sandbox Code Playgroud)\n\n并使用 StringToBytes:
\n\nlet strToByteArr = stringToBytes(event[1]);\nthis.masterPdf = new Uint8Array(strToByteArr);\n …Run Code Online (Sandbox Code Playgroud)