PDF to PNG - pqScan.com
.NET PDF to Text SDK Easy to Extract PDF Text and Convert PDF Document to Text File in .NET Download Trial Purchase Now

How to Use C# to Extract Text from PDF

back to home  >  .NET PDF to Text SDK  >  How to Extract Text from PDF in .NET  >  PDF to Text Extraction Using C#

pqScan PDF to Text Extractor SDK for .NET empowers C# programmers to easily extract and get text content in PDF document without using Adobe PDF reader or any other third-part software. And the exported PDF content can be saved in String Object or directly converted to text file using Visual C# programming, thus can be easily searched, archived and recycled.

Now, in the following sections, we will provide developers with C# examples for how to extract plain text from PDF file and how to convert PDF to txt file. Please feel free to download .NET PDF to Text Extractor and Converter SDK online to have a test.

PDF to Text Extraction - C# Example

The functionality of pqScan .NET PDF to Text Extractor is similar to OCR technology, which is easily be used for text recognition from PDF in C#. The example below explains how to use C# class code to get text from PDF file page(s) in Visual Studio .NET program. C# developers can quickly extract text from one page, a few pages, and all pages of PDF document.

using System;
using System.Text;
using PQScan.PDFToText;

namespace PDF2Text
{
  class Program
  {
    static void Main(string[] args)
    {
      // Create an instance of PQScan.PDFToText.PDFExtractor object.
      PDFExtractor extractor = new PDFExtractor();

      // Load a PDF document.
      extractor.LoadPDF("sample.pdf");

      // Get total page count.
      int count = extractor.PageCount;

      for (int i = 0; i < count; i++)
      {
        // Extract text from each PDF file page.
        string pageText = extractor.ToText(i);
        Console.WriteLine(pageText);
      }

      // Extract text from whole PDF document.
      string totalText = extractor.ToText();
      Console.WriteLine(totalText);
    }
  }
}

PDF to Text File Conversion - C# Example

Our .NET PDF to Text Converter Software also allows users to convert PDF to text file without losing formatting using C# code. Please directly copy free example below to extract text from whole PDF and save it to text file.

using System;
using System.Text;
using PQScan.PDFToText;

namespace PDF2TextFile
{
  class Program
  {
    static void Main(string[] args)
    {
      // Create an instance of PQScan.PDFToText.PDFExtractor object.
      PDFExtractor extractor = new PDFExtractor();

      // Load a PDF file.
      extractor.LoadPDF("sample.pdf");

      // Convert whole PDF text to txt file.
      extractor.ToTextFile("output-text.txt");
    }
  }
}

To see more .NET APIs for PDF text extraction, please refer to .NET Tutorial: How to Extract Text from PDF.

pqScan SDK
.NET PDF to Text Converter
Online Guide
.NET Guide for PDF to Text VB.NET Guide for PDF to Text ASP.NET Guide for PDF to Text
Considering product quality, speed and licensing price, pqScan SDK is the clear choice for me. Very professional and useful product! Emin Couvelier