打印对话框关闭后,TCPDF 返回上一页 [英] TCPDF return to previous page after print dialog close
问题描述
我正在使用 TCPDF 为在线应用程序生成文档.我希望用户在打印后返回表单,因为用户将再次捕获数据.
我尝试在新标签/窗口中打开 pdf 并在打印后调用 window.close()
,但要使用 window.close()
,表单必须使用 window.open()
打开,情况并非如此.表单操作打开窗口.
然后我尝试在同一个选项卡中打开表单并调用 history.back()
,但也不起作用(通过不工作,我指的是页面保留在 pdf 上.>
我尝试过的代码(以及许多其他代码)
$js = <<<EOD窗口.打印();document.location.href = 'http://www.google.com';排爆;
和
$js = <<<EOD窗口.打印();window.history.back();排爆;
和
$js = <<<EOD窗口.打印();历史.go(-1);排爆;
和
$js = <<<EOD窗口.打印();window.addEventListener("afterprint", "window.history.back();");排爆;
此代码在不在 TCPDF 中时有效:
这必须在 TCPDF 中工作
有什么建议吗?
问题是如果直接加载PDF文件,那么那个页面没有运行JS,所以无法用JS关闭
我建议的最佳解决方案是使用 ViewerJS,这是一个用 JS 编写的 PDF 阅读器,因此您可以仍然在显示文档的同时运行代码.
I am using TCPDF to generate documents for an online application. I want the user to return to the form after print because the user will capture data again.
I have tried opening the pdf in a new tab / window and calling window.close()
after print, but to use window.close()
the form must open using window.open()
which is not the case. Form action opens the window.
I have then tried to open the form in the same tab and calling history.back()
, but also not working (by not working I refer to the page remains on the pdf.
Code I have tried (amongst many other)
$js = <<<EOD
window.print();
document.location.href = 'http://www.google.com';
EOD;
and
$js = <<<EOD
window.print();
window.history.back();
EOD;
and
$js = <<<EOD
window.print();
history.go(-1);
EOD;
and
$js = <<<EOD
window.print();
window.addEventListener("afterprint", "window.history.back();");
EOD;
This code works when not in TCPDF:
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
window.print();
window.onafterprint = function(){
window.history.go(-1);
}
});
</script>
This must work in TCPDF
Any suggestions?
The problem is that if you load a PDF file directly, then that page does not have JS running on it, so you can not close it with JS
The best solution I can suggest is to use ViewerJS, which a PDF reader written in JS, so you can still run code at the same time as displaying the document.
这篇关于打印对话框关闭后,TCPDF 返回上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!