Android PDF开发:android-pdfview

Android平台自身没有直接可以阅读和处理pdf的方案,在github上面有一个第三方开源的pdf开发SDK,其主页地址是:

https://github.com/JoanZapata/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 {@Overrideprotected 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() {@Overridepublic void onPageChanged(int page, int pageCount) {// 当用户在翻页时候将回调。Toast.makeText(getApplicationContext(), page + " / " + pageCount, Toast.LENGTH_SHORT).show();}}).load();}}



我把该第三方开源库整理成Eclipse下可用的lib,上传到github上,地址链接:
https://github.com/zhangphil/android-pdfview-lib-for-eclipse
使用时候,下载该lib,导入到eclipse作为lib,然后在项目中直接引用即可。

更多相关文章

  1. Android(安卓)- Android(安卓)Studio 的 Preview窗口
  2. Android代码混淆常见配置
  3. Android(安卓)自定义dialog出入场动画
  4. Android下pm命令详解
  5. Android(安卓)SDK三种更新失败及其解决办法
  6. 使用Visual Studio 2015开发Android(安卓)程序
  7. Android: R cannot be resolved to a variable
  8. Android(安卓)Studio 连接夜神模拟器
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android中Bitmap, Drawable, Byte之间的
  2. Android(安卓)TextView(EditView)文字底部
  3. android shape和selector
  4. Android(安卓)Tool Chain Creater
  5. CoordinatorLayout+AppBarLayout 底部无
  6. Android(安卓)中 Movie 类显示GIF图片
  7. android获取热点主机ip和连接热点手机ip
  8. 安装后新建Android出现“AndroidManifest
  9. Android自定义控件中常见的方法
  10. Android应用开发相关下载资源