在React JS中使用字节数组生成PDF

时间:2019-04-03 07:47:50

标签: javascript reactjs react-native

我有一个API调用,它将返回json作为响应。json对象包含pdfBytes和xml作为字符串。如何将响应中的pdf字节作为blob并生成文档。

下面是我的代码段,以前我仅从我的API中得到一个响应,即仅pdf字节,它按预期工作,但现在使用json则不工作。

 var oReq = new XMLHttpRequest();

  var URLToPDF =
    "http://localhost:8080/downloadPDF";

  oReq.open("GET", URLToPDF, true);
  oReq.responseType = "blob";
  var that = this;
  oReq.onload = function() {
    console.log("Response received",oReq.response);
    const file = new Blob([oReq.response], { type: "application/pdf" });

    fileURL = URL.createObjectURL(file);
 window.open(fileURL, "_blank");
    that.setState({ loaderFlagInvoicePdf: false });
    that.setState({ invoicePDFDisplay: true });
  };

  oReq.send();

有人能建议我如何从json响应中删除blob吗?

0 个答案:

没有答案
相关问题