Skip to content
Loading
How to read pdf line by line and fetch the data in c#
    1. using IronPdf;  
    2.   
    3. using PdfDocument Pdf = PdfDocument.FromFile("doc.pdf");  
    4. string text = pdf.ExtractAllText();  
    You may use the IronPDF libray to perform all of this in as few as 2 lines of code.
    https://www.ironpdf.com
    +1
  • You can use LEADTOOLS Document SDK technology in your application.
    https://www.leadtools.com/sdk/document
     
    Here is some sample code:
    1. using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false))  
    2. {  
    3.     ocrEngine.Startup(nullnullnullnull);  
    4.     List documentText = new List();  
    5.     var inputDocument = DocumentFactory.LoadFromFile(input, documentOptions);  
    6.     inputDocument.Text.TextExtractionMode = DocumentTextExtractionMode.Auto;  
    7.     inputDocument.Text.OcrEngine = ocrEngine;  
    8.     foreach (var page in inputDocument.Pages)  
    9.     {  
    10.         var pageText = page.GetText();  
    11.    
    12.         pageText.BuildText();  
    13.         documentText.Add(pageText);  
    14.     }  
    15. }  
     
    +1
    1. // Create an instance of Parser class  
    2. using(Parser parser = new Parser("sample.pdf"))  
    3. {  
    4.     // Extract a text into the reader  
    5.     using(TextReader reader = parser.GetText())  
    6.     {  
    7.         // Print a text from the document  
    8.         // If text extraction isn't supported, a reader is null  
    9.         Console.WriteLine(reader == null ? "Text extraction isn't supported" : reader.ReadToEnd());  
    10.     }  
    11. }  
    This code is based on GroupDocs.Parser for .NET.
    +1
  • Read pdf line by line and fetch the data in c#: https://www.iditect.com/tutorial/pdf-to-text/
    1. PdfToTxtConverter converter = new PdfToTxtConverter();  
    2. converter.Load(File.ReadAllBytes("sample.pdf"));  
    3.   
    4. for (int i = 0; i < converter.PageCount; i++)  
    5. {  
    6.     //Extract each page text from PDF with original layout  
    7.     string pageText = converter.PageToText(i);  

     
    +1
    1. PdfDocument doc = new PdfDocument();    
    2. doc.LoadFromFile(@"..\..\..\..\..\..\Data\Sample2.pdf");    
    3.     
    4. StringBuilder buffer= new StringBuilder();    
    5. buffer.Append(document.Pages[0].ExtractText());    
    6.     
    7. String fileName = "TextFromPDF.txt";    
    8. File.WriteAllText(fileName, content.ToString());   
    This solution is based on free Spire.PDF component.
    +1