HTML5在线预览PDF的示例代码
程序员文章站
2023-11-23 21:24:04
本篇文章主要介绍了HTML5在线预览PDF的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
... 17-09-14...
简介
pdf.js is a portable document format (pdf) viewer that is built with html5.
pdf.js is community-driven and supported by mozilla labs. our goal is to create a general-purpose, web standards-based platform for parsing and rendering pdfs.
开源地址:
下载后不能直接使用,需要重新构建,不熟悉将会非常麻烦
构建好的程序包:
示例
引用文件,直接复制下文可以直接使用
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>课程详情</title> <style type="text/css"> </style> <script src="~/scripts/jquery-1.10.2.min.js"></script> <script src="~/scripts/plugins/pdfjs/pdf.js"></script> <script src="~/scripts/plugins/pdfjs/pdf.worker.js"></script> <script type="text/javascript"> var var_filepath = decodeuricomponent("@filepath");//不能跨域 var var_win_height = $(window).height(); $(document).ready(function () { resetplayersize(); }); $(window).resize(function () { resetplayersize(); }); function resetplayersize() { var_win_height = $(window).height(); $(".tmplayer").css({ "height": var_win_height + "px" }); } </script> </head> <body style="margin: 0;overflow: hidden"> <div id="tmplayer" class="tmplayer" style="height: 557px; width: 100%; height: 100%"></div> <script type="text/javascript"> $('.tmplayer').html('<iframe frameborder="0" scrolling="no" src="/scripts/plugins/pdfjs/generic/web/viewer.html?file=' + var_filepath + '" style="width:100%; height:100%;"></iframe>'); </script> </body> </html>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: HTML5添加禁止缩放功能