C# Read PDF Walkthrough

Today we'll walk through an easy way how to read PDF content and extract text in its original format, from enitre documents or from specific pages, all within your C# project.


Step 1

1. Install IronPDF

Your first step to reading a PDF file in C# will be to install IronPDF, a C# PDF Library that gives you full generating, editing, and manipulating capabilities for your documents in .NET.

You can download the software or access through the NuGet page. IronPDF is free for development and you can use it in your project during this walkthrough tutorial.


 PM > Install-Package IronPdf

How to Tutorial

2. Read PDF File in C#

As you open IronPDF, you can see that the library has great functionality for making it easier to work with PDFs. Feel free to explore all the classes and functions.

Using this C# library, we can read PDF files, extract content, and even extract high quality and original images. See the examples below for the many ways we can use different functions to achieve our PDF reading needs in a .NET environment.

/**
Read PDF File
anchor-read-pdf-file-in-c-num
**/
using IronPdf;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace readpdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //Select the Desired PDF File
            using PdfDocument PDF = PdfDocument.FromFile("any.pdf");

            //Using ExtractAllText() method, extract every single text from an pdf
            string AllText = PDF.ExtractAllText();
            //View text in an Label or textbox
            label2.Text = AllText;

            //Get all Images
            IEnumerable<Image> AllImages = PDF.ExtractAllImages();
            //View Image in a PictureBox
            pictureBox1.Image = AllImages.First();

            //Else Combine above both functionality using PageCount
            for (var index = 0; index < PDF.PageCount; index++)
            {
                int PageNumber = index + 1;
                string Text = PDF.ExtractTextFromPage(index);
                IEnumerable<Image> Images = PDF.ExtractImagesFromPage(index);
            }

        }
    }
}
/**
Read PDF File
anchor-read-pdf-file-in-c-num
**/
using IronPdf;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace readpdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //Select the Desired PDF File
            using PdfDocument PDF = PdfDocument.FromFile("any.pdf");

            //Using ExtractAllText() method, extract every single text from an pdf
            string AllText = PDF.ExtractAllText();
            //View text in an Label or textbox
            label2.Text = AllText;

            //Get all Images
            IEnumerable<Image> AllImages = PDF.ExtractAllImages();
            //View Image in a PictureBox
            pictureBox1.Image = AllImages.First();

            //Else Combine above both functionality using PageCount
            for (var index = 0; index < PDF.PageCount; index++)
            {
                int PageNumber = index + 1;
                string Text = PDF.ExtractTextFromPage(index);
                IEnumerable<Image> Images = PDF.ExtractImagesFromPage(index);
            }

        }
    }
}
'''
'''Read PDF File
'''anchor-read-pdf-file-in-c-num
'''*
Imports IronPdf
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Linq
Imports System.Windows.Forms

Namespace readpdf
	Partial Public Class Form1
		Inherits Form

		Public Sub New()
			InitializeComponent()

			'Select the Desired PDF File
			Using PDF As PdfDocument = PdfDocument.FromFile("any.pdf")
	
				'Using ExtractAllText() method, extract every single text from an pdf
				Dim AllText As String = PDF.ExtractAllText()
				'View text in an Label or textbox
				label2.Text = AllText
	
				'Get all Images
				Dim AllImages As IEnumerable(Of Image) = PDF.ExtractAllImages()
				'View Image in a PictureBox
				pictureBox1.Image = AllImages.First()
	
				'Else Combine above both functionality using PageCount
				For index = 0 To PDF.PageCount - 1
					Dim PageNumber As Integer = index + 1
					Dim Text As String = PDF.ExtractTextFromPage(index)
					Dim Images As IEnumerable(Of Image) = PDF.ExtractImagesFromPage(index)
				Next index
	
			End Using
		End Sub
	End Class
End Namespace
VB   C#

3. PDF Output

We have used a C# Form to show you the perfect output of reading the PDF content. With this approach, it's all about simplicity and using as little code as possible to achieve your project needs.

~ PDF ~

~ C# Form ~


Library Quick Access

Library Documentation

Documentation for the IronPDF library is available in the handy API Reference for you to explore and share.

Library Documentation