从Blob agnular打印pdf文件时出现问题 [英] Issue while printing pdf files from Blob agnular

查看:112
本文介绍了从Blob agnular打印pdf文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Api,该API以以下格式返回数据:

I have an Api that returns the data in the format of

{ fileName: string, blob: Blob }[]

我想打印所有这些文件,所以我正在使用

I want to print all these files, so I am using

_files.forEach((_fileInfo) => {
      const blobUrl = URL.createObjectURL(_fileInfo.blob);
      const oWindow = window.open(blobUrl, "print");
      oWindow.print();
      oWindow.close();
});

这会打开多个打印窗口,但在预览中会显示空白文档.

this opens the multiple print windows, but in preview it shows blank documents.

但是当我将所有这些文件下载为zip时,它将下载正确的PDF文件.

but when i download all these files as a zip it downloads the correct PDF files.

// add files to zip
files.forEach((_fileInfo) => {
    zip.file(_fileInfo.fileName, _fileInfo.blob);
});

// download and save
return zip.generateAsync({ type: "blob" }).then((content) => {
    if (content) {
        return saveAs(content, name);
    }
});

  1. 可能是问题所在

  1. What could be the issue,

是否可以在不打开多个窗口的情况下按顺序打印所有文档?

is there any way to print all documents in a sequence without opening multiple windows?

推荐答案

Pdf文件需要花费一些时间来加载,这就是为什么它显示空白文档的原因,所以我使用了 print-js 解决此问题.

Pdf file takes time to load thats why it was showing blank document, So i used print-js to solve this issue.

如何导入

import * as printJS from "print-js";

使用方法

const blobUrl = URL.createObjectURL(_fileInfo.blob);
printJS(blobUrl);

这篇关于从Blob agnular打印pdf文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆