在dompdf中的newtab上生成pdf [英] generate the pdf on newtab in dompdf

查看:82
本文介绍了在dompdf中的newtab上生成pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过dompdf将创建的pdf打开到新的浏览器选项卡?
我尝试了这些。
当我单击生成按钮(现在它是一个提交按钮)时,控制器操作
如下所示

Is there any way to open the created pdf by dompdf to new browser tab ? I tried these. When I click the generate button (now it is a submit button) the controllers action is given below

Controller:

Controller:

function generatePdf()
{
  require_once("dompdf/dompdf_config.inc.php");
  $data="this is a sample pdf";
  $dompdf = new DOMPDF();
  $html = $this->load->view('report/modelpdfview', $data, true);
  $dompdf->load_html($html);
  $dompdf->render();
  $dompdf->stream("mypdffile.pdf",array('Attachment'=>0));
  $this->load->view('view/mysiteView', $data);
}

但它在同一位置打开会导致用户失去对现场。 (我知道浏览器中有后退按钮)。

But it open on the same location which leads the user will lose control from the site. (I know there is back button in browser)

推荐答案

创建一个PHP脚本,该脚本创建要显示的PDF内容。如果合适,请使用一些命令行参数来控制创建的内容,也可以将内容存储在会话变量中。让我们称它为 makemypdf.php

Create a PHP script that creates the PDF content you want to display. If appropriate use some command line parameters to control what's created, or you can store your content in a session variable. Let's call it makemypdf.php

从Javascript中,打开一个弹出窗口,并将其作为URL:

From Javascript, open up a pop-up window with that as a url:

window.open(makemypdf.php, "mypdfwindow","...other window specs");

新窗口将包含您的PDF文件,而现有页面仍处于打开状态。

The new window will contain your PDF file, with your existing page still open.

您的问题对内容的要求不高,因此您必须自己填写一些技巧。

Your question is a bit light on content, so you'll have to fill in some of the mechanics yourself.

主页:

session_start();
$_SESSION['pdfcontent'][0] = "First PDF content";
$_SESSION['pdfcontent'][1] = "Second PDF content";

您的开窗器将变为:

window.open("makemypdf.php?pdfcontent=1", "mypdfwindow","...other window specs");

makemypdf.php

And in makemypdf.php

session_start();
$pdfcontent = $_SESSION['pdfcontent'][$_GET['pdfcontent'];
// render your PDF document here

这篇关于在dompdf中的newtab上生成pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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