C# 使用 iTextSharp 将 PDF 转换成 TXT 文本

var pdfReader = new PdfReader("xxx.pdf");
StreamWriter output = new StreamWriter(new FileStream("处理结果.txt", FileMode.Create));

int pageCount = pdfReader.NumberOfPages;
for (int pg = 1; pg <= pageCount; pg++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
var value = PdfTextExtractor.GetTextFromPage(pdfReader, pg, strategy);
value = value.Replace(" ", "");
Console.WriteLine(value);
output.Write(value);
}

output.Flush();
output.Close();
Console.Write("处理完毕");
Console.ReadLine();

//网络素材仅限收藏 方便学习

posted @ 2021-06-05 19:29  New_HackerHK  阅读(232)  评论(0编辑  收藏  举报