HTML5在线预览PDF的示例代码
作者:互联网
2025-08-15
简介
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.
开源地址:https://*git*h*ub.com/mozilla/pdf.js
下载后不能直接使用,需要重新构建,不熟悉将会非常麻烦
构建好的程序包:build.rar
示例
引用文件,直接复制下文可以直接使用
< !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 >
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。
注:相关教程知识阅读请移步到HTML教程频道。
相关标签:
HTML教程
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
WebSocket 连接池生产级实现:实时行情高可用与负载均衡
04/18
使用 Python 合并与拆分 Excel 单元格的实用方法
04/18
Pandas数据清洗完整指南:8大核心技巧详解
04/17
NumPy+Pandas数据分析基础完全指南
04/17
AI Agent 接入 Zvec (一):MCP 篇
04/17
python 更新Obsidian
04/17
用Manim实现动态交点计算--从一个动点问题说起
04/17
用 AI 解决数据库性能问题的方法论
04/17
前端害怕被蒸馏 快速入门Python 【demo_03】
04/17
Python 操作 Word 文档节与页面设置
04/16
AI精选
