Reputation: 504
I have codes here to view pdf file in browser but I can't find how to change the page title and the title bar. Is this possible to customize title?
$file = "additionalInfo_content/QXp6dk3ZB1.pdf";
$fp = fopen($file, "r") ;
$myFileName = 'test';
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$myFileName."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' . filesize($file));
ob_clean();
flush();
while (!feof($fp)) {
$buff = fread($fp, 1024);
print $buff;
}
exit;
The page title show's what the last string in my URL which is the QXp6dk3ZB1.pdf as well the title bar. I want to change it on what my desire title
Upvotes: 3
Views: 7447
Reputation: 31
You can control the window title that displays when loading a pdf through php by using your htaccess file Rewrite rules to hide the php processing file. Example using the htaccess RewriteRule ^uploads/([^/]+)/([^/]+)/([^/]+)(/)?$ /file.php?source=$1&file=$2&name=$3 [NC,L,QSA]
Upvotes: 1
Reputation: 6159
The title is normally changed using the HTML <title>
element. When viewing a file that is not HTML, it just displays the filename, or the internal PDF meta-title, if available.
You would have to alter the meta data of your file before sending it to the browser. Among other methods, there's this one: http://php.net/manual/en/function.pdf-set-info.php
Upvotes: 2