Open PDF from FPDF in new tab Open PDF from FPDF in new tab codeigniter codeigniter

Open PDF from FPDF in new tab


You should create the new tab before running the FPDF code.

Alternative you can save the pdf as a file and open a new tab with the correct header.see this question: Show a PDF files in users browser via PHP/Perl

The code terminates with output by design, unless you save it to file or string.

$pdf->Output($filename,'F');

If you could elaborate on what you want to do after the output i might be able to help more.


Here is what we are doing and some thoughts:

  1. The Output() method takes 2 arguments, name and dest. You are sending an array in for the name parameter, probably not what you want. The second, dest, will use the "D" as you have specified.
  2. Output() sends headers and the data depending on the value you specify for dest. See below.

What that means is if you want to continue executing code, you are likely going to need to separate out the logic that generates this PDF into a new page, open that in the new tab using target="_new" like you were thinking, which then prompts the user to download or in that case you can use the "I" value and open it within the browser.

Output() from fpdf.php [lines 999-1036]:

switch($dest)    {        case 'I':            // Send to standard output            $this->_checkoutput();            if(PHP_SAPI!='cli')            {                // We send to a browser                header('Content-Type: application/pdf');                header('Content-Disposition: inline; filename="'.$name.'"');                header('Cache-Control: private, max-age=0, must-revalidate');                header('Pragma: public');            }            echo $this->buffer;            break;        case 'D':            // Download file            $this->_checkoutput();            header('Content-Type: application/x-download');            header('Content-Disposition: attachment; filename="'.$name.'"');            header('Cache-Control: private, max-age=0, must-revalidate');            header('Pragma: public');            echo $this->buffer;            break;        case 'F':            // Save to local file            $f = fopen($name,'wb');            if(!$f)                $this->Error('Unable to create output file: '.$name);            fwrite($f,$this->buffer,strlen($this->buffer));            fclose($f);            break;        case 'S':            // Return as a string            return $this->buffer;        default:            $this->Error('Incorrect output destination: '.$dest);    }