Reputation: 112
Standing on the shoulders of giants, I have successfully cobbled a script using header() to publish pdf documents on my intranet,
My display code:
<?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);
?>
All works well, but I would like the new page containing the .pdf to have a < title > that corresponds to the document name being published.
Is this possible?
Thanks - Chris.
Upvotes: 5
Views: 6834
Reputation: 564
If you first open the PDF with the Zend/PDF library, you can modify the contents of the pdf, including title and other meta related information.
See: http://php.net/manual/en/function.pdf-set-info.php
Upvotes: 0
Reputation: 1556
Instead of throwing out the headers you should render a normal page and embed the PDF in an iframe. In that way you can have your title and the PDF is still inline.
<!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>
Upvotes: 2