pdfh5在线预览pdf文件

前言

pc浏览器和ios的浏览器都可以直接在线显示pdf文件,但是android浏览器不能在线预览pdf文件,如何预览pdf文件?

Github: https://github.com/gjTool/pdfh5

Gitee: https://gitee.com/gjTool/pdfh5

使用pdfh5预览pdf

  1. 编写预览页面
html 复制代码
<html>
<head>
    <meta charset="UTF-8">
    <title>pdfh5预览</title>
    <link rel="stylesheet" href="pdfh5/css/pdfh5.css"/>
    <link rel="stylesheet" href="pdfh5/css/style.css"/>
    <style type="text/css">

    </style>
</head>
<body>
<div id="demo"></div>
</body>
<script src="pdfh5/js/pdf.js" type="text/javascript" charset="utf-8"></script>
<script src="pdfh5/js/pdf.worker.js" type="text/javascript" charset="utf-8"></script>
<script src="pdfh5/js/jquery-3.6.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="pdfh5/js/pdfh5.js" type="text/javascript" charset="utf-8"></script>
<script>
    var pdfh5 = new Pdfh5('#demo', {
        pdfurl: "./default.pdf" //可以是你的pdf链接地址/xxx/xxx.pdf
    });
</script>
</html>
  1. 下载需要用到的css和js文件
    https://github.com/gjTool/pdfh5

    请见Git仓库中寻找

  2. 访问网页测试

pdfh5 扩展API

https://gitee.com/gjTool/pdfh5#pdfh5js

遇到的问题

1. 显示页面高度很小,不正常显示

解决办法: 找到pdfh5.css, 屏蔽height属性

css 复制代码
.pdfjs .pdfViewer .pageContainer img {
    width: 100%;
    /*height: 100%;*/
    position: relative;
    z-index: 100;
	/* user-select:none; */
}
相关推荐
willow1 天前
html5基础整理
html
anOnion4 天前
构建无障碍组件之Radio group pattern
前端·html·交互设计
前端Hardy4 天前
HTML&CSS&JS:丝滑无卡顿的明暗主题切换
javascript·css·html
前端Hardy5 天前
HTML&CSS&JS:基于定位的实时天气卡片
javascript·css·html
前端Hardy5 天前
HTML&CSS:纯CSS实现随机转盘抽奖机——无JS,全靠现代CSS黑科技!
css·html
DeathGhost5 天前
分享URL地址到微信朋友圈没有缩略图?
前端·html
前端Hardy6 天前
HTML&CSS:高颜值产品卡片页面,支持主题切换
css·html
Never_Satisfied6 天前
在HTML & CSS中,nth-child、nth-of-type详解
前端·css·html
你怎么知道我是队长6 天前
前端学习---HTML---块元素和行内元素
前端·学习·html
holeer6 天前
【V1.0】Typora 中的 HTML 支持|软件文档自翻译
前端·编辑器·html·typora·web·markdown·文档