手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >使用pdfbox实现pdf文本提取和合并功能示例
使用pdfbox实现pdf文本提取和合并功能示例
摘要:有时我们需要对PDF文件进行一些处理,提取文本、合并等。以前我们使用A-PDFTextExtractor免费工具,为什么不自己写一个呢?现在...

有时我们需要对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

【使用pdfbox实现pdf文本提取和合并功能示例】相关文章:

ASP.NET中使用Application对象实现简单在线人数统计功能

Asp.net使用Comet开发http长连接示例分享

用CSS实现图片倾斜 只支持IE

asp.net文件上传示例

应用Response.Write实现带有进度条的多文件上传

Net中实现无限分类的2个例子

asp.net使用npoi读取excel模板并导出下载详解

asp. net下使用foreach简化文本文件的访问。

DataGrid同时具有分页和排序功能及注意点

asp.net下用js实现鼠标移至小图,自动显示相应大图

精品推荐
分类导航