您现在的位置是:网站首页> 编程资料编程资料
使用pdfbox实现pdf文本提取和合并功能示例_实用技巧_
2023-05-24
394人已围观
简介 使用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
相关内容
- mstest实现类似单元测试nunit中assert.throws功能_实用技巧_
- ASP.NET MVC3 实现全站重定向的简单方法_实用技巧_
- Jmail发送邮件与带附件乱码解决办法分享_实用技巧_
- .net后台代码调用前台JS的两种方式_实用技巧_
- .Net 文本框实现内容提示的实例代码(仿Google、Baidu)_实用技巧_
- 在aspx页面引用html页的写法_实用技巧_
- DataSet、DataTable、DataRow区别详解_实用技巧_
- asp.net中C#获取字符串中汉字的个数的具体实现方法_实用技巧_
- asp.net 备份和恢复数据库的方法示例_实用技巧_
- asp.net操作xml增删改示例分享_实用技巧_
