最近有朋友问我能不能不通过FLASH的方式在线查看PDF文档,因为之前没有做过类似的东西,第一反应就是用下面这个方式来实现:
<?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(\'xxx.pdf\'); 后来在网上查了一下资料,发现还有很多种实现方式,其中用 pdf.js 来实现我觉得是最优方案。
下载地址: http://mozilla.github.io/pdf.js/
DEMO:http://mozilla.github.io/pdf.js/web/viewer.html
本文地址:https://www.stayed.cn/item/12
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我