Home > Backend Development > PHP Tutorial > PHP实现在线阅读PDF文件的方法_PHP

PHP实现在线阅读PDF文件的方法_PHP

WBOY
Release: 2016-05-30 08:46:01
Original
996 people have browsed it

本文实例讲述了PHP实现在线阅读PDF文件的方法。分享给大家供大家参考。具体实现方法如下:

<&#63;php 
if(!function_exists('read_pdf')) { 
 function read_pdf($file) { 
  if(strtolower(substr(strrchr($file,'.'),1)) != 'pdf') { 
   echo '文件格式不对.'; 
   return; 
  } 
  if(!file_exists($file)) { 
   echo '文件不存在'; 
   return; 
  } 
  header('Content-type: application/pdf'); 
  header('filename='.$file); 
  readfile($file); 
 } 
} 
read_pdf('Python_study.pdf'); 
Copy after login

为了更好地用户体验,建议你前端采用 FlexPaper在线显示文档组件来显示你的文档,先用PDF2SWF工具将你的pdf转成flash文件,然后用 FlexPaper来显示转换后的swf文件,这样用户浏览速度会很快,就像百度文库那样!

  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script type="text/javascript" src="pdfobject.js"></script>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 

//第一种方式
// var myPDF = new PDFObject({ url: "1.pdf" }).embed(); 

//第二种方式
var variablename = new PDFObject({ url: "1.pdf" }).embed("pdfobj");

//第三种方式
// var myembedparams = {
// url: "1.pdf"
// };
// var myPDF = new PDFObject(myembedparams).embed();
}); 
</script>
</head>
<body>asdfadsfasdf
<div id="pdfobj"></div>
</body>
</html>

Copy after login

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template