0

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)

  • why not put a target="_blank" to the link that point to your pdf? – ikhsan Jul 02 '13 at 07:18
  • currently i doing with that way. but it needs server space to store the files. I just want to generate a pdf file through programing and display it to the browser (that is also working). No need to store the file. – John Varghese Jul 02 '13 at 07:21

1 Answers1

0

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
  • sorry i dont get you. How can open a session variable in windows url.Can you please give an example. I also added more content. Please see it... – John Varghese Jul 02 '13 at 08:00