jquery 跳过预览 调用打印机打印文件流
时间: 2023-08-04 09:05:49 浏览: 139
你可以通过以下步骤使用 jQuery 将文件流打印出来:
1. 创建一个隐藏的 iframe 元素,将文件流作为其 src 属性值。
2. 当 iframe 加载完成后,使用 JavaScript 调用其 contentWindow.print() 方法进行打印。
以下是一个简单的示例代码:
```javascript
var fileStream = "your_file_stream";
var iframe = $("<iframe>")
.hide()
.attr("src", "data:application/pdf;base64," + fileStream)
.appendTo("body");
iframe.on("load", function() {
// 打印 iframe 内容
this.contentWindow.print();
// 移除 iframe 元素
$(this).remove();
});
```
请注意,这种方法只适用于可打印的文件类型,例如 PDF 文件。对于其他类型的文件,你需要使用适当的插件或工具来将其转换为可打印的格式。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)