我想要一个自定义<;标题>;在PHP中使用header()


I want a custom < title > using header() in PHP

站在巨人的肩膀上,我成功地用header()拼凑了一个脚本,在我的内联网上发布pdf文档

我的显示代码:

<?php
require_once "includes/IniFile.php";
include_once "includes/process.php";
$MyData['ini'] = IniFile::getSettings();
foreach ( $_POST as $key => $value )
   { $fn = $key; }
$fn = str_replace("|sp|"," ",$fn);
$fn = str_replace("|dt|",".",$fn);
$ed = explode('!',$fn) ;
$MyData['ini']['pathMask'] = str_replace('|DEPT|', dptdir($ed[1], $MyData['ini'] ['departments']), $MyData['ini']['pathMask']);
$MyData['ini']['pathMask'] = str_replace('|FLDR|', subdir($ed[2], $MyData['ini'] ['folders']), $MyData['ini']['pathMask']);
$fn ='';
$file = $MyData['ini']['pathMask'].$ed[0];
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="'.$fn.'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
@readfile($file);
?>

所有操作都很好,但我希望包含.pdf的新页面具有<title>,它对应于正在发布的文档名称。

这可能吗?

谢谢——克里斯。

与其抛出标题,不如呈现一个普通页面并将PDF嵌入到iframe中。这样你就可以拥有你的标题,PDF仍然是在线的。

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My great title for the PDF</title>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: 0
}
</style>
</head>
<body>
  <iframe src="yourpdfname.pdf"></iframe>
</body>
</html>

如果您首先使用Zend/PDF库打开PDF,您可以修改PDF的内容,包括标题和其他元相关信息。

请参阅:http://php.net/manual/en/function.pdf-set-info.php