解壓縮下載的PDFBox,找到其中的Bin目錄,需要在項目中添加引用的dll文件有: IKVM.GNU.Classpath.dll PDFBox-0.7.3.dll FontBox-0.1.0-dev.dll IKVM.Runtime.dll 將以上4個文件引用到項目中,在文件中需要引入以下2個命名空間: using org.pdfbox.pdmodel; using org.pdfbox.util;
using org.pdfbox.pdmodel;
using org.pdfbox.util;
public void pdf2txt(FileInfo file,FileInfo txtfile)
{PDDocument doc = PDDocument.load(file.FullName);PDFTextStripper pdfStripper = new PDFTextStripper();string text = pdfStripper.getText(doc);StreamWriter swPdfChange = new StreamWriter(txtfile.FullName, false, Encoding.GetEncoding("gb2312"));swPdfChange.Write(text);swPdfChange.Close();
}
iTextSharp,其實很多時候都是用于生成PDF,但是他讀取PDF的能力也不差,使用如下:
?
1、下載iTextSharp
下載地址:http://sourceforge.net/projects/itextsharp/
2、引用動態(tài)鏈接庫
解壓縮下載的壓縮包里面的itextsharp-dll-core.zip,得到itextsharp.dll,在項目中添加引用itextsharp.dll即可 在文件中需要引入以下3個命名空間: using iTextSharp; using iTextSharp.text; using iTextSharp.text.pdf;