此代码在没有额外样式的空白浏览器窗口中打开PDF。
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="'.basename($complete_path).'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
header('Content-Length: ' .filesize($complete_path));
$success = readfile($complete_path);但我想申请更多的信息和一些造型太。所以我尝试了这个代码:
echo '<!DOCTYPE html>';
echo '<head>';
echo '<meta charset="UTF-8">';
echo '<title>'.$file_name.'</title>';
echo '<link rel="stylesheet" type="text/css" href="css/docs.css" />';
echo '</head>';
echo '<body >';
echo'<div class="frame">';
$success = readfile($complete_path);
echo'</div>';
echo '</body>';显然这是失败的,这是一个快速的尝试。那么,如何将PDF文件嵌入样式的浏览器页面中呢?我不想把它下载到磁盘上。
发布于 2016-11-09 15:46:11
要嵌入,您可以使用<embed>显示PDF,而无需下载:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Embeded PDF</title>
</head>
<body>
<embed src="MY_PDF_FILE.PDF" type="application/pdf" height="25%" width="25%">
</body> ▲
</html>现在使用PHP方式:
<?php
$pdf = "MY_PDF_FILE.PDF"; ◄
echo <<<BLOCK
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Embeded PDF</title>
</head>
<body>
<embed src="$pdf" type="application/pdf" height="25%" width="25%">
</body> ▲
</html>
BLOCK;
?>https://stackoverflow.com/questions/40510744
复制相似问题