How to extract data from pdf document in C#
Loading
How to extract data from pdf document in C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Cynthia SathuragiriPosted Mar 18, 2026, 4:49 AM
To extract data from a PDF in C#, you typically use a library like iText7 or PdfPig.
using iText7:
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
string text = "";
using (PdfReader reader = new PdfReader("sample.pdf"))
using (PdfDocument pdf = new PdfDocument(reader))
{
for (int i = 1; i <= pdf.GetNumberOfPages(); i++)
{
text += PdfTextExtractor.GetTextFromPage(pdf.GetPage(i));
}
}
Console.WriteLine(text);
Install via NuGet:
Install-Package itext7
Works well for text-based PDFs
For scanned PDFs, use OCR tools like Tesseract OCR
Brian WatsonPosted Mar 18, 2026, 4:41 AM
You can use libraries like iText7 or PdfSharp in C# to read and extract text or data from PDF files easily. Try it out with a small test PDF!
Sangeetha SPosted Mar 4, 2026, 9:36 AM
Install-Package itext7
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using System;
class Program
{
static void Main(string[] args)
{
string pdfPath = "sample.pdf";
using (PdfReader reader = new PdfReader(pdfPath))
using (PdfDocument pdf = new PdfDocument(reader))
{
int numberOfPages = pdf.GetNumberOfPages();
for (int i = 1; i <= numberOfPages; i++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string text = PdfTextExtractor.GetTextFromPage(pdf.GetPage(i), strategy);
Console.WriteLine($"--- Page {i} ---");
Console.WriteLine(text);
}
}
}
}