如何将HTML代码放入PHP代码中阅读PDF文件?

时间:2013-07-25 06:52:32

标签: php

我想在php代码中添加html标签,用于阅读PDF File.i想要添加链接页面底部和上面这个链接pdf文件是display.but我找不到这样做的方法。 我想做这样的事情。
enter image description here

表示我希望显示PDF文件的内嵌滚动条,然后链接其他pdf文件。

这里是我的代码:

<?php
$filename=base64_decode($_REQUEST['file2']);
$new_id=base64_decode($_REQUEST['id2']);
$line = "<html>";
$line .= "<head>";
$line .= "<title>PDF test</title>";
$line .= "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
$line .= "</head>";
$line .= "<body><div style='position:absolute; overflow:scroll;height:100px !important'>";
$file = WEB_ROOT."/admin/images/plastic_sandesh/pdffile/".$filename;
$length = filesize($file);
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file);
header("Content-Length: ".$length); 
@readfile($file);

$line .= "</div></body>";
$line .= "</html>";
?>

<iframe style='border:1px solid #FEFEFE; width:100px; height:100px;'>
<div style="position:absolute; overflow:scroll;height:100px !important">
<?php
$Qry2 =mysql_query( "select * from `tbl_plasticsandesh_pages` where `sandesh_id`='$new_id' order by `order`") or die(mysql_error());
$j=1;
 $cnt=mysql_num_rows($Qry2);
while($res2 = mysql_fetch_array($Qry2))
{
    $file_name2=base64_encode($res['pdf_page']);
    ?>
  <a href="readpdf.php?act=view&file=<?php echo $file_name2;?>$id2=<?php echo $_REQUEST['id2'];?>" style="color:#111"><?php echo $j;?></a><br />
<?php
$j++;
}
?>
 </div>
 </iframe>

但问题是显示的唯一pdf文件,没有其他PDF文件的链接。

提前致谢。

2 个答案:

答案 0 :(得分:2)

您正在设置标题,浏览器会将您的页面显示为application / pdf。这就是它没有显示链接的原因。

解决方案:将页面显示为html页面,并在iframe中显示pdf。

答案 1 :(得分:0)

通过使用它来解决:

<iframe name="iframe1" frameborder="0" src="<?php echo SITE_URL."/admin/images/plastic_sandesh/pdffile/".$filename;?>" height="100%" width="100%">
<html>
<body marginwidth="0" marginheight="0" style="background-color: rgb(38,38,38);">
<embed width="100%" height="" name="plugin" src="<?php echo SITE_URL."/admin/images/plastic_sandesh/pdffile/".$filename;?>" type="application/pdf">
</body>
</html>
</iframe>

然后是链接及其工作的另一个代码。