Gathering detailed insights and metrics for pdfh5
Gathering detailed insights and metrics for pdfh5
Gathering detailed insights and metrics for pdfh5
Gathering detailed insights and metrics for pdfh5
npm install pdfh5
Typescript
Module System
Node Version
NPM Version
76.3
Supply Chain
99
Quality
85.9
Maintenance
100
Vulnerability
99.6
License
JavaScript (64.1%)
CSS (21.73%)
HTML (10.79%)
Vue (3.23%)
TypeScript (0.14%)
Total Downloads
601,963
Last Day
39
Last Week
586
Last Month
3,234
Last Year
182,913
MIT License
1,041 Stars
363 Commits
246 Forks
15 Watchers
4 Branches
4 Contributors
Updated on Jul 04, 2025
Minified
Minified + Gzipped
Latest Version
2.0.5
Package Id
pdfh5@2.0.5
Unpacked Size
2.84 MB
Size
1.05 MB
File Count
16
NPM Version
10.8.2
Node Version
18.20.8
Published on
May 18, 2025
Cumulative downloads
Total Downloads
Last Day
34.5%
39
Compared to previous day
Last Week
-14%
586
Compared to previous week
Last Month
-35.7%
3,234
Compared to previous month
Last Year
8.6%
182,913
Compared to previous year
1、有问题可以加Q群咨询,技术交流群,也可以探讨技术,另有微信群可以问群主拉入微信群
2、如果有报错,请复制example运行,然后对照相关文件,以及package.json,缺什么补什么
3、如果有某些字体显示不了,那可能是pdf.js缺少相关字库解析,可以尝试更改cMapUrl,建议去官方地址找版本
4、如果IOS下pdf显示不了,安卓却可以,可能是pdf精度过高导致,Safari浏览器canvas渲染绘制图片宽高不能超过16777216,超过会不显示
1<div id="demo"></div>
1<script src="js/pdf.js" type="text/javascript" charset="utf-8"></script> 2<script src="js/pdf.worker.js" type="text/javascript" charset="utf-8"></script> 3<script src="js/pdfh5.js" type="text/javascript" charset="utf-8"></script>
1var pdfh5 = new Pdfh5(document.querySelector("#demo"), { 2 pdfurl: "./default.pdf" 3});
1npm install pdfh5
1<template> 2 <div id="app"> 3 <div id="demo"></div> 4 </div> 5</template> 6<script> 7 import Pdfh5 from "pdfh5"; 8 export default { 9 name: 'App', 10 data() { 11 return { 12 pdfh5: null 13 }; 14 }, 15 mounted() { 16 //实例化 17 this.pdfh5 = new Pdfh5(document.querySelector("#demo"), { 18 pdfurl: "../../static/test.pdf", 19 // cMapUrl:"https://unpkg.com/pdfjs-dist@3.8.162/cmaps/", 20 // responseType: "blob" // blob arraybuffer 21 }); 22 //监听完成事件 23 this.pdfh5.on("complete", function (status, msg, time) { 24 console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum) 25 //禁止手势缩放 26 this.pdfh5.zoomEnable(false); 27 }) 28 } 29 } 30</script> 31 32<style> 33 *{ 34 padding: 0; 35 margin: 0; 36 } 37 html,body,#app { 38 width: 100%; 39 height: 100%; 40 } 41</style>
1var pdfh5 = new Pdfh5(selector, options);
参数名称 | 类型 | 取值 | 是否必须 | 作用 |
---|---|---|---|---|
selector | HTMLElement | - | √ | pdfh5的容器,html DOM元素对象 |
options | Object | - | × | pdfh5的配置项参数 |
1var pdfh5 = new Pdfh5(document.querySelector("#demo"), { 2 pdfurl: "./default.pdf" 3});
参数名称 | 类型 | 取值 | 作用 |
---|---|---|---|
pdfurl | String | - | pdf地址 |
responseType | String | blob 、 arraybuffer 默认 blob | 请求pdf数据格式 |
URIenable | Boolean | true、false, 默认false | true开启地址栏file参数 |
data | Array(arraybuffer) | - | pdf文件流 ,与pdfurl二选一(二进制PDF数据。使用类型化数组(Uint8Array)可以提高内存使用率。如果PDF数据是BASE64编码的,请先使用atob()将其转换为二进制字符串。) |
renderType | String | "canvas"、"svg",默认"canvas" | pdf渲染模式 |
pageNum | Boolean | true、false, 默认true | 是否显示左上角页码 |
backTop | Boolean | true、false, 默认true | 是否显示右下角回到顶部按钮 |
maxZoom | Number | 最大倍数3 | 手势缩放最大倍数 |
scale | Number | 最大比例5,默认1.5 | pdf渲染的比例 |
scrollEnable | Boolean | true、false, 默认true | 是否允许pdf滚动 |
zoomEnable | Boolean | true、false, 默认true | 是否允许pdf手势缩放 |
cMapUrl | String | " | 解析pdf时,特殊情况下显示完整字体的cmaps文件夹路径,例如 cMapUrl:"https://unpkg.com/pdfjs-dist@2.0.943/cmaps/" |
limit | Number | 默认0 | 限制pdf加载最大页数 |
logo | Object | {src:"pdfh5.png",x:10,y:10,width:40,height:40}src水印图片路径(建议使用png透明图片),width水印宽度,height水印高度,以每页pdf左上角为0点,x、y为偏移值。 默认false | 给每页pdf添加水印logo(canvas模式下使用) |
goto | Number | 默认0 | 加载pdf跳转到第几页 |
textLayer | Boolean | true、false, 默认false | 是否开启textLayer,可以复制文本(canvas模式下使用)】 |
background | Object | {color:"#fff",image:"url('pdfh5.png')",repeat:"no-repeat",position:"left top",size:"40px 40px"},和css的background属性语法相同,默认false | 是否开启背景图模式 |
1、文件地址
1new Pdfh5(document.querySelector("#demo"), { 2 pdfurl: "git.pdf", 3 // responseType: "blob" // blob arraybuffer 4});
2、pdf文件流或者buffer已经得到,如何渲染
1 new Pdfh5(document.querySelector("#demo"), { 2 data: blob, //blob arraybuffer 3 });
1pdfh5.scrollEnable(true) //允许pdf滚动 2pdfh5.scrollEnable(false) //不允许pdf滚动
方法名 | 传参 | 传参取值 | 作用 |
---|---|---|---|
scrollEnable | Boolean | true、false, 默认true | 是否允许pdf滚动(需要在pdf加载完成后使用) |
zoomEnable | Boolean | true、false, 默认true | 是否允许pdf手势缩放(需要在pdf加载完成后使用) |
show | Function | 带一个回调函数 | pdfh5显示 |
hide | Function | 带一个回调函数 | pdfh5隐藏 |
reset | Function | 带一个回调函数 | pdfh5还原 |
destroy | Function | 带一个回调函数 | pdfh5销毁 |
on | (String, Function) | String:监听的事件名,Function:监听的事件回调 | on方法监听所有事件 |
goto | Number | Number:要跳转的pdf页数 | pdf跳转到第几页(pdf加载完成后使用) |
download | (String, Function) | String:下载pdf的名称,默认download.pdf,Function:下载完成后的回调 | 下载pdf |
updateFile | options | options.pdfurl:要更新的pdf地址,options.data:要更新的pdf文件流(blob 、 arraybuffer ) | 更新pdf |
1pdfh5.on("ready", function () { 2 console.log("总页数:" + this.totalNum) 3})
事件名 | 回调 | 作用 |
---|---|---|
init | Function | 监听pdfh5开始初始化 |
ready | Function | 监听pdf准备开始渲染,此时可以拿到pdf总页数 |
error | Function(msg,time) | 监听加载失败,msg信息,time耗时 |
success | Function(msg,time) | 监听pdf渲染成功,msg信息,time耗时 |
complete | Function(status, msg, time) | 监听pdf加载完成事件,加载失败、渲染成功都会触发。status有两种状态success和error |
render | Function(currentNum, time, currentPageDom) | 监听pdf渲染过程,currentPageDom当前加载的pdf的dom,currentNum当前加载的pdf页数, |
zoom | Function(scale) | 监听pdf缩放,scale缩放比例 |
scroll | Function(scrollTop,currentNum) | 监听pdf滚动,scrollTop滚动条高度,currentNum当前页码 |
backTop | Function | 监听回到顶部按钮的点击事件回调 |
zoomEnable | Function(flag) | 监听允许缩放,flag:true,false |
scrollEnable | Function(flag) | 监听允许滚动,flag:true,false |
show | Function | 监听pdfh5显示 |
hide | Function | 监听pdfh5隐藏 |
reset | Function | 监听pdfh5还原 |
destroy | Function | 监听pdfh5销毁 |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
Found 2/18 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More