![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
1、有问题可以加Q群咨询,技术交流群,也可以探讨技术,另有微信群可以问群主拉入微信群
2、如果有报错,请复制example运行,然后对照相关文件,以及package.json,缺什么补什么
3、如果有某些字体显示不了,那可能是pdf.js缺少相关字库解析,可以尝试更改cMapUrl,建议去官方地址找版本
4、如果IOS下pdf显示不了,安卓却可以,可能是pdf精度过高导致,Safari浏览器canvas渲染绘制图片宽高不能超过16777216,超过会不显示
<link rel="stylesheet" href="css/pdfh5.css" />
<div id="demo"></div>
<script src="js/pdf.js" type="text/javascript" charset="utf-8"></script>
<script src="js/pdf.worker.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/pdfh5.js" type="text/javascript" charset="utf-8"></script>
var pdfh5 = new Pdfh5('#demo', {
pdfurl: "./default.pdf"
});
npm install pdfh5
<template>
<div id="app">
<div id="demo"></div>
</div>
</template>
<script>
import Pdfh5 from "pdfh5";
export default {
name: 'App',
data() {
return {
pdfh5: null
};
},
mounted() {
//实例化
this.pdfh5 = new Pdfh5("#demo", {
pdfurl: "../../static/test.pdf",
// cMapUrl:"https://unpkg.com/pdfjs-dist@3.8.162/cmaps/",
// responseType: "blob" // blob arraybuffer
});
//监听完成事件
this.pdfh5.on("complete", function (status, msg, time) {
console.log("状态:" + status + ",信息:" + msg + ",耗时:" + time + "毫秒,总页数:" + this.totalNum)
//禁止手势缩放
this.pdfh5.zoomEnable(false);
})
}
}
</script>
<style>
@import "pdfh5/css/pdfh5.css";
*{
padding: 0;
margin: 0;
}
html,body,#app {
width: 100%;
height: 100%;
}
</style>
import Pdfh5 from "pdfh5";
import "pdfh5/css/pdfh5.css";
var pdfh5 = new Pdfh5(selector, options);
参数名称 | 类型 | 取值 | 是否必须 | 作用 |
---|---|---|---|---|
selector | String | - | √ | pdfh5的容器选择器 |
options | Object | - | × | pdfh5的配置项参数 |
var pdfh5 = new Pdfh5('#demo', {
pdfurl: "./default.pdf"
});
参数名称 | 类型 | 取值 | 作用 |
---|---|---|---|
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 | 是否开启背景图模式 |
new Pdfh5('#demo', {
pdfurl: "git.pdf",
// responseType: "blob" // blob arraybuffer
});
new Pdfh5('#demo', {
data: blob, //blob arraybuffer
});
pdfh5.scrollEnable(true) //允许pdf滚动
pdfh5.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 |
pdfh5.on("ready", function () {
console.log("总页数:" + this.totalNum)
})
事件名 | 回调 | 作用 |
---|---|---|
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销毁 |
FAQs
JS plugin of preview PDF for mobile. web/h5/移动端PDF预览手势缩放插件
The npm package hy-pdfh5 receives a total of 3 weekly downloads. As such, hy-pdfh5 popularity was classified as not popular.
We found that hy-pdfh5 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.