【问题标题】:Converting from blob to pdf从blob转换为pdf
【发布时间】:2019-06-04 14:38:08
【问题描述】:

我能够将我的 pdf 文件转换为 blob。但我想做的恰恰相反,将它从blob转换为pdf。

这是我将其从 pdf 转换为 blob 的代码。我只需要一些建议,我可以从 blob 返回到 pdf。

var xhr=new XMLHttpRequest();

xhr.open("GET","./template.pdf");
xhr.responseType="arraybuffer";

xhr.onload = function (e){
    var blob = new Blob([xhr.response]);
    var url = URL.createObjectURL(blob)

    console.log(url);

    var embed=document.getElementById("template");
    embed.src = url;
}

xhr.send();

结果将从控制台返回一个 blob=> blob:http://localhost:8081/d42939da-e318-4d88-b46f-8240efaa7b1c,一旦我将其粘贴到 url 上,它会显示一个巨大的 blob 文本

【问题讨论】:

标签: javascript html blob


【解决方案1】:

您可以在创建 blob 时设置内容类型以告知它是 pdf。

var blob = new Blob([xhr.response], { type: 'application/pdf' });

【讨论】:

    猜你喜欢
    • 2020-07-12
    • 2019-08-19
    • 2022-12-26
    • 1970-01-01
    • 2018-06-25
    • 2016-05-17
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    相关资源
    最近更新 更多