android开发环境Android应用开发那些事

安卓开发应用内部打开pdf

2019-07-30  本文已影响181人  皓皓amous

https://github.com/pwlin/cordova-plugin-file-opener2

最近项目中有个需求,在App中需要打开pdf文件格式。由于Android平台是没有直接去阅读pdf的方案,只能去调用外部程序去打开pdf文件。这里只好去求助github的帮助,下面介绍一个有关于pdf开发的框架:AndroidPdfViewer。
github地址:(https://github.com/barteksc/AndroidPdfViewer)

用法:
1.在build.gradle里面添加依赖 compile 'com.github.barteksc:android-pdf-viewer:2.7.0-beta.1'
2.在layout中调用:
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp50" />
3.在Activity里面引用pdf,就可以打开pdf文件了,这个控件有很多的方法,支持很多功能。
PDFView pdfView;
String filePath = intent.getStringExtra(PDF_FILE_PATH);
if (null != filePath) {
File file = new File(filePath);
if (file.exists()) {
pdfView.fromFile(file) //设置pdf文件地址
.defaultPage(1) //设置默认显示第1页
.onPageChange(PdfActivity.this) //设置翻页监听
.onLoad(this) //设置加载监听
.onDraw(this)//绘图监听
.enableSwipe(true) //是否允许翻页,默认是允许翻页
.load();
}
}

效果图:支持pdf预览,滑动,放大缩小。

image image image

作者:Mr_Ashin
链接:https://www.jianshu.com/p/2d073ef89258
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

上一篇下一篇

猜你喜欢

热点阅读