今天按項目要求找了一個android的PDF控件,各種操作效果都非常好,在這里和大家分享一下。
這是github的地址:https://github.com/barteksc/AndroidPdfViewer
用法很簡單:
1.在build.gradle里面添加依賴 compile 'com.github.barteksc:android-pdf-viewer:2.7.0'
2.然后就可以直接在layout里面使用了
<com.github.barteksc.pdfviewer.PDFView android:id="@+id/pdfView" android:layout_width="match_parent" android:layout_height="match_parent" />
3.在Activity里面引用資源,就可以打開pdf文件了,而且這個控件有超級多的方法,支持很多功能,需要的自己去看看就行
private PDFView pdfView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pdfView = (PDFView) findViewById(R.id.pdfView); pdfView.fromAsset("test.pdf").load();//打開在assets文件夾里面的資源 //pdfView.fromBytes().load();//本地打開 //pdfView.fromFile().load();//網絡下載打開,()放字節數組 }
另外提一下,assets文件夾是創建在main文件目錄下的,和java文件夾是平行的
