在给定页面的新选项卡中打开dompdf [英] open dompdf in new tab taken data from given page

查看:156
本文介绍了在给定页面的新选项卡中打开dompdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道至少还有两个其他类似的问题,但他们不能帮助我。

I know that there are at least two other similar questions, but they do not help me.

我有textyma和tinymce,用户写他的文本。然后有一个按钮PDF,应该创建pdf并在新标签中打开它。 pdf的内容是tinymce中的内容。

I have textarea with tinymce where user writes his text. Then there is a button "PDF" that should create pdf and open it in new tab. The content of pdf is the content in tinymce.

当用户点击按钮时,表单被提交到index.php操作。然后index.php从$ _POST变量中收集信息并创建pdf。

When user click on button, the form is submitted to index.php action. Then index.php gathers information from $_POST variable and creates pdf.

我无法将其作为正常链接在新标签页中打开。
我尝试了不同的方式。

I cannot get it to open in new tab as a normal link. I tried it in different ways.

1)我可以在同一个选项卡打开PDF,但这不是我需要的。这行打开我的pdf在同一个标​​签:

1) I can open PDF in the same tab, but this is not what I need. This line opens my pdf on the same tab:

$dompdf->stream('document.pdf',array('Attachment'=>0));

2)我可以在新窗口中打开它,但是浏览器警告这是弹出。客户不想要它。另一个问题是pdf存储在服务器上。我不想要它(弹出警告更重要)。这是我的代码:

2) I can open it in new window, but then browser warns that this is pop-up. Client doesn't want it. Also another problem with this is that pdf is stored on server. I do not want it (pop-up warning is more important). Here is my code:

$output = $dompdf->output();
file_put_contents('document.pdf', $output); //save pdf on server

//opens generated pdf in new window, but this creates warning for popup
echo '<script type="text/javascript" language="javascript"> 
window.open("http://modeles-de-lettres.org/test/saved_pdf.pdf", "_blank"); 
</script>'; 

我读过这些:

1 )使用dompdf 在新标签页中打开PDF

1) Open PDF in a new tab using dompdf

这表明:在新标签页中打开,这取决于你如何生成PDF,但最简单的方法是提供一个带有目标属性的链接。我认为这意味着我有

This suggests: "As far as opening in a new tab. That depends on how you are generating the PDF. But the simplest way it to provide a link with a target attribute." I think this means that I have

<a href="my.pdf" target="blank" 

<a href="my.php" target="blank" 

但这不适用于

2)

2) generate the pdf on newtab in dompdf

这是我之前实现的东西(我做了

This is something that I have implemented before (I did it without sessions), but it creats warning about popups.

推荐答案

问题是你在做什么事情的顺序。您应该从用户事件(例如单击按钮)打开新窗口。如果页面加载事件上的脚本尝试打开一个窗口,浏览器会假定它是一个不需要的弹出窗口,因为用户除了导航到页面之外没有做任何其他操作。

The problem is the order in which you're doing things. You should be opening the new window from a user event, like clicking a button. If a script on a page load event tries to open a window, the browser will presume it's an unwanted popup, since the user hasn't done anything besides navigating to the page.

可以为您工作的是为表单标签添加 target =somewhere_new属性。这样,浏览器将打开一个新的选项卡,因为没有框架/ iframe与 name =somewhere_new属性,你不必做任何特殊的服务器端,只是像使用 $ dompdf-> stream('document.pdf',array('Attachment'=> 0)); 在结尾

What could work for you, is adding a target="somewhere_new" attribute to your form tag. This way, the browser would open a new tab since there's no frame/iframe with a name="somewhere_new" attribute, and you wouldn't have to do anything special in the server side, just process the data as you did before using $dompdf->stream('document.pdf',array('Attachment'=>0)); at the end

这篇关于在给定页面的新选项卡中打开dompdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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