AVAILABLE NOW: Spring 2025 Release

Convert Images to Searchable PDF with OCR in C#

By Apryse | 2025 Apr 18

Sanity Image
Read time

6 min

PDFs are used virtually everywhere and by everyone these days. Throughout most organizations, PDF documents are vital to business applications and workflows. Many industries such as insurance agencies, financial institutions, and legal practices have standardized their document management systems on the PDF format due to the file format’s portability and versatility.

How these PDFs are being consumed depends on the type of PDF being dealt with. There are two main types of PDFs: image and searchable. For example, if you use a word processor to save the PDF, then that most likely will be a searchable PDF and you may copy/paste the text within the document as you please. On the other hand, if you use a scanner to convert paper to PDF, that most likely will be an image PDF and you will not be able to be able to search the text.

Even if you use a scanner to create an image PDF or were sent an image PDF by someone else, there still is a way to make it searchable. This happens through OCR. Developers are able to easily make automated OCR solutions and achieve these image to searchable PDF conversions with as little as five lines of code thanks to Apryse's powerful OCR libraries. These solutions are what save people and companies their two most valuable resources: time and money.

For this task, you’ll need the Apryse SDK and the Apryse OCR Module. The below code shows you all that is needed to create a solution that converts images to searchable PDFs.

C# Code:

Copied to clipboard

class Program  

{  

   public static string inputImage = @"Path to input image file";  

   public static string outputPDF = @"path to output PDF file";  

  

   public static void Main(string[] args)  

   {  

      PDFNet.Initialize("Place your license key here");  

  

        PDFNet.AddResourceSearchPath("../../../../../Lib/");  

  

      if (!OCRModule.IsModuleAvailable())  

      {  

         Console.WriteLine("");  

         Console.WriteLine("Unable to run OCRTest: Apryse SDK OCR module not available.");  

         Console.WriteLine("---------------------------------------------------------------");  

         Console.WriteLine("The OCR module is an optional add-on, available for download");  

         Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");  

         Console.WriteLine("module, ensure that the SDK is able to find the required files");  

         Console.WriteLine("using the PDFNet.AddResourceSearchPath() function.");  

         Console.WriteLine("");  

         return;  

      }  

  

      ImageToPdf();  

   }  

   public static void ImageToPdf()  

   {  

      try  

      {  

         using (PDFDoc doc = new PDFDoc())  

         {  

            OCRModule.ImageToPDF(doc, inputImage, null);  

            doc.Save(outputPDF, pdftron.SDF.SDFDoc.SaveOptions.e_linearized);  

         }  

      }  

      catch (Exception e)  

      {  

         Console.WriteLine(e.ToString());  

      }  

   }  

}  

See For Yourself - Free Evaluation

Copied to clipboard

Download the Apryse SDK for free. It’s fully functional and comes with free chat and email support.

Stay Tuned for More Conversion Samples

Stay tuned for more conversion examples to see how Apryse easily fits into any workflow converting PDF files into other document files or images and back again. Need help in the meantime? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team.

Sanity Image

Apryse

Share this post

email
linkedIn
twitter