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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.