Extract PDF via C#

Parse text and images from PDF document. Use Aspose.PDF for .NET to modify PDF files programmatically

Most popular action with Parser in C#

How to parse PDF with .NET Library

Do you need to extract PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With .NET libraries like Aspose.PDF, developers can extract text from PDF or extract images from PDF. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional C# developers.

  • Extract PDF data: texts, images, forms, fields, etc.
  • Extract text from PDF
  • Extract Images from PDF
  • Extract Fonts from PDF
  • Extract Data from the Form
  • Extract Text From Stamps
  • Extract Data from Table

In order to extract PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy-to-use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Parse PDF via C#


To try the code in your environment, you need Aspose.PDF for .NET.

  1. Load the PDF with an instance of Document.
  2. Create TextAbsorber object to extract text.
  3. Accept the absorber for all the pages.
  4. Get the extracted text
  5. Create a writer and open the file, write a line of text to the file

Extract PDF Files - C#

This sample code shows how to extract PDF documents

Input file:

File not added

Output format:

PDF

Output file:


    // Open document
    Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf");

    // Create TextAbsorber object to extract text
    TextAbsorber textAbsorber = new TextAbsorber();
    // Accept the absorber for all the pages
    pdfDocument.Pages.Accept(textAbsorber);
    // Get the extracted text
    string extractedText = textAbsorber.Text;
    // Create a writer and open the file
    TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt");
    // Write a line of text to the file
    tw.WriteLine(extractedText);
    // Close the stream
    tw.Close();

About Aspose.PDF for .NET API

Aspose.PDF for C# API provides a wide range of features for working with PDF files. Some of the features include:

  • Create PDF documents from scratch or from HTML, XML, or images.
  • Edit existing PDF documents by adding or removing pages, text, images, and other content.
  • Convert PDF documents to other formats such as HTML, XML, and images.
  • Render PDF documents to images or XPS format.
  • Print PDF documents directly from your application.
  • Digitally sign PDF documents.

You can find more information on Aspose.PDF for C# API in this Aspose documentation