Open PDF in a new tab using dompdf

I have a same problem into my site (http://www.pdfwebcreator.com)

My solution is:

    $myfile = fopen($strFileName, "r") or die("Unable to open file!");
    $fileSize = filesize($strFileName);
    header("HTTP/1.1 200 OK");
    header("Pragma: public");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

    header("Cache-Control: private", false);

    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=\"temporaryPdf.pdf\""); 

    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $fileSize);

    echo fread($myfile, $fileSize);
}

Whether a PDF is downloaded or viewed in the browser depends on a couple of factors. One is your browser settings, but we have no control there. The second is how dompdf present the PDF to the browser. You can tell dompdf to offer the PDF for direct viewing using $dompdf->stream('my.pdf',array('Attachment'=>0));.

As far as opening in a new tab. That depends on how you are generating the PDF. But the simplest way it to provide a link with a target attribute.

Tags:

Dompdf