Android PDFView

1. AndroidPdfViewer

导入AndroidPdfViewer

implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

repositories里面添加库

maven { url 'https://jcenter.bintray.com' }

布局文件引用PDFView

<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdf_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

PdfViewer为我们提供了以下几种读取文件的方法:

pdfView.fromUri(Uri)
pdfView.fromFile(File)
pdfView.fromBytes(byte[])
pdfView.fromStream(InputStream)
pdfView.fromSource(DocumentSource)
pdfView.fromAsset(String)

Configurator主要方法

pages(int... pageNumbers) // 指定显示页面,默认全部显示
defaultPage(int defaultPage) // 默认实现页面

enableSwipe(boolean enableSwipe) // 控制屏幕滑动,默认为true能够滑动
enableDoubletap(boolean enableDoubletap) // 禁用双击,默认为true,可以双击
swipeHorizontal(boolean swipeHorizontal) // 开启横向滑动,默认竖向
enableAnnotationRendering(boolean annotationRendering) // 支持电子签
spacing(int spacing) // 页面之间空隙,单位是dp

onLoad(OnLoadCompleteListener onLoadCompleteListener) // 加载结束,开始绘制
onPageScroll(OnPageScrollListener onPageScrollListener) // 监听页面滚动
onPageChange(OnPageChangeListener onPageChangeListener) // 监听页面变化

load() // 最后调用,使配置生效

PDFView其他方法

jumpTo(int page, boolean withAnimation) // 跳转到指定页面
jumpTo(int page)
getPageCount() // 获取总页面数
getCurrentPage() // 获取当前页面

enableAntialiasing(boolean enableAntialiasing) // 改善渲染效果,默认是false
useBestQuality(boolean bestQuality) // 提高pdf清晰度,把图片格式从RGB_565提高到ARGB_8888,默认是false

canScrollVertically(int direction) // 是否可以纵向滚动,direction大于0,向下滚动,direction小于0,向上滚动
canScrollHorizontally(int direction) // 是否可以横向滚动,direction大于0,向右滚动,direction小于0,向左滚动

github地址: GitHub - barteksc/AndroidPdfViewer: Android view for displaying PDFs rendered with PdfiumAndroid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值