使用pdfbox實現(xiàn)pdf文本提取和合并功能示例
有時我們需要對PDF文件進行一些處理,提取文本、合并等。以前我們使用A-PDF Text Extractor免費工具,為什么不自己寫一個呢?
現(xiàn)在我們可以使用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();
}
}
其它的功能您可以自行發(fā)揮了. 這個類庫目前支持:
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
相關文章
ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設置(九)
這篇文章主要為大家詳細介紹了ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
asp.net得到本機數(shù)據(jù)庫實例的兩種方法代碼
這篇文章介紹了asp.net得到本機數(shù)據(jù)庫實例的兩種方法代碼,有需要的朋友可以參考一下2013-07-07
Asp.net中Microsoft.Identity的IPasswordHasher加密的默認實現(xiàn)與運用
本文主要介紹了Microsoft.Identity的IPasswordHasher加密的默認實現(xiàn)與運用。具有很好的參考價值,下面跟著小編一起來看下吧2017-02-02
ASP.NET中使用開源組件NPOI快速導入導出Execl數(shù)據(jù)
這篇文章主要介紹了ASP.NET中使用開源組件NPOI快速導入導出Execl數(shù)據(jù),NPOI是一個很強大的Execl操作組件,需要的朋友可以參考下2014-09-09

