【问题标题】:Typescript print PDF file does not displays the FileName while saving as PDFTypescript 打印 PDF 文件在另存为 PDF 时不显示文件名
【发布时间】:2019-11-30 10:16:12
【问题描述】:

在 Angular 应用程序后端文件响应是 Blob 类型。使用 IFrame 我可以打印文件,但是当我选择另存为 PDF 时。屏幕显示从 url 获取的随机名称。

点赞 - 1231-35677-345.pdf

但我希望名称默认显示为 Summary.pdf

我的代码 -

const newBlob = new Blob([blob], { type: type });
const fileURL = URL.createObjectURL(newBlob);

const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = fileURL;
iframe.name = fileName;
document.body.appendChild(iframe);
iframe.contentWindow.print();

【问题讨论】:

    标签: angular typescript pdf iframe printing


    【解决方案1】:

    您可以使用file-saver

    import { saveAs } from 'file-saver';

    const newBlob = new Blob([blob], { type: type });
    let fileName = "Summary";
    FileSaver.saveAs(newBlob , `${fileName}.pdf`);
    

    【讨论】:

      猜你喜欢
      • 2021-10-27
      • 2018-05-20
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多