PDFview展示本地或网络PDF文件

1.依赖jar包

compile 'com.github.barteksc:android-pdf-viewer:1.4.0'
2.xml布局

          android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

            android:id="@+id/scrollBar"
        android:layout_width="1dp"
        android:background="#00000000"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
3.代码

先将pdf文件下载到本地,然后打开

pdfView.fromUri(uri)用法
//获取到文件在本地存储的路径
 
  
pdfName = Environment.getExternalStorageDirectory() +
        "/download";
//testPic1.pdf为文件下载后的命名
File file = new File(pdfName, "testPic1.pdf");
Uri uri = Uri.fromFile(file);
pdfView.fromUri(uri)
        .defaultPage(pageNumber)
        .enableDoubletap(true)
        .onDraw(this)
        .onPageChange(this)
        .enableAnnotationRendering(true)
        .onLoad(this)
        .enableDoubletap(true)
        .swipeVertical(true)
        .load();
//另外一个用法
pdfView. fromAsset(" testPic1.pdf ")
.defaultPage(1)
.onPageChange(MainActivity.this)
.swipeVertical(true)
.showMinimap(false)
.enableAnnotationRendering(true)
.onLoad(MainActivity.this)
.load();

记得添加权限
  1.   
  2.    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  
  3.      
  4.    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>  
  5.      
  6.    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />  

你可能感兴趣的:(android控件,android知识点)