注意 一定要引用這個(gè)兩個(gè)命名空間
using org.pdfbox.pdmodel;
using org.pdfbox.util;
//PDF 文件讀取
//FileInfo file = new FileInfo(Server.MapPath("file\\巔峰銷售心理學(xué).pdf"));
//FileInfo txtfile = new FileInfo(Server.MapPath("file\\index.txt"));//文件名不可相同
//pdf2txt(file,txtfile);
/// <summary>
/// PDF 文件讀取方法
/// </summary>
/// <param name="file"></param>
/// <param name="txtfile"></param>
public void pdf2txt(FileInfo file, FileInfo txtfile)
{
PDDocument doc = PDDocument.load(file.FullName);
PDFTextStripper pdfStripper = new PDFTextStripper();
String txt = pdfStripper.getText(doc);
StreamWriter swPdfChange = new StreamWriter(txtfile.FullName, false, Encoding.GetEncoding("gb2312"));
this.div1.InnerHtml += txt.Replace("\r", " ").Replace("\n", "<br>");
swPdfChange.Close();
}
更多信息請(qǐng)查看IT技術(shù)專欄