Android Examples PDF
来源:互联网 发布:前端 知乎 编辑:程序博客网 时间:2024/05/21 06:24
How to Read PDF files in Android?
Read PDF Files from Sdcard in Android
First Create one Android Project in Eclipse after that download PDFViewer.jar file from Internet and then add into project's build path.
After Create one Activity in this Project, Name is Second.java
Second.java
public class Second extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
After that Add below code into your project's main activity and change extends Activity to ListActivity in your java file.
First.java
public class First extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
And Don't Forget to Add Second Activity in Android Manifest file.
First Create one Android Project in Eclipse after that download PDFViewer.jar file from Internet and then add into project's build path.
After Create one Activity in this Project, Name is Second.java
Second.java
public class Second extends PdfViewerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
public int getPreviousPageImageResource() {
return R.drawable.left_arrow;
}
public int getNextPageImageResource() {
return R.drawable.right_arrow;
}
public int getZoomInImageResource() {
return R.drawable.zoom_in;
}
public int getZoomOutImageResource() {
return R.drawable.zoom_out;
}
public int getPdfPasswordLayoutResource() {
return R.layout.pdf_file_password;
}
public int getPdfPageNumberResource() {
return R.layout.dialog_pagenumber;
}
public int getPdfPasswordEditField() {
return R.id.etPassword;
}
public int getPdfPasswordOkButton() {
return R.id.btOK;
}
public int getPdfPasswordExitButton() {
return R.id.btExit;
}
public int getPdfPageNumberEditField() {
return R.id.pagenum_edit;
}
}
After that Add below code into your project's main activity and change extends Activity to ListActivity in your java file.
First.java
public class First extends ListActivity {
String[] pdflist;
File[] imagelist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
File images = Environment.getExternalStorageDirectory();
imagelist = images.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return ((name.endsWith(".pdf")));
}
});
pdflist = new String[imagelist.length];
for (int i = 0; i < imagelist.length; i++) {
pdflist[i] = imagelist[i].getName();
}
this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pdflist));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String path = imagelist[(int) id].getAbsolutePath();
openPdfIntent(path);
}
private void openPdfIntent(String path) {
try {
final Intent intent = new Intent(First.this, Second.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
And Don't Forget to Add Second Activity in Android Manifest file.
Enjoy :--)
转子:http://androidcodeexamples.blogspot.jp/2013/03/how-to-read-pdf-files-in-android.html
0 0
- Android Examples PDF
- Android examples
- [Android]read file examples
- [android]JNI Examples for Android
- Android官方资料--Configuration Examples
- examples
- examples
- Android Dev Intro - Android ADB Command Examples
- android pdf
- android pdf
- bash Cookbook, 2nd Edition Solutions and Examples for bash Users pdf
- android游戏引擎andengine学习系列一:运行examples
- How to Build and Run Android NDK Examples?
- android pdf包
- 开源Android pdf 解析
- android 打开PDF
- android解析pdf文档
- Android中生成PDF
- 导航控制器之间交互式传递数组的讨论
- UIViewContentMode详解
- js 对象
- C++局部变量和全局变量
- linux 安装xmanager碰到的问题 及处理方法
- Android Examples PDF
- 初始化与赋值的区别
- 源代码教育最新开班时间
- CUDA简介
- iOS代码书写规范
- oc与js交互-----WKWebView
- Intent传递自定义类型
- turtlebot(hydro)学习笔记五:Joystick控制turtlebot运动
- ArrayList和LinkedList区别