Essential PDF如何从PDF文件中快速提取文本

作者:控件中国网   出处:控件中国网   2015-12-16 14:52:17   阅读:5

Essential PDF是一款专门用于处理和操作PDF文件的商业控件,可以用于Windows Forms, WPF, Silverlight, ASP.NET and ASP.NET MVC, WinRT, Windows phone, Windows store universal 和Xamarin等平台下进行PDF文件的创建、读取和写入操作,支持为PDF文件添加文本、各种格式的图片、表格和图形,能够合并和分割PDF文件,支持转换HTML, RTF, Microsoft word, Microsoft Excel和 XPS文件为PDF格式,兼容 PDFX1-A and PDFA1-B,该产品包含在Syncfusion公司提供的各大套包产品里以及Essential Studio File Formats套包产品里。
 
这篇文章主要介绍怎么利用Essential PDF控件提供的丰富API对PDF文件内的文本进行提取,具体可以参考下面的代码:
 
1.从PDF文件的某页中提取文本
//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
//Load the first page.
PdfPageBase page = loadedDocument.Pages[0];
//Extract text from first page.
string extractedText = page.ExtractText();
//Close the document
loadedDocument.Close(true);
 
2.从整个PDF文件中提取文本
// Load an existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
 
// Loading page collections
PdfLoadedPageCollection loadedPages = loadedDocument.Pages;
string extractedText = string.Empty;
 
// Extract text from existing PDF document pages
foreach (PdfLoadedPage lpage in loadedPages)
 
{
extractedText += lpage.ExtractText();
}
// Close the document.
loadedDocument.Close(true);
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat