Extract Text using TextLineCollection
17 Feb 20221 minute to read
The PDF Viewer server library allows you to extract the text from a page along with the bounds using TextLineCollection. Text extracting can be done using the ExtractText() method.
Add the following dependency to your application using the
NuGet Package Manager.
From Volume 2 2019 release Syncfusion.Pdf.AspNet.Mvc5 and Syncfusion.Compression.Base packages are added as dependency for PDF Viewer control. Ensure the dependency packages are referred in your application properly.
The following code snippet explains how to extract the text from a page using TextLineCollection.
var path = @"currentDirectory\..\..\..\..\Data\Simple.pdf"; var fileInfo = new FileInfo(path); var docStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); // Load the PDF document. PdfLoadedDocument document = new PdfLoadedDocument(docStream); // Loading page collections PdfPageBase page = document.Pages as PdfLoadedPage; //Extract text from the page. var text = page.ExtractText(out TextLineCollection textLineCollection);
Find the sample How to extract text using TextLineCollection
Ensure the provided document path and output text saved locations in your application level.