感谢您的查看,
6665.jpg (76.9 KB)
// Open document 打开PDF文件
Aspose.Pdf.Document pdfDocument1 = new Aspose.Pdf.Document(fi);
// Create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber();
// Accept the absorber for all the pages
pdfDocument1.Pages.Accept(textAbsorber);
// Get the extracted text
string extractedText = textAbsorber.Text;
// Create a writer and open the file Create a writer and open the file
var dir = System.IO.Path.GetDirectoryName(fi);
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fi);
string wb = dir+"\\"+ fileNameWithoutExtension+".txt";
//不要空格
extractedText.Trim().Replace(" ", "");
extractedText.Replace(" ", "");
extractedText.Replace("\n", "");
extractedText.Replace(" ", string.Empty);
extractedText.Replace("\n", string.Empty);
//创建txt文本和写入权限
FileStream fs1 = new FileStream(wb, FileMode.Create, FileAccess.Write);//创建写入
TextWriter tw = new StreamWriter(fs1);
// Write a line of text to the file 在文件中写入一行文本
tw.WriteLine(extractedText);
// Close the stream 关闭小溪
tw.Close();