javascript - html页面javascript/jQuery的pdf预览
问题描述
我正在尝试通过单击按钮在 HTML 页面的 javascript 中的新页面上创建 pdf 预览。
我想要的是,通过单击页面上的此按钮,它将在浏览器上打开一个新选项卡,其中包含源页面的 pdf 预览,然后我将从那里下载 pdf。
此刻我已经使用了这段代码
function printopen() {
var w = window.open();
var html = $("#divtoprint").html();
$(w.document.body).html(html);
w.print();
}
这会打开一个新的空白页面和弹出窗口。我不想显示弹出窗口,但相应的下载按钮和页面应该包含 pdf 预览。
实现这一目标的正确方法是什么?
解决方案
这将在新选项卡中打开 pdf 预览,您也可以下载它。
在您的 window.open 中,将您的资源的路径作为参数https://developer.mozilla.org/en-US/docs/Web/API/Window/open
function printopen(){
var w = window.open("path_to_your_file");
var html = $("#divtoprint").html();
$(w.document.body).html(html);
w.print();
}
但请记住,不能保证用户可以决定选项卡是否会出现在新选项卡中。
推荐阅读
- javascript - 双 forEach 到双 for 循环
- python - 任何信息论都可以帮助我在不进行视觉检查的情况下对数据集进行聚类?
- android - 使用 AndroidX LiveData 和模拟视图模型进行仪器测试时遇到问题
- python - Python - 如何使用正则表达式查找多个单词并同时提取它们
- django - 不确定如何在 fstring 中格式化 url
- javascript - 多个站点的全局通用导航栏
- php - 有选择地格式化数组中的值
- javascript - 从函数中设置变量,里面可能有ajax-load?
- html - 您如何通过 html 将任何 tumblr 帖子的头像作为图像获取?
- node.js - 如何在sails.js 0.12 cors.js 文件中添加多个来源