在web项目中如何读取pdf格式的文件,并显示在页面上。
那就用这个组件
在HTML里放FLASH插件,FLASH插件就是http://flexpaper.devaldi.com/,
然后插件去读PDF里的数据
8) 你是要把PDf文件嵌套在浏览器中?
还是说只是读取pdf的内容···
显示用页面显示??
读取Pdf中的文本内容可以使用pdfbox-1.5.0.jar,
[code="java"]
如果你只是读取内容,那么的话,很多开源的jar
LS说的pdfbox
还有itext也很强大,精确的读取
public class ReaderForPDF {
/**
@param fileName
*/
public void readPDF(String fileName) {
File file = new File(fileName);
FileInputStream in = null;
try {
in = new FileInputStream(fileName);
//新建一个PDF解析器对象
PDFParser parser = new PDFParser(in);
//对PDF文件进行解析
parser.parse();
//获取解析后得到的PDF文档对象
PDDocument pdfdocument = parser.getPDDocument();
//新建一个PDF文本剥离器
PDFTextStripper stripper = new PDFTextStripper();
//从PDF文档对象中剥离文本
String result = stripper.getText(pdfdocument);
System.out.println("PDF文件" + file.getAbsolutePath() + "的文本内容如下:");
System.out.println(result);
} catch (Exception e) {
System.out.println("读取PDF文件"+ file.getAbsolutePath() + "生失败!" + e);
e.printStackTrace();
} finally {
if (in != null){
try {
in.close();
} catch (IOException e1) {
}
}
}
}
public static void main(String[] args) {
ReaderForPDF pdf = new ReaderForPDF();
String fileName = "src/tempPDF.pdf";
try {
pdf.readPDF(fileName);
} catch (Exception e) {
e.printStackTrace();
}
}
}
[/code]
用flash插件,可以用类似百度文库的那种
flexpaper or flashpaper
[url]http://www.cnblogs.com/sobne/articles/1822479.html[/url]