generate the pdf on newtab in dompdf

梦想与她 提交于 2019-12-24 20:58:07

问题


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:

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)


回答1:


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

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

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

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.

In your main page:

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

Your window opener becomes:

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

And in makemypdf.php

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


来源:https://stackoverflow.com/questions/17419535/generate-the-pdf-on-newtab-in-dompdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!