Android PDF开发:android-pdfview

android-pdfview应用比较简单,要害的中央是PDFView,将PDFView作为像Android的ImageView或者TextView一样写进xml布局文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <com.joanzapata.pdfview.PDFView        android:id="@+id/pdfView"        android:layout_width="match_parent"        android:layout_height="match_parent" /></FrameLayout>

而后在Java下层代码间接加载pdf文件资源装载进去即可:

package zhangphil.pdfview;import com.joanzapata.pdfview.PDFView;import com.joanzapata.pdfview.listener.OnPageChangeListener;import android.app.Activity;import android.os.Bundle;import android.widget.Toast;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        PDFView pdfView = (PDFView) findViewById(R.id.pdfView);        // 在我这个测试例子中,当时筹备一个叫做sample.pdf的pdf大文件放到assets目录下。        // 从assets文件目录下读取名为 sample.pdf的文件,缺省把该pdf定位到第一页。        pdfView.fromAsset("sample.pdf").defaultPage(1).onPageChange(new OnPageChangeListener() {            @Override            public void onPageChanged(int page, int pageCount) {                // 当用户在翻页时候将回调。                Toast.makeText(getApplicationContext(), page + " / " + pageCount, Toast.LENGTH_SHORT).show();            }        }).load();    }}