Skip to content

Commit

Permalink
增加limit
Browse files Browse the repository at this point in the history
  • Loading branch information
qq861366490 committed Nov 27, 2019
1 parent 89e7310 commit c3550d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pdfh5.js v1.2.21
# pdfh5.js v1.2.22

[![npm version](https://img.shields.io/npm/v/pdfh5.svg)](https://www.npmjs.com/package/pdfh5) [![npm downloads](https://img.shields.io/npm/dt/pdfh5.svg)](https://www.npmjs.com/package/pdfh5) [![MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/gjTool/pdfh5/blob/master/LICENSE) [![GitHub issues](https://img.shields.io/github/issues/gjTool/pdfh5.svg)](https://github.com/gjTool/pdfh5/issues) [![GitHub stars](https://img.shields.io/github/stars/gjTool/pdfh5.svg?style=social)](https://github.com/gjTool/pdfh5/stargazers) [![GitHub forks](https://img.shields.io/github/forks/gjTool/pdfh5.svg?style=social)](https://github.com/gjTool/pdfh5/network/members)

Expand All @@ -18,7 +18,7 @@

## 更新信息

- 2019.11.01 更新: 1. 修复svg模式下chrome等浏览器显示高度不正常
- 2019.11.27 更新: 1. 新增配置项属性limit,限制pdf加载最大页数


### pdfh5在线预览 (建议使用谷歌浏览器F12手机模式打开预览)
Expand Down Expand Up @@ -150,6 +150,7 @@ var pdfh5 = new Pdfh5('#demo', {
|scrollEnable| {Boolean}|true、false, 默认true|是否允许pdf滚动|
|zoomEnable| {Boolean}|true、false, 默认true|是否允许pdf手势缩放|
|cMapUrl| {String}| 默认"./js/cmaps/"|解析pdf时,特殊情况下显示完整字体的cmaps文件夹路径|
|limit| {Number}| 默认0 |限制pdf加载最大页数|

## pdf文件流请求示例(以jq ajax为例)

Expand Down Expand Up @@ -224,6 +225,7 @@ pdfh5.on("ready", function () {
- [JayLin](https://github.com/110117ab) ¥6.66
- [靓仔城](https://github.com/ljc7877376) ¥6.67
- 南蓝 ¥8.80
- 我是太阳 ¥29.99

## 扫码加入QQ群和更多小伙伴一起交流前端技术:
![QQ群:651601340](https://www.gjtool.cn/download/qq.png)
Expand Down
11 changes: 10 additions & 1 deletion js/pdfh5.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; (function (g, fn) {
var version = "1.2.21", pdfjsVersion = "2.1.266";
var version = "1.2.22", pdfjsVersion = "2.1.266";
console.log("The latest version and API of pdfh5 from: https://www.gjtool.cn (pdf.js: " + pdfjsVersion + " , pdfh5.js: " + version + ")")
if (typeof require !== 'undefined') {
if (g.$ === undefined) {
Expand Down Expand Up @@ -670,6 +670,12 @@
options.lazy = options.lazy === true ? true : false;
options.renderType = options.renderType === "canvas" ? "canvas" : "svg";
options.resize = options.resize === false ? false : true;
if(options.limit){
var n = parseFloat(options.limit)
options.limit = isNaN(n) ? 0 : n < 0 ? 0 : n;
}else{
options.limit = 0
}
if (options.renderType === "canvas") {
options.scale = 2;
}
Expand Down Expand Up @@ -958,6 +964,9 @@
self.loading.hide()
self.thePDF = pdf;
self.totalNum = pdf.numPages;
if(options.limit>0){
self.totalNum = options.limit
}
self.pageTotal.text(self.totalNum)
var arr1 = self.eventType["ready"];
if (arr1 && arr1 instanceof Array) {
Expand Down
9 changes: 5 additions & 4 deletions pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#demo {
display: none;
height: 50%;
}
</style>
</head>
Expand Down Expand Up @@ -66,13 +67,13 @@
<script src="js/pdfh5.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function () {
// $("#app").remove()
// $("#demo").show()
$("#app").remove()
$("#demo").show()
//当前默认优先获取浏览器地址栏?file=后面的地址,如果地址栏没有,再拿配置项的pdfurl或者data来渲染pdf
//优先顺序: ?file= > pdfurl > data
var pdfh5 = new Pdfh5('#demo', {
pdfurl: "https://yxq.linksign.cn/api/v1.0/file/downSignFile?fileCode=15729209200281073563943",
// pdfurl: "testPDF/1.pdf",
pdfurl: "git.pdf",
// limit:2, // 限制加载最大页数
renderType:"canvas",
// type:"ajax",
lazy: true
Expand Down

0 comments on commit c3550d6

Please sign in to comment.