在浏览器中导出为 pdf 或图像时阻止查看下载 window
Prevent viewing of the download window while exporting to pdf or image in browser
在将 HTML 页面导入 PDF 时,我正在下载 window 弹出窗口类似于下面给出的
但我不想让用户看到 pdf 已下载,但我仍然可以下载。
我尝试了以下代码,但我仍然在 Firefox 浏览器中得到 window:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<script>
window.stop();
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(document.body, function() {
pdf.save('web.pdf');
});
</script>
<p id="to-pdf">HTML content...</p>
</body>
</html>
我尝试使用 window.stop 但没有结果。请求你的帮助
我正确理解了你的问题,即你想在另一个浏览器选项卡中创建和显示 pdf:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<p id="to-pdf">HTML content...</p>
</body>
<script>
var pdf = new jsPDF('p', 'pt', 'a4');
var pdfFile;
pdf.addHTML(document.body, function() {
console.log(pdf);
var pdfBlob = pdf.output('blob');
var fileURL = URL.createObjectURL(pdfBlob);
window.open(fileURL);
});
</script>
</html>
或者您也可以通过单击按钮在其他选项卡中打开 pdf:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<p id="to-pdf">HTML content...</p>
<p id="openPDFButton">Open PDF</p>
</body>
<script>
var pdf = new jsPDF('p', 'pt', 'a4');
var pdfFile;
pdf.addHTML(document.body,function(){});
document.getElementById('openPDFButton').onclick = function(){
var pdfBlob = pdf.output('blob');
var fileURL = URL.createObjectURL(pdfBlob);
window.open(fileURL);
};
</script>
</html>
希望对您有所帮助!
在将 HTML 页面导入 PDF 时,我正在下载 window 弹出窗口类似于下面给出的
但我不想让用户看到 pdf 已下载,但我仍然可以下载。
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<script>
window.stop();
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(document.body, function() {
pdf.save('web.pdf');
});
</script>
<p id="to-pdf">HTML content...</p>
</body>
</html>
我尝试使用 window.stop 但没有结果。请求你的帮助
我正确理解了你的问题,即你想在另一个浏览器选项卡中创建和显示 pdf:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<p id="to-pdf">HTML content...</p>
</body>
<script>
var pdf = new jsPDF('p', 'pt', 'a4');
var pdfFile;
pdf.addHTML(document.body, function() {
console.log(pdf);
var pdfBlob = pdf.output('blob');
var fileURL = URL.createObjectURL(pdfBlob);
window.open(fileURL);
});
</script>
</html>
或者您也可以通过单击按钮在其他选项卡中打开 pdf:
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<body>
<p id="to-pdf">HTML content...</p>
<p id="openPDFButton">Open PDF</p>
</body>
<script>
var pdf = new jsPDF('p', 'pt', 'a4');
var pdfFile;
pdf.addHTML(document.body,function(){});
document.getElementById('openPDFButton').onclick = function(){
var pdfBlob = pdf.output('blob');
var fileURL = URL.createObjectURL(pdfBlob);
window.open(fileURL);
};
</script>
</html>
希望对您有所帮助!