Text extraction v10.0.0

PDF to Text for .NET

The ExpertPdf PDF to Text Converter extracts the text from a PDF document in any type of .NET application. The result is a .NET String you can use in search operations or save to a file on disk. No installation is needed to run the converter.

Keep the original PDF layout or extract in reading order, choose the pages, open password protected documents, mark the page breaks, save the text as HTML with meta tags from the PDF description, and search for text with its page and position.

NuGet · ExpertPdf.PdfToText C# & VB.NET samples included
Output .NET String or HTML
Layout Original or reading order
Targets .NET Framework to .NET 11

Everything PDF to Text does.

Grouped by how the text comes out of the PDF document and what you get back.

Extraction

How the text comes out.

From a file or a stream, in the original layout or in reading order, from the pages you choose, from password protected documents.

Extract from a file or a stream

Pass the path of a PDF file, or a Stream such as a FileStream or a MemoryStream holding the PDF bytes.

Keep the original layout

The default layout keeps the text where it was on the page: a page with two columns of text gives two columns of text.

Extract in reading order

In reading order, two columns of text become two blocks of text, one after the other.

Choose the pages

Extract only a range of pages with StartPageNumber and EndPageNumber. By default all the pages are extracted.

Password protected PDFs

Open password protected documents with the UserPassword property.

Get the page count

GetPageCount returns the number of pages of a PDF file or stream.

Document information

GetDocumentInformation returns the title, author and page count, and the size and rotation of every page, without extracting the text.

Output & search

What you get back.

A string or an HTML document, page break marks, and the positions of the text you search for.

A .NET String

ConvertToText returns the text as a .NET String you can search or save to a file on disk.

Text per page

ConvertToTextPages returns one string per page, in one call.

HTML with meta tags

Save the text in an HTML document with the title, subject, keywords and author from the PDF document description as meta tags.

Mark the page breaks

Insert a special character after the text of each page. The character is given by PdfToTextConverter.PAGE_BREAK_MARK.

Search with positions

Search for a text and get the page number and the position on the page (X, Y, width and height) of every match.

Several terms at once

SearchTexts searches for several terms in one pass, with the results grouped by term and page. Arabic and other non-Latin text is found whatever the character forms in the PDF.

Text from an area

ExtractTextAtCoords returns the text inside a rectangle of a given page.

A PDF, as a string.

The PdfToTextConverter class: extract text from a file, save it as HTML from a stream, and search for text. All the properties and methods are in the API reference.

Program.cs · C#
using ExpertPdf;

var converter = new PdfToTextConverter();
converter.Layout = TextLayout.ReadingLayout;
converter.MarkPageBreaks = true;
converter.StartPageNumber = 1;
converter.EndPageNumber = 5;

// From a file path, or from a Stream with ConvertToText(stream)
string text = converter.ConvertToText("contract.pdf");
File.WriteAllText("contract.txt", text, System.Text.Encoding.UTF8);

The download includes a ready-to-use sample application with its full C# and VB.NET source code. Install from NuGet with dotnet add package ExpertPdf.PdfToText, or read the developer's guide.

Text extraction questions, answered.

Common questions about layouts, output, page ranges and search.

What is the difference between the original layout and reading order?
With the default TextLayout.OriginalLayout, the text keeps its layout from the PDF page: a page with two columns of text gives two columns of text. With TextLayout.ReadingLayout, the same page gives two blocks of text, one after the other. Choose the layout with the Layout property.
What does the converter return?
A .NET String with the extracted text, which you can search or save to a file. When AddHtmlMetaTags is true, the text is placed in an HTML document whose meta tags hold the title, subject, keywords and author from the PDF document description. The charset meta tag is set by HtmlCharset and is UTF-8 by default.
Can it extract text from password protected PDF documents?
Yes. Set the UserPassword property to the password that opens the document.
Can I extract the text of only some pages?
Yes. Set the StartPageNumber and EndPageNumber properties. By default the text of all the pages is extracted.
Can I search for text in a PDF document?
Yes. ExtractTextPositions searches a PDF file or stream for a text, case sensitive or not, whole words only or not, and returns a TextPosition for each match, with the page number, X, Y, width and height. ExtractTextAtCoords does the opposite: it returns the text inside a rectangle of a given page.
Can I get the text of each page separately, or search several terms at once?
Yes. ConvertToTextPages returns one string per page, and SearchTexts searches for several terms in one call, with the results grouped by term and by page, including their positions.
Does it need an installation?
No installation is necessary. Install the ExpertPdf.PdfToText package from NuGet, or copy eppdftotext.dll and eptools.dep from the download to the bin folder of your application and reference eppdftotext.dll.
Which .NET versions and operating systems are supported?
.NET Framework and .NET Core / .NET 5 to .NET 11 (through .NET Standard 2.0), with assemblies for .NET Framework 2.0 and 4.0 and for .NET Standard 2.0. The library runs on Windows, in 32-bit or 64-bit applications. An x64 optimized package, ExpertPdf.PdfToText.x64, is also available for applications that run as x64 processes.
Is there a free version I can try?
Yes. Download the free evaluation, which includes a ready-to-use sample application with its full C# and VB.NET source code. The evaluation version extracts the text from the first 5 pages of a PDF document.

Extract text from PDF documents in .NET.

Download the free evaluation with the C# and VB.NET sample application. When you are ready, license it on the pricing page.

Targets.NET Framework · .NET Core · .NET 5 to 11
Versionv10.0.0