谷歌支持使用游览器直接打开pdf,但是url需要连接谷歌服务,国内无法连接,此方案不可行
网上使用比较多的库
源类库com.joanzapata.pdfview.PDFView
Github地址:https://github.com/JoanZapata/android-pdfview
网上教程很多,但是有一个问题,图片从模糊变清晰比较慢
不适合商用
推荐AndroidPdfViewer(github:https://github.com/barteksc/AndroidPdfViewer),它是基于Google的VuDroid类库来解码PDF文件,在APP内直接加载PDF文件
compile 'com.github.barteksc:android-pdf-viewer:1.4.0'
/** * 加载pdf的方法 */ private void loadPdf(File file, int page) { Uri uri = Uri.fromFile(file); pdfView.fromUri(uri) .defaultPage(page) .enableDoubletap(true) .onPageChange(this) .swipeVertical(false) .enableAnnotationRendering(true) .enableDoubletap(true) .showMinimap(true) .enableSwipe(true) .load(); }
<com.joanzapata.pdfview.PDFView android:id="@+id/pdfview" android:layout_width="match_parent" android:layout_height="match_parent" />