示例文件:

详细步骤:
Step 1: 初始化PdfDocument类的对象并加载PDF文件。
PdfDocument pdf = new PdfDocument();pdf.LoadFromFile("Stories.pdf");
Step 2: 获取第一页。
PdfPageBase page = pdf.Pages[0];
Step 3: 从页面中的特定矩形区域中提取文本,之后将文本保存为.txt文件。
string text = page.ExtractText(new RectangleF(50, 50, 500, 100) );StringBuilder sb = new StringBuilder();sb.AppendLine(text);File.WriteAllText("Extract.txt", sb.ToString());
输出:

完整代码:
//Initialize an object of PdfDocument classPdfDocument pdf = new PdfDocument();//Load the PDF filepdf.LoadFromFile("Stories.pdf");//Get the first pagePdfPageBase page = pdf.Pages[0];// Extract text from a specific rectangular area within the pagestring text = page.ExtractText(new RectangleF(50, 50, 500, 100) );//Save the text to a .txt fileStringBuilder sb = new StringBuilder();sb.AppendLine(text);File.WriteAllText("Extract.txt", sb.ToString());
标签:文档管理文件格式转换PDF文档处理
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!