Recently, we published some blog posts such as converting PDF to HTML and PDF to Images programmatically. This article will teach us how to convert PDF to Text in C# using a .NET OCR library. As a .NET developer, you can easily use this library to convert files to other popular file formats. In addition, there is a rich stack of features to automate the text extraction process from PDF documents. However, we will write the steps and the code snippet to demonstrate the text extraction from a scanned PDF file.
The following points will be covered in this article:
- .NET OCR library installation
- How to Convert PDF to Text in C#
- PDF to Text conversion - advanced options
.NET OCR library installation
This library is powerful and offers comprehensive documentation regarding development and usage. You can convert and process various file formats quickly and efficiently.
How to Convert PDF to Text in C#
The text extraction from a scanned PDF file is quite easy and is a matter of a few lines of source code in C#.
Please follow the steps mentioned below:
- Create an object of AsposeOcr class.
- Initialize an instance of the DocumentRecognitionSettings class to recognize images from PDF.
- Set the value of the DetectAreas property to enable automatic text areas detection.
- Create a list of RecognitionResult types, extract text from scanned PDF documents by calling the RecognizePdf method and assign the result to the list.
Copy & paste the following code to convert PDF to TEXT in C#.
PDF to Text conversion - advanced options
In this section, we will explore this library further. It also lets you recognize scanned PDFs from the stream.
Following are the steps:
- Instantiate an instance of the AsposeOcr class.
- Create an instance of the MemoryStream class to recognize PDF from the stream.
- Initialize the constructor of FileStream and load the source file.
- Invoke the CopyTo method to write the bytes to the memory stream.
- Create an object of DocumentRecognitionSettings class that recognizes images from PDF.
- Create a list of RecognitionResult types and initialize with the results of the RecognizePdf method.
Get a Free License
You can get a free temporary license to try the API without evaluation limitations.
This brings us to the end of this blog post. You have learned how to convert PDF to Text in C# programmatically. In addition, we also have explored some advanced methods offered by this .NET OCR library. Moreover, you may visit the documentation to know other features. This guide will surely help you if you are looking to equip your application with a PDF to Text converter. Further, conholdate.com is writing new blog posts on new topics. Therefore, please stay in touch for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
How do I convert a PDF to text programmatically?
What is the easiest way to convert PDF to text
You may visit the documentation of this library to know about the methods with which you can extract the data from scanned PDF files programmatically.