PDF.js在页面的简单使用
程序员文章站
2022-05-14 22:13:24
...
安装和导入
npm install --save vue-pdf
导入模块
import pdf from "vue-pdf";
导入pdf组件
components: {
pdf,
},
HTML
<div #="pdf">
<div class="pdf-tab">
<div
class="btn-def btn-pre"
@click.stop="prePage">上一页</div>
<div
class="btn-def btn-next"
@click.stop="nextPage">下一页</div>
<div
class="btn-def"
@click.stop="clock">顺时针</div>
<div
class="btn-def"
@click.stop="counterClock">逆时针</div>
<div
class="btn-def"
@click.stop="pdfPrintAll">全部打印</div>
<div
class="btn-def"
@click.stop="pdfPrint">部分打印</div>
</div>
<div>{{pageNum}}/{{pageTotalNum}}</div>
<div>进度:{{loadedRatio}}</div>
<div>页面加载成功: {{curPageNum}}</div>
<pdf
ref="pdf"
:src="pdfUrl"
:page="pageNum"
:rotate="pageRotate"
@password="password"
@progress="loadedRatio = $event"
@page-loaded="pageLoaded($event)"
@num-pages="pageTotalNum=$event"
@error="pdfError($event)"
@link-clicked="page = $event">
</pdf>
</div>
data变量
pdfUrl:"xxx.pdf",//pdf地址
pageNum:1,
pageTotalNum:1,
pageRotate:0,
// 加载进度
loadedRatio:0,
curPageNum:0,
}
js
prePage(){
var p = this.pageNum
p = p>1?p-1:this.pageTotalNum
this.pageNum = p
},
nextPage(){
var p = this.pageNum
p = p<this.pageTotalNum?p+1:1
this.pageNum = p
},
clock(){
this.pageRotate += 90
},
counterClock(){
this.pageRotate -= 90
},
password(updatePassword, reason) {
updatePassword(prompt('password is "123456"'))
console.log('...reason...')
console.log(reason)
console.log('...reason...')
},
pageLoaded(e){
this.curPageNum = e
},
pdfError(error){
console.error(error)
},
pdfPrintAll(){
this.$refs.pdf.print()
},
pdfPrint(){
this.$refs.pdf.print(100,[1,2])
},
上一篇: 点击按钮 复制文本 使用clipboard.js复制页面内容到剪切板
下一篇: JSP页面的思考
推荐阅读
-
在iOS应用中使用UIWebView创建简单的网页浏览器界面
-
详解在vue-cli项目下简单使用mockjs模拟数据
-
在Windows上使用putty远程登录Linux服务器的简单教程
-
mongodb 在 linux 中的安装和简单使用
-
使用PDF.JS插件在HTML中预览PDF文件的方法
-
在Python的Flask框架下使用sqlalchemy库的简单教程
-
第三方库LibUSB在Android系统上的简单使用
-
在Python中使用Mako模版库的简单教程
-
在Android Studio中Parcelable插件的简单使用教程
-
在Python的Django框架中simple-todo工具的简单使用