展会信息港展会大全

使用pdfbox实现pdf文本提取和合并功能示例
来源:互联网   发布日期:2016-01-26 10:52:14   浏览:4702次  

导读:这篇文章主要介绍了使用pdfbox实现pdf文本提取和合并功能示例,大家参考使用吧有时我们需要对PDF文件进行一些处理,提取文本、合并等。以前我们使用A-PDF Text Extractor免费工具,为什么不自己写一个呢?现在我们 ...

这篇文章主要介绍了使用pdfbox实现pdf文本提取和合并功能示例,大家参考使用吧

有时我们需要对PDF文件进行一些处理,提取文本、合并等。以前我们使用A-PDF Text Extractor免费工具,为什么不自己写一个呢?

现在我们可以使用PDFBox-0.7.3这个开源类库. 下载解包后引用:

代码如下:

PDFBox-0.7.3.dll

IKVM.GNU.Classpath.dll

新建一个项目,代码很简单:

代码如下:

public static string ParseToTxtStringUsingPDFBox(string filename){

PDDocument doc = PDDocument.load(filename);

PDFTextStripper stripper = new PDFTextStripper();

return stripper.getText(doc);

}

获得这个textString,再把它们写成磁盘文件就可以了, 像这样的方法:

代码如下:

public static void WriteToTextFile(string str,string txtpath)

{

if (string.IsNullOrEmpty(txtpath))

throw new ArgumentNullException("Output file path should not be Null");

using (var txtWriter = new StreamWriter(txtpath))

{

txtWriter.Write(str);

txtWriter.Close();

}

}

其它的功能您可以自行发挥了. 这个类库目前支持:

PDF to text extraction

Merge PDF Documents

PDF Document Encryption/Decryption

Lucene Search Engine Integration

Fill in form data FDF and XFDF

Create a PDF from a text file

Create images from PDF pages

Print a PDF

赞助本站

人工智能实验室

相关热词: pdf pdfbox

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港