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; */
}
相关推荐
a11177621 小时前
小鸡下蛋 小游戏 html
前端·开源·html
DevOpenClub21 小时前
用网页快照、静态 HTML 和 PDF 转换接口构建网页归档 Agent
前端·人工智能·pdf·html
瓦学妹1 天前
2026年如何才能在不被屏蔽的情况下抓取网站?
前端·javascript·html
软件技术NINI2 天前
盗墓笔记html+css+js 2页
css·笔记·html
ShuiShenHuoLe2 天前
Go html/template 使用入门
开发语言·golang·html
午安~婉2 天前
挑战二:博客预览卡片
前端·javascript·html
IMPYLH3 天前
HTML 的 <dt> 元素
java·前端·html
IMPYLH3 天前
HTML 的 <em> 元素
java·前端·html
a1117763 天前
农业数字孪生大屏网页 html开源
前端·html
a1117764 天前
汽车3D配置器 THreeJS 开源项目
前端·3d·html·汽车