PDF
.Net
document processing
C#
software development

Reading PDF documents in .Net

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Reading PDF documents in .NET is a common requirement for many applications, whether for extracting text, accessing metadata, or manipulating the content of PDF files. Several libraries and tools facilitate this process, each with its own strengths and features. In this article, we will explore the most popular options, delve into technical explanations, and provide examples to guide you through working with PDF documents in .NET.

Overview of Libraries

.NET developers have several choices when it comes to reading PDF documents. Some of the most commonly used libraries include:

  • iTextSharp: A port of the iText Java library to .NET, iTextSharp is a well-established library for creating and manipulating PDF documents.
  • PdfSharp: A library for creating and processing PDF files with support for drawing, fonts, and more.
  • Aspose.PDF: A powerful commercial product that offers comprehensive features for PDF manipulation.
  • PDF.js: Although primarily a JavaScript library, PDF.js can be used through interop or a web interface for PDF rendering.
  • IronPDF: A commercial library allowing the creation and manipulation of PDFs, offering tools like converting from HTML to PDF.

The choice among these libraries depends on specific project requirements, licensing, and the features needed.

iTextSharp Example

iTextSharp is quite popular due to its robust feature set and its primary focus on PDF manipulation. Below is an example of how to read a PDF file using iTextSharp in .NET.

Installation

First, install the iTextSharp library via NuGet package manager:

  • PdfReader: Initializes a new instance to read the PDF from the file.
  • PdfDocument: Represents the PDF document for manipulation and extraction.
  • PdfTextExtractor: Provides static methods to extract text content from the specified page.
  • PdfDocument: Represents the PDF file being worked on.
  • PdfReader.Open: Opens an existing PDF file.
  • XGraphics: Handles drawing operations, letting you render graphics over a PDF.
  • XImage: Represents images that can be drawn in a PDF.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.