注意 一定要引用这个两个命名空间
using org.pdfbox.pdmodel;
using org.pdfbox.util;
//PDF 文件读取
//FileInfo file = new FileInfo(Server.MapPath("file\\巅峰销售心理学.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();
}
中国足彩网信息请查看IT技术专栏