javascript - JS PDF Blob 空白页
问题描述
我正在使用外部 Rest API 来获取包裹的 spedition 标签。作为回应,我有:
%PDF-1.4\n%����\n6 0 obj\n<</ColorSpace[/Indexed/DeviceRGB 255(\0\0\0 [...]
现在我需要在浏览器中显示 PDF
var xhr = new XMLHttpRequest();
xhr.open('POST', '/Order/CreateShipmentInpost', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.responseType = 'arraybuffer';
xhr.onload = function (e) {
if (this.status == 200) {
var blob = new Blob([this.response], { type: "application/pdf" });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = "Report.pdf";
link.click();
}
};
xhr.send($.param(data));
在生成的 PDF 文件中只有空白页。我不知道为什么内容没有显示。
我正在使用responseType = 'arraybuffer'
. 控制器返回:
return File(Encoding.UTF8.GetBytes(data, MediaTypeNames.Application.Pdf);
我也尝试返回 json 或字符串,但 PDF 始终为空。
解决方案
推荐阅读
- c++ - AST(抽象语法树)是由语言还是由前端定义的?
- arrays - 大家好,我如何在反应组件上渲染这些成分,而不必通过“strIngredient20”写出“strIngredient1”
- javascript - 如何在 vue 中将这些数据从 console.log(element.faculty_name) 显示到模板?
- javascript - Redux 工具包:未捕获的 TypeError:无法读取未定义的属性(读取“类型”)
- riscv - GCC 上的 RISC-V 程序集 - 为什么会生成冗余 mv 命令?
- python - 为什么 cv2.namedWindow 不起作用?
- javascript - 为什么当我使用`useState`时`setTimeout`调用不止一次?
- android - 具有委托 gpu 的 TFlite 给出错误的结果
- typescript - 从类型的默认参数推断 TypeScript 类型
- git - git diff --stat 输出中的 3 个前导点 (...) 代表什么