一、下载地址:http://sourceforge.net/projects/pdfbox/?source=dlp下载之后把lib中的PDFBox.jar引用到包中,单单引入这一个包是不够的,我们还需要引入external中的jar文件
二、编写源代码:
public class PdfParser {
/**
*
* @param path
* 文件路径
* @param ts
* pdf字符穿解析类,此处为构造参数防止在解析的时候频繁打开,关闭
* @return
* @throws IOException
*/
public static String getContent(String path, PDFTextStripper ts,StringWriter writer)
throws IOException {
//PDFTextStripper ts=new PDFTextStripper();
// StringWriter writer=new StringWriter();
FileInputStream fis = new FileInputStream(path);
PDDocument pdfDocument = PDDocument.load(fis);
ts.writeText(pdfDocument, writer);
String s = writer.getBuffer().toString();
pdfDocument.close();

本文介绍了如何使用PDFBox库解析PDF文档,包括下载PDFBox.jar和额外依赖的外部jar文件。在实际操作中,可能会遇到未关闭PDF文档的警告异常,通过正确使用stringWriter可以避免此类问题。
3万+

被折叠的 条评论
为什么被折叠?



