Use this php code to open a pdf in a new tab

You can't do that from that request.

But you can open the link in a new browser window by adding target="_blank" to your a tag, then browsers usually will use a new tab.


You can open a new tab while opening your pdf document. Example: if the code that opens your pdf document is on a page called pdfdocument.php, that is some code like so

    $pdf = file_get_contents($PDFfilename);
    header('Content-Type: application/pdf');
    header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header('Content-Length: '.strlen($pdf));
    header('Content-Disposition: inline; filename="'.basename($PDFfilename).'";');
    ob_clean(); 
    flush(); 
    echo $pdf;

and you have a link to the page such as http://www.example.com/pdfdocument.php, you can display it in a new tab like so <a href="http://www.example.com/pdfdocument.php" target="_blank"> click here to show pdf preview </a>

Tags:

Php

Pdf

Magento