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; */
}
相关推荐
守正出琦1 天前
带代码示例的 HTML 标签实操手册
前端·html
yume_sibai1 天前
HTML HTML5基础(1)
前端·html·html5
XianZhe_1 天前
Pug 哈巴狗 便捷的HTML预处理器 上
前端·html·pug·html预处理器
yume_sibai1 天前
HTML HTML5基础(2)
前端·html·html5
守正出琦1 天前
HTML 常用标签速查表
前端·javascript·html
小时前端1 天前
虚拟DOM已死?90%内存节省的Vapor模式正在颠覆前端
前端·html
Keepreal4961 天前
Web Components简介及如何使用
前端·javascript·html
一只学java的小汉堡2 天前
HTML 01入门:从概念到开发环境搭建与页面头部配置
前端·css·html
今天没有盐2 天前
💕CSS 基础入门指南💕:选择器与文本样式
前端·html·响应式设计
九皇叔叔2 天前
HTML与CSS基础入门:从语法到页面结构全解析
css·html·1024程序员节