先要对pdf文件进行解析,然后显示出来

解析pdf文件需要pdfbox的jar包,下载地址为:http://pdfbox.apache.org/download.html

下面是解析pdf的代码:

package com.lingjoin.extractors;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.util.Date;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.pdfbox.util.PDFTextStripper;
import com.lingjoin.paser.LingJoinFile;

/**
* PDF解析器
*
* @author Ansj
*
*/
public class PDFExtractor extends AbstractExtractor {

private String getContent(LingJoinFile f) {
// TODO Auto-generated method stub
PDDocument doc = null ;
try {
doc = PDDocument.load(f);
PDFTextStripper stripper = new PDFTextStripper();
/**
* 设置文件的信息
*/
this.setLingJoinFileInfo(f, doc
.getDocumentInformation());
return stripper.getText(doc);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (doc != null) {
try {
doc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return "";
}

private BufferedReader getContentReader(LingJoinFile f) {
return new BufferedReader(new StringReader(this.getContent(f)));
}

/**
*
* 项目名称:FilePaser
* 类描述: 设置文件的信息
* 创建人:ANSJ
* 创建时间:2010-4-14 下午04:27:57
* 修改备注:
* @version
*/
private void setLingJoinFileInfo(LingJoinFile f, PDDocumentInformation info) {
if (info.getAuthor() != null) {
f.setlAuthor(info.getAuthor());
}
}

public void paserFileToReader(LingJoinFile f) throws Exception {
f.setlContentReader(this.getContentReader(f)) ;

}

public void paserFileToString(LingJoinFile f) throws Exception {
// TODO Auto-generated method stub
f.setlContent(this.getContent(f)) ;
}

public PDFExtractor(Integer typeFlag) {
// TODO Auto-generated constructor stub
this.typeFlag = typeFlag ;
}

private Integer typeFlag = null ;

public Integer getTypeFlag() {
// TODO Auto-generated method stub
return typeFlag;
}
}


上面是用pdfbox实现的,只是部分不全的代码,同时还有用动态库so文件,读取图片。

源码下载地址http://download.csdn.net/detail/dahuaishu2010_/5292196

更多相关文章

  1. xposed框架的检测和反制
  2. FFMpeg For Android之Ubuntu下编译
  3. Android(安卓)9.0 添加 SD 卡写权限
  4. Android(安卓)Neon
  5. 使用百度地图SDK 这是之前版本 现在的sdk v2-1-2使用方法完全改
  6. android 9.0系统重启的代码详解
  7. android studio proguard 混淆微信libammsdk.jar报错
  8. Android: 向最强看齐, 反编译 植物大战僵尸.apk
  9. Android(安卓)使用RecycleView制作头像堆叠效果

随机推荐

  1. Android DNS之getaddrinfo()的实现
  2. 从MediaStore获取制定文件夹下的视频信息
  3. Android(安卓)Tween动画之RotateAnimatio
  4. Android学习笔记——关于onConfiguration
  5. 5分钟完全理解android handler
  6. 开启andriod手机的adbd,进行无线adb调试
  7. android 软键盘的弹出问题总结
  8. android M 运行时权限申请流程
  9. android的Application使用
  10. Android CountDownTimer倒计时器的使用