> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/ocrtest.md).

# OCR - search PDFs and Extract Text

Sample code shows how to use the Apryse OCR module on scanned documents in multiple languages. The OCR module can make searchable PDFs and extract scanned text for further indexing.  Samples provided

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/core/get-started/get-started.md" class="button primary">Server SDK</a><a href="https://apryse.com/capabilities#OpticalCharacterRecognition(OCR)" class="button primary">Package: OCR</a><a href="https://docs.apryse.com/core/guides/info/modules#ocr-module" class="button primary">Module: OCR</a><a href="https://showcase.apryse.com/ocr-module" class="button primary">Live demo</a>
{% endhint %}

Sample code shows how to use the Apryse Server OCR module on scanned documents in multiple languages; provided in Python, C++, C# (.Net), Java, Node.js (JavaScript), PHP, Ruby and VB. The OCR module can make searchable PDFs and extract scanned text for further indexing.

Looking for OCR + WebViewer? Check out our [OCR - Showcase Sample Code](/web/get-started/samples/showcase-demo-ocr-module.md)

Learn more about our [Server SDK](/core/get-started/get-started.md) and [OCR capabilities](https://apryse.com/capabilities/ocr).

### Implementation steps

To run this sample, you will need:

1. [Get started with Server SDK](/core/get-started/get-started.md) in your language/framework
2. [Download OCR Module](/core/learn-more/modules.md#ocr-module)
3. Add the sample code provided below

To use this feature in production, your license key will need the [OCR Package](https://apryse.com/capabilities#OpticalCharacterRecognition\(OCR\)). Trial keys already include this package.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.     
//---------------------------------------------------------------------------------------

using System;
using pdftron;
using pdftron.Common;
using pdftron.SDF;
using pdftron.PDF;

namespace OCRTestCS
{
    
    /// <summary>
    //---------------------------------------------------------------------------------------
    // The following sample illustrates how to use OCR module
    //---------------------------------------------------------------------------------------
    /// </summary>
    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() {}
        
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // The first step in every application using PDFNet is to initialize the 
            // library and set the path to common PDF resources. The library is usually 
            // initialized only once, but calling Initialize() multiple times is also fine.
            PDFNet.Initialize(PDFTronLicense.Key);

            // Can optionally set path to the OCR module
            PDFNet.AddResourceSearchPath("../../../../../Lib/");

            // if the IRIS OCR module is available, will use that instead of the default
            bool use_iris = OCRModule.IsIRISModuleAvailable();
            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 https://docs.apryse.com/core/guides/info/modules#ocr-module . 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;
            }

            // Relative path to the folder containing test files.
            string input_path =  "../../../../TestFiles/OCR/";
            string output_path = "../../../../TestFiles/Output/";

            //--------------------------------------------------------------------------------
            // Example 1) Process image
            try
            {

                // A) Setup empty destination doc
                using (PDFDoc doc = new PDFDoc())
                {
                    // B) Set English as the language of choice
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("eng");

                    // C) Run OCR on the .png with options            
                    OCRModule.ImageToPDF(doc, input_path + "psychomachia_excerpt.png", opts);

                    // D) check the result
                    doc.Save(output_path + "psychomachia_excerpt.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 1: psychomachia_excerpt.png");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //--------------------------------------------------------------------------------
            // Example 2) Process document using multiple languages
            try
            {

                // A) Setup empty destination doc
                using (PDFDoc doc = new PDFDoc())
                {

                    // B) Setup options with multiple target languages, English will always be considered as secondary language
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("deu");
                    opts.AddLang("fra");
                    opts.AddLang("eng");

                    // C) Run OCR on the .jpg with options        
                    OCRModule.ImageToPDF(doc, input_path + "multi_lang.jpg", opts);

                    // D) check the result
                    doc.Save(output_path + "multi_lang.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 2: multi_lang.jpg");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //--------------------------------------------------------------------------------
            // Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
            try
            {

                // A) Open the .pdf document
                using (PDFDoc doc = new PDFDoc(input_path + "german_kids_song.pdf"))
                {

                    // B) Setup options with a single language and an ignore zone
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("deu");

                    RectCollection ignoreZones = new RectCollection();
                    ignoreZones.AddRect(424, 163, 493, 730);
                    opts.AddIgnoreZonesForPage(ignoreZones, 1);

                    // C) Run OCR on the .pdf with options
                    OCRModule.ProcessPDF(doc, opts);

                    // D) check the result
                    doc.Save(output_path + "german_kids_song.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 3: german_kids_song.pdf");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //--------------------------------------------------------------------------------
            // Example 4) Process multipage tiff with text/ignore zones specified for each page
            try
            {

                // A) Setup empty destination doc
                using (PDFDoc doc = new PDFDoc())
                {

                    // B) Setup options with a single language plus text/ignore zones
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("eng");

                    RectCollection zones = new RectCollection();


                    // ignore signature box in the first 2 pages
                    zones.AddRect(1492, 56, 2236, 432);
                    opts.AddIgnoreZonesForPage(zones, 1);
                    zones.Clear();

                    zones.AddRect(1492, 56, 2236, 432);
                    opts.AddIgnoreZonesForPage(zones, 2);
                    zones.Clear();

                    // can use a combination of ignore and text boxes to focus on the page area of interest,
                    // as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
                    zones.AddRect(992, 1276, 1368, 1372);
                    opts.AddIgnoreZonesForPage(zones, 3);
                    zones.Clear();

                    // select horizontal BUFFER ZONE sign
                    zones.AddRect(900, 2384, 1236, 2480);
                    // select right vertical BUFFER ZONE sign
                    zones.AddRect(1960, 1976, 2016, 2296);
                    // select Lot No.
                    zones.AddRect(696, 1028, 1196, 1128);

                    // select part of the plan inside the BUFFER ZONE
                    zones.AddRect(428, 1484, 1784, 2344);
                    zones.AddRect(948, 1288, 1672, 1476);
                    opts.AddTextZonesForPage(zones, 3);

                    // C) Run OCR on the .pdf with options
                    OCRModule.ImageToPDF(doc, input_path + "bc_environment_protection.tif", opts);

                    // D) check the result
                    doc.Save(output_path + "bc_environment_protection.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 4: bc_environment_protection.tif");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //--------------------------------------------------------------------------------
            // Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
            // out special characters), and finally applying modified OCR JSON to the source PDF document 
            try
            {

                // A) Open the .pdf document
                using (PDFDoc doc = new PDFDoc(input_path + "zero_value_test_no_text.pdf"))
                {

                    // B) set English language
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("eng");


                    // C) Run OCR on the .pdf 
                    string json = OCRModule.GetOCRJsonFromPDF(doc, opts);

                    // D) Post-processing step (whatever it might be), but we just print JSON here
                    Console.WriteLine("Have OCR result JSON, re-applying to PDF");

                    // E) Apply potentially modified OCR JSON to the PDF
                    OCRModule.ApplyOCRJsonToPDF(doc, json);

                    // F) check the result
                    doc.Save(output_path + "zero_value_test_no_text.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            //--------------------------------------------------------------------------------
            // Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
            try
            {

                // A) Setup empty destination doc
                using (PDFDoc doc = new PDFDoc())
                {

                    // B) set English language
                    OCROptions opts = new OCROptions();
                    if(use_iris) opts.SetOCREngine("iris");
                    opts.AddLang("eng");

                    // C) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
                    // in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.

                    string xml = OCRModule.GetOCRXmlFromImage(doc, input_path + "physics.tif", opts);

                    // D) Post-processing step (whatever it might be), but we just print XML here
                    Console.WriteLine("Have OCR result XML, re-applying to PDF");

                    // E) Apply potentially modified OCR XML to the PDF
                    OCRModule.ApplyOCRXmlToPDF(doc, xml);

                    // F) check the result
                    doc.Save(output_path + "physics.pdf", SDFDoc.SaveOptions.e_remove_unused);

                    Console.WriteLine("Example 6: extracting and applying OCR XML from physics.tif");
                }

            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            PDFNet.Terminate();
        }

    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}

<pre class="language-go" data-line-numbers><code class="lang-go">//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

package main

import (
	"fmt"
	. "github.com/pdftron/pdftron-go/v2"
)

// Relative path to the folder containing test files.
var inputPath =  "../../TestFiles/OCR/"
var outputPath = "../../TestFiles/Output/"

// ---------------------------------------------------------------------------------------
// The following sample illustrates how to use OCR module
// --------------------------------------------------------------------------------------

func main(){

    // The first step in every application using PDFNet is to initialize the 
	// library and set the path to common PDF resources. The library is usually 
	// initialized only once, but calling Initialize() multiple times is also fine.
	var licenseKey = "<code class="expression">visitor.claims.serverKey || "YOUR_LICENSE_KEY"</code>"
	PDFNetInitialize(licenseKey)

	var iris_installed = true // Set to true if the IRIS OCR module is installed and you wish to use it

	// The location of the OCR Module
	if iris_installed {
		PDFNetAddResourceSearchPath("../../IRISOCRModuleWindows/Lib")
	} else {
		PDFNetAddResourceSearchPath("../../OCRModuleWindows/Lib")
	}

	var use_iris = OCRModuleIsIRISModuleAvailable()

	if ! OCRModuleIsModuleAvailable(){
		fmt.Println("Unable to run OCRTest: PDFTron SDK OCR module not available.\n" +
		"---------------------------------------------------------------\n" +
		"The OCR module is an optional add-on, available for download\n" +
		"at https://docs.apryse.com/core/guides/info/modules#ocr-module . If you have already downloaded this\n" +
		"module, ensure that the SDK is able to find the required files\n" +
		"using the PDFNetAddResourceSearchPath() function.")
		return
	}

	// Example 1) Process image without specifying options, default language - English - is used
	// --------------------------------------------------------------------------------

	// A) Setup empty destination doc
	doc := NewPDFDoc()

	// B) Run OCR on the .png with options
	ocrOpts := NewOCROptions()
	if use_iris {
		ocrOpts.SetOCREngine("iris")
	}
		
	OCRModuleImageToPDF(doc, inputPath + "psychomachia_excerpt.png", ocrOpts)

	// C) Check the result
	doc.Save(outputPath + "psychomachia_excerpt.pdf", uint(0))
	fmt.Println("Example 1: psychomachia_excerpt.png")

	// Example 2) Process document using multiple languages
	// --------------------------------------------------------------------------------

	// A) Setup empty destination doc
	doc = NewPDFDoc()

	// B) Setup options with multiple target languages, English will always be considered as secondary language
	opts := NewOCROptions()
	if use_iris {
		opts.SetOCREngine("iris")
	}
	opts.AddLang("deu")
	opts.AddLang("fra")
	opts.AddLang("eng")

	// C) Run OCR on the .jpg with options
	OCRModuleImageToPDF(doc, inputPath + "multi_lang.jpg", opts)

	// D) Check the result
	doc.Save(outputPath + "multi_lang.pdf", uint(0))
	fmt.Println("Example 2: multi_lang.jpg")

	// Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image
	// --------------------------------------------------------------------------------

	// A) Open the .pdf document
	doc = NewPDFDoc(inputPath + "german_kids_song.pdf")

	// B) Setup options with a single language and an ignore zone
	opts = NewOCROptions()
	if use_iris {
		opts.SetOCREngine("iris")
	}
	opts.AddLang("deu")

	ignoreZones := NewRectCollection()
	ignoreZones.AddRect(NewRect(424.0, 163.0, 493.0, 730.0))
	opts.AddIgnoreZonesForPage(ignoreZones, 1)

	// C) Run OCR on the .pdf with options
	OCRModuleProcessPDF(doc, opts)

	// D) check the result
	doc.Save(outputPath + "german_kids_song.pdf", uint(0))
	fmt.Println("Example 3: german_kids_song.pdf")

	// Example 4) Process multi-page tiff with text/ignore zones specified for each page,
	// --------------------------------------------------------------------------------

	// A) Setup empty destination doc
	doc = NewPDFDoc()

	// B) Setup options with a single language plus text/ignore zones
	opts = NewOCROptions()
	if use_iris {
		opts.SetOCREngine("iris")
	}
	opts.AddLang("eng")

	ignoreZones = NewRectCollection()

	// ignore signature box in the first 2 pages
	ignoreZones.AddRect(NewRect(1492.0, 56.0, 2236.0, 432.0))
	opts.AddIgnoreZonesForPage(ignoreZones, 1)
	opts.AddIgnoreZonesForPage(ignoreZones, 2)

	// can use a combination of ignore and text boxes to focus on the page area of interest,
	// as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
	ignoreZones.Clear()
	ignoreZones.AddRect(NewRect(992.0, 1276.0, 1368.0, 1372.0))
	opts.AddIgnoreZonesForPage(ignoreZones, 3)

	textZones := NewRectCollection()
	// we only have text zones selected in page 3
	// select horizontal BUFFER ZONE sign
	textZones.AddRect(NewRect(900.0, 2384.0, 1236.0, 2480.0))
	// select right vertical BUFFER ZONE sign
	textZones.AddRect(NewRect(1960.0, 1976.0, 2016.0, 2296.0))
	// select Lot No.
	textZones.AddRect(NewRect(696.0, 1028.0, 1196.0, 1128.0))

	// select part of the plan inside the BUFFER ZONE
	textZones.AddRect(NewRect(428.0, 1484.0, 1784.0, 2344.0))
	textZones.AddRect(NewRect(948.0, 1288.0, 1672.0, 1476.0))
	opts.AddTextZonesForPage(textZones, 3)

	// C) Run OCR on the .pdf with options
	OCRModuleImageToPDF(doc, inputPath + "bc_environment_protection.tif", opts)

	// D) check the result
	doc.Save(outputPath + "bc_environment_protection.pdf", uint(0))
	fmt.Println("Example 4: bc_environment_protection.tif")

	// Example 5) Alternative workflow for extracting OCR result JSON, postprocessing
	// (e.g., removing words not in the dictionary or filtering out special characters),
	// and finally applying modified OCR JSON to the source PDF document
	// --------------------------------------------------------------------------------

	// A) Open the .pdf document
	doc = NewPDFDoc(inputPath + "zero_value_test_no_text.pdf")

	// B) Run OCR on the .pdf with English language

	opts = NewOCROptions()
	if use_iris {
		opts.SetOCREngine("iris")
	}
	opts.AddLang("eng")

	// C) Run OCR on the .pdf
	json := OCRModuleGetOCRJsonFromPDF(doc, opts)

	// D) Post-processing step (whatever it might be)
	fmt.Println("Have OCR result JSON, re-applying to PDF")
	
	// E) Apply potentially modified OCR JSON to the PDF
	OCRModuleApplyOCRJsonToPDF(doc, json)

	// F) Check the result
	doc.Save(outputPath + "zero_value_test_no_text.pdf", uint(0))
	fmt.Println("Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf")

	// Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format,
	// similar to the one used by TextExtractor
	// --------------------------------------------------------------------------------

	// A) Setup empty destination doc
	doc = NewPDFDoc()

	// B) Run OCR on the .tif with English language, extracting OCR results in XML format. Note that
	// in the process we convert the source image into PDF.
	// We reuse this PDF document later to add hidden text layer to it.
	opts = NewOCROptions()
	if use_iris {
		opts.SetOCREngine("iris")
	}
	opts.AddLang("eng")
	xml := OCRModuleGetOCRXmlFromImage(doc, inputPath + "physics.tif", opts)

	// C) Post-processing step (whatever it might be)
	fmt.Println("Have OCR result XML, re-applying to PDF")

	// D) Apply potentially modified OCR XML to the PDF
	OCRModuleApplyOCRXmlToPDF(doc, xml)

	// E) Check the result
	doc.Save(outputPath + "physics.pdf", uint(0))
	fmt.Println("Example 6: extracting and applying OCR XML from physics.tif")
}

</code></pre>

{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------
#include <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/OCRModule.h>
#include <PDF/OCROptions.h>
#include <SDF/Obj.h>
#include <iostream>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace std;
using namespace pdftron;
using namespace PDF;
using namespace SDF;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use OCR module
//---------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
	try 
	{
		// The first step in every application using PDFNet is to initialize the 
		// library and set the path to common PDF resources. The library is usually 
		// initialized only once, but calling Initialize() multiple times is also fine.
		PDFNet::Initialize(LicenseKey);
		// The location of the OCR Module
		PDFNet::AddResourceSearchPath("../../../Lib/");

		// if the IRIS OCR module is available, will use that instead of the default
		const bool use_iris = OCRModule::IsIRISModuleAvailable();
		if(!OCRModule::IsModuleAvailable())
		{
			cout << endl;
			cout << "Unable to run OCRTest: Apryse SDK OCR module not available." << endl;
			cout << "---------------------------------------------------------------" << endl;
			cout << "The OCR module is an optional add-on, available for download" << endl;
			cout << "at https://docs.apryse.com/core/guides/info/modules#ocr-module . If you have already downloaded this" << endl;
			cout << "module, ensure that the SDK is able to find the required files" << endl;
			cout << "using the PDFNet::AddResourceSearchPath() function." << endl << endl;
			return 0;
		}

		// Relative path to the folder containing test files.
		string input_path =  "../../TestFiles/OCR/";
		string output_path = "../../TestFiles/Output/";


		//--------------------------------------------------------------------------------
		// Example 1) Process image without specifying options, default language - English - is used
		try 
		{

			// A) Setup empty destination doc

			PDFDoc doc;

			// B) Run OCR on the .png without options

			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");
			OCRModule::ImageToPDF(doc, input_path + "psychomachia_excerpt.png", &opts);

			// C) check the result

			doc.Save(output_path + "psychomachia_excerpt.pdf", 0, 0);
			
			cout << "Example 1: psychomachia_excerpt.png" << endl;

		}
		catch(Common::Exception& e)	
		{
			cout << e << endl;
		}
		catch(...) 
		{
			cout << "Unknown Exception" << endl;
		}

		//--------------------------------------------------------------------------------
		// Example 2) Process document using multiple languages
		try
		{
			// A) Setup empty destination doc

			PDFDoc doc;

			// B) Setup options with multiple target languages, English will always be considered as secondary language

			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");
			opts.AddLang("deu");
			opts.AddLang("fra");
			opts.AddLang("eng");

			// C) Run OCR on the .jpg with options

			OCRModule::ImageToPDF(doc, input_path + "multi_lang.jpg", &opts);

			// D) check the result

			doc.Save(output_path + "multi_lang.pdf", 0, 0);

			cout << "Example 2: multi_lang.jpg" << endl;

		}
		catch (Common::Exception& e)
		{
			cout << e << endl;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
		}

		//--------------------------------------------------------------------------------
		// Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
		try
		{
			// A) Open the .pdf document

			PDFDoc doc((input_path + "german_kids_song.pdf").c_str());

			// B) Setup options with a single language and an ignore zone

			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");
			opts.AddLang("deu");

			RectCollection ignore_zones;
			ignore_zones.AddRect(424, 163, 493, 730);
			opts.AddIgnoreZonesForPage(ignore_zones, 1);

			// C) Run OCR on the .pdf with options

			OCRModule::ProcessPDF(doc, &opts);

			// D) check the result

			PDFDoc doc_out(doc);
			doc_out.Save(output_path + "german_kids_song.pdf", 0, 0);

			cout << "Example 3: german_kids_song.pdf" << endl;
		}
		catch (Common::Exception& e)
		{
			cout << e << endl;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
		}

		//--------------------------------------------------------------------------------
		// Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language
		try
		{
			// A) Setup empty destination doc

			PDFDoc doc;

			// B) Setup options with a single language plus text/ignore zones

			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");
			opts.AddLang("eng");

			RectCollection ignore_zones;
			// ignore signature box in the first 2 pages
			ignore_zones.AddRect(1492, 56, 2236, 432);
			opts.AddIgnoreZonesForPage(ignore_zones, 1);
			opts.AddIgnoreZonesForPage(ignore_zones, 2);

			// can use a combination of ignore and text boxes to focus on the page area of interest,
			// as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
			ignore_zones.Clear();
			ignore_zones.AddRect(992, 1276, 1368, 1372);
			opts.AddIgnoreZonesForPage(ignore_zones, 3);

			RectCollection text_zones;
			// we only have text zones selected in page 3

			// select horizontal BUFFER ZONE sign
			text_zones.AddRect(900, 2384, 1236, 2480);
			// select right vertical BUFFER ZONE sign
			text_zones.AddRect(1960, 1976, 2016, 2296);
			// select Lot No.
			text_zones.AddRect(696, 1028, 1196, 1128);

			// select part of the plan inside the BUFFER ZONE
			text_zones.AddRect(428, 1484, 1784, 2344);
			text_zones.AddRect(948, 1288, 1672, 1476);
			opts.AddTextZonesForPage(text_zones, 3);

			// C) Run OCR on the .tif with options

			OCRModule::ImageToPDF(doc, input_path + "bc_environment_protection.tif", &opts);

			// D) check the result

			doc.Save(output_path + "bc_environment_protection.pdf", 0, 0);

			cout << "Example 4: bc_environment_protection.tif" << endl;

		}
		catch (Common::Exception& e)
		{
			cout << e << endl;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
		}

		//--------------------------------------------------------------------------------
		// Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
		// out special characters), and finally applying modified OCR JSON to the source PDF document 
		try
		{

			// A) Open the .pdf document

			PDFDoc doc((input_path + "zero_value_test_no_text.pdf").c_str());

			// B) Run OCR on the .pdf with default English language
			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");

			UString json = OCRModule::GetOCRJsonFromPDF(doc, &opts);

			// C) Post-processing step (whatever it might be)

			cout << "Have OCR result JSON, re-applying to PDF " << endl;

			// D) Apply potentially modified OCR JSON to the PDF

			OCRModule::ApplyOCRJsonToPDF(doc, json);

			// E) Check the result

			PDFDoc doc_out(doc);
			doc_out.Save(output_path + "zero_value_test_no_text.pdf", 0, 0);

			cout << "Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf" << endl;

		}
		catch (Common::Exception& e)
		{
			cout << e << endl;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
		}

		//--------------------------------------------------------------------------------
		// Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
		try
		{

			// A) Setup empty destination doc

			PDFDoc doc;

			// B) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
			// in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
			
			OCROptions opts;
			if(use_iris) opts.SetOCREngine("iris");
			UString xml = OCRModule::GetOCRXmlFromImage(doc, input_path + "physics.tif", NULL);

			// C) Post-processing step (whatever it might be)

			cout << "Have OCR result XML, re-applying to PDF" << endl;

			// D) Apply potentially modified OCR XML to the PDF

			OCRModule::ApplyOCRXmlToPDF(doc, xml);

			// E) Check the result

			PDFDoc doc_out(doc);
			doc_out.Save(output_path + "physics.pdf", 0, 0);

			cout << "Example 6: extracting and applying OCR XML from physics.tif" << endl;

		}
		catch (Common::Exception& e)
		{
			cout << e << endl;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
		}

		cout << "Done." << endl;

		PDFNet::Terminate();
	}
	catch(Common::Exception& e)	
	{
		cout << e << endl;
	}
	catch (...) {
		cout << "Unknown Exception" << endl;
	}

	return 0;	
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.sdf.Obj;
import com.pdftron.sdf.ObjSet;
import com.pdftron.sdf.SDFDoc;
import com.pdftron.pdf.*;

import com.pdftron.common.PDFNetException;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use OCR module
//---------------------------------------------------------------------------------------
public class OCRTest {
	public static void main(String[] args) {
		try {
			// The first step in every application using PDFNet is to initialize the
			// library and set the path to common PDF resources. The library is usually
			// initialized only once, but calling Initialize() multiple times is also fine.
			PDFNet.initialize(PDFTronLicense.Key());
			PDFNet.addResourceSearchPath("../../../Lib/");

			boolean use_iris = OCRModule.isIRISModuleAvailable();
			if( !OCRModule.isModuleAvailable() )
			{
				System.out.println("");
				System.out.println("Unable to run OCRTest: Apryse SDK OCR module not available.");
				System.out.println("---------------------------------------------------------------");
				System.out.println("The OCR module is an optional add-on, available for download");
				System.out.println("at https://docs.apryse.com/core/guides/info/modules#ocr-module . If you have already downloaded this");
				System.out.println("module, ensure that the SDK is able to find the required files");
				System.out.println("using the PDFNet.addResourceSearchPath() function.");
				System.out.println("");
				return;
			}

			// Relative path to the folder containing test files.
			String input_path = "../../TestFiles/OCR/";
			String output_path = "../../TestFiles/Output/";

			//--------------------------------------------------------------------------------
			// Example 1) Process image without specifying options, default language - English - is used
			try (PDFDoc doc = new PDFDoc()) // A) Setup empty destination doc
			{
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");

				// B) Run OCR on the .png with options
				OCRModule.imageToPDF(doc, input_path + "psychomachia_excerpt.png", options);

				// C) check the result
				doc.save(output_path + "psychomachia_excerpt.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 1: psychomachia_excerpt.png");
				
			} catch (Exception e) {
				e.printStackTrace();
			}

			//--------------------------------------------------------------------------------
			// Example 2) Process document using multiple languages
			try (PDFDoc doc = new PDFDoc()) // A) Setup empty destination doc
			{
				// B) Setup options with multiple target languages, English will always be considered as secondary language
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");
				options.addLang("deu");
				options.addLang("fra");
				options.addLang("eng");

				// C) Run OCR on the .jpg with options
				OCRModule.imageToPDF(doc, input_path + "multi_lang.jpg", options);

				// D) check the result
				doc.save(output_path + "multi_lang.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 2: multi_lang.jpg");
			} catch (Exception e) {
				e.printStackTrace();
			}

			//--------------------------------------------------------------------------------
			// Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
			try (PDFDoc doc = new PDFDoc(input_path + "german_kids_song.pdf")) // A) Open the .pdf document
			{
				// B) Setup options with a single language and an ignore zone
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");
				options.addLang("deu");

				RectCollection zones = new RectCollection();
				zones.addRect(424, 163, 493, 730);

				options.addIgnoreZonesForPage(zones, 1);

				// C) Run OCR on the .pdf with options
				OCRModule.processPDF(doc, options);
				
				// D) check the result
				doc.save(output_path + "german_kids_song.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 3: german_kids_song.pdf");
			} catch (Exception e) {
				e.printStackTrace();
			}

			//--------------------------------------------------------------------------------
			// Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language

			try (PDFDoc doc = new PDFDoc()) // A) Setup empty destination doc
			{
				// B) Setup options with a single language plus text/ignore zones
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");
				options.addLang("eng");

				RectCollection zones = new RectCollection();
				zones.addRect(1492, 56, 2236, 432);

				// ignore signature box in the first 2 pages
				options.addIgnoreZonesForPage(zones, 1);
				options.addIgnoreZonesForPage(zones, 2);

				// can use a combination of ignore and text boxes to focus on the page area of interest,
				// as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
				zones.clear();
				zones.addRect(992, 1276, 1368, 1372);
				options.addIgnoreZonesForPage(zones, 3);

				// we only have text zones selected in page 3

				zones.clear();
				// select horizontal BUFFER ZONE sign
				zones.addRect(900, 2384, 1236, 2480);
				// select right vertical BUFFER ZONE sign
				zones.addRect(1960, 1976, 2016, 2296);
				// select Lot No.
				zones.addRect(696, 1028, 1196, 1128);

				// select part of the plan inside the BUFFER ZONE
				zones.addRect(428, 1484, 1784, 2344);
				zones.addRect(948, 1288, 1672, 1476);

				options.addTextZonesForPage(zones, 3);

				// C) Run OCR on the .tif with options
				OCRModule.imageToPDF(doc, input_path + "bc_environment_protection.tif", options);
				
				// D) check the result
				doc.save(output_path + "bc_environment_protection.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 4: bc_environment_protection.tif");
			} catch (Exception e) {
				e.printStackTrace();
			}

			//--------------------------------------------------------------------------------
			// Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
			// out special characters), and finally applying modified OCR JSON to the source PDF document 
			try (PDFDoc doc = new PDFDoc(input_path + "zero_value_test_no_text.pdf")) // A) Open the .pdf document
			{
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");

				// B) Run OCR on the .pdf with default English language
				String json = OCRModule.getOCRJsonFromPDF(doc, options);

				// C) Post-processing step (whatever it might be), but we just print json here
				System.out.println("Have OCR result JSON, re-applying to PDF");

				// D) Apply potentially modified OCR JSON to the PDF
				OCRModule.applyOCRJsonToPDF(doc, json);

				// E) Check the result
				doc.save(output_path + "zero_value_test_no_text.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf");
			} catch (Exception e) {
				e.printStackTrace();
			}

			//--------------------------------------------------------------------------------
			// Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
			try (PDFDoc doc = new PDFDoc()) // A) Setup empty destination doc
			{
				OCROptions options = new OCROptions();
				if(use_iris) options.setOCREngine("iris");

				// B) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
				// in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
				String xml = OCRModule.getOCRXmlFromImage(doc, input_path + "physics.tif", options);

				// C) Post-processing step (whatever it might be), but we just print XML here
				System.out.println("Have OCR result XML, applying to PDF");

				// D) Apply potentially modified OCR XML to the PDF
				OCRModule.applyOCRXmlToPDF(doc, xml);

				// E) Check the result
				doc.save(output_path + "physics.pdf", SDFDoc.SaveMode.LINEARIZED, null);
				System.out.println("Example 6: extracting and applying OCR XML from physics.tif");
			}
			catch (Exception e) {
				e.printStackTrace();
			}

			PDFNet.terminate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------


const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
  'use strict';

  //---------------------------------------------------------------------------------------
  // The following sample illustrates how to use OCR module
  //---------------------------------------------------------------------------------------
  exports.runOCRTest = () => {
    const main = async () => {
      try {

        PDFNet.addResourceSearchPath('../../lib/');

        const useIRIS = await PDFNet.OCRModule.isIRISModuleAvailable();
        if (!(await PDFNet.OCRModule.isModuleAvailable())) {
          console.log('\nUnable to run OCRTest: Apryse SDK OCR module not available.');
          console.log('---------------------------------------------------------------');
          console.log('The OCR module is an optional add-on, available for download');
          console.log('at https://docs.apryse.com/core/guides/info/modules#ocr-module . If you have already downloaded this');
          console.log('module, ensure that the SDK is able to find the required files');
          console.log('using the PDFNet.addResourceSearchPath() function.\n');

          return;
        }

        // Relative path to the folder containing test files.
        const input_path = '../TestFiles/OCR/';
        const output_path = '../TestFiles/Output/';

        //--------------------------------------------------------------------------------
        // Example 1) Process image without specifying options, default language - English - is used
        try {

          // A) Setup empty destination doc
          const doc = await PDFNet.PDFDoc.create();
          
          await doc.initSecurityHandler();

          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');

          // B) Run OCR on the .png with options
          await PDFNet.OCRModule.imageToPDF(doc, input_path + 'psychomachia_excerpt.png', opts);

          // C) check the result
          await doc.save(output_path + 'psychomachia_excerpt.pdf', 0);

          console.log('Example 1: psychomachia_excerpt.png');

        } catch (err) {
          console.log(err);
        }

        //--------------------------------------------------------------------------------
        // Example 2) Process document using multiple languages
        try {
          // A) Setup empty destination doc
          const doc = await PDFNet.PDFDoc.create();
          await doc.initSecurityHandler();

          // B) Setup options with multiple target languages, English will always be considered as secondary language
          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');
          opts.addLang('deu');
          opts.addLang('fra');
          opts.addLang('eng');

          // C) Run OCR on the .jpg with options
          await PDFNet.OCRModule.imageToPDF(doc, input_path + 'multi_lang.jpg', opts);

          // D) check the result
          await doc.save(output_path + 'multi_lang.pdf', 0);

          console.log('Example 2: multi_lang.jpg');
        } catch (err) {
          console.log(err);
        }

        //--------------------------------------------------------------------------------
        // Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
        try {
          // A) Open the .pdf document
          const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'german_kids_song.pdf');
          doc.initSecurityHandler();

          // B) Setup options with a single language and an ignore zone
          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');
          opts.addLang('deu');

          const ignore_zones = [];
          ignore_zones.push(new PDFNet.Rect(424, 163, 493, 730));
          opts.addIgnoreZonesForPage(ignore_zones, 1);

          // C) Run OCR on the .pdf with options
          await PDFNet.OCRModule.processPDF(doc, opts);

          // D) check the result
          await doc.save(output_path + 'german_kids_song.pdf', 0);

          console.log('Example 3: german_kids_song.pdf');
        } catch (err) {
          console.log(err);
        }

        //--------------------------------------------------------------------------------
        // Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language
        try {
          // A) Setup empty destination doc
          const doc = await PDFNet.PDFDoc.create();
          await doc.initSecurityHandler();

          // B) Setup options with a single language plus text/ignore zones
          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');
          opts.addLang('eng');

          var ignore_zones = [];
          // ignore signature box in the first 2 pages
          ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
          opts.addIgnoreZonesForPage(ignore_zones, 1);

          ignore_zones = [];
          ignore_zones.push(new PDFNet.Rect(1492, 56, 2236, 432));
          opts.addIgnoreZonesForPage(ignore_zones, 2);

          // can use a combination of ignore and text boxes to focus on the page area of interest,
          // as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
          ignore_zones = [];
          ignore_zones.push(new PDFNet.Rect(992, 1276, 1368, 1372));
          opts.addIgnoreZonesForPage(ignore_zones, 3);


          const text_zones = [];
          // we only have text zones selected in page 3

          // select horizontal BUFFER ZONE sign
          text_zones.push(new PDFNet.Rect(900, 2384, 1236, 2480));
          // select right vertical BUFFER ZONE sign
          text_zones.push(new PDFNet.Rect(1960, 1976, 2016, 2296));
          // select Lot No.
          text_zones.push(new PDFNet.Rect(696, 1028, 1196, 1128));

          // select part of the plan inside the BUFFER ZONE
          text_zones.push(new PDFNet.Rect(428, 1484, 1784, 2344));
          text_zones.push(new PDFNet.Rect(948, 1288, 1672, 1476));
          opts.addTextZonesForPage(text_zones, 3);

          // C) Run OCR on the .tif with options
          await PDFNet.OCRModule.imageToPDF(doc, input_path + 'bc_environment_protection.tif', opts);

          // D) check the result
          await doc.save(output_path + 'bc_environment_protection.pdf', 0);

          console.log('Example 4: bc_environment_protection.tif');
        } catch (err) {
          console.log(err);
        }

        //--------------------------------------------------------------------------------
        // Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
        // out special characters), and finally applying modified OCR JSON to the source PDF document 
        try {
          // A) Open the .pdf document
          const doc = await PDFNet.PDFDoc.createFromFilePath(input_path + 'zero_value_test_no_text.pdf');
          await doc.initSecurityHandler();

          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');

          // B) Run OCR on the .pdf with default English language
          const json = await PDFNet.OCRModule.getOCRJsonFromPDF(doc, opts);

          // C) Post-processing step (whatever it might be)
          console.log('Have OCR result JSON, re-applying to PDF ');

          // D) Apply potentially modified OCR JSON to the PDF
          await PDFNet.OCRModule.applyOCRJsonToPDF(doc, json);

          // E) Check the result
          await doc.save(output_path + 'zero_value_test_no_text.pdf', 0);

          console.log('Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf');
        } catch (err) {
          console.log(err);
        }

        //--------------------------------------------------------------------------------
        // Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
        try {

          // A) Setup empty destination doc
          const doc = await PDFNet.PDFDoc.create();
          await doc.initSecurityHandler();

          const opts = new PDFNet.OCRModule.OCROptions();
          if(useIRIS) opts.setOCREngine('iris');

          // B) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
          // in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
          const xml = await PDFNet.OCRModule.getOCRXmlFromImage(doc, input_path + 'physics.tif', opts);

          // C) Post-processing step (whatever it might be)
          console.log('Have OCR result XML, re-applying to PDF');

          // D) Apply potentially modified OCR XML to the PDF
          await PDFNet.OCRModule.applyOCRXmlToPDF(doc, xml);

          // E) Check the result
          await doc.save(output_path + 'physics.pdf', 0);

          console.log('Example 6: extracting and applying OCR XML from physics.tif');
        } catch (err) {
          console.log(err);
        }
        console.log('Done.');
      } catch (err) {
        console.log(err);
      }
    };
    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function(error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function(){ return PDFNet.shutdown(); });
  };
  exports.runOCRTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=OCRTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/OCR/";
$output_path = getcwd()."/../../TestFiles/Output/";

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use OCR module
//---------------------------------------------------------------------------------------
	
	// The first step in every application using PDFNet is to initialize the 
	// library and set the path to common PDF resources. The library is usually 
	// initialized only once, but calling Initialize() multiple times is also fine.
	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.

	// The location of the OCR Module
	PDFNet::AddResourceSearchPath("../../../Lib/");

	// If the IRIS OCR module is available, will use that instead of the default
	$use_iris = OCRModule::IsIRISModuleAvailable();
	if(!OCRModule::IsModuleAvailable()) {
		echo "Unable to run OCRTest: PDFTron SDK OCR module not available.\n
			---------------------------------------------------------------\n
			The OCR module is an optional add-on, available for download\n
			at https://dev.apryse.com/. If you have already downloaded this\n
			module, ensure that the SDK is able to find the required files\n
			using the PDFNet::AddResourceSearchPath() function.\n";
	} else
	{
		//--------------------------------------------------------------------------------
		// Example 1) Process image 
		// A) Setup empty destination doc

		$doc = new PDFDoc();

		// B) Use the IRIS OCR engine if available

		$opts = new OCROptions();
		if ($use_iris) {
		    $opts->SetOCREngine("iris");
		}

		// C) Run OCR on the .png with options
		OCRModule::ImageToPDF($doc, $input_path."psychomachia_excerpt.png", $opts);

		// D) Check the result

		$doc->Save($output_path."psychomachia_excerpt.pdf", 0);

		echo "Example 1: psychomachia_excerpt.png \n";


		//--------------------------------------------------------------------------------
		// Example 2) Process document using multiple languages
	 
		// A) Setup empty destination doc
		
		$doc = new PDFDoc();

		// B) Setup options with multiple target languages, English will always be considered as secondary language

		$opts = new OCROptions();
		if ($use_iris) {
		    $opts->SetOCREngine("iris");
		}
		$opts->AddLang("deu");
		$opts->AddLang("fra");
		$opts->AddLang("eng");

		// B) Run OCR on the .png with options

		OCRModule::ImageToPDF($doc, $input_path."multi_lang.jpg", $opts);

		// C) check the result

		$doc->Save($output_path."multi_lang.pdf", 0);

		echo "Example 2: multi_lang.jpg \n";


		//--------------------------------------------------------------------------------
		// Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
		
		// A) Open the .pdf document
		
		$doc = new PDFDoc($input_path."german_kids_song.pdf");

		// B) Setup options with a single language and an ignore zone

		$opts = new OCROptions();
		if ($use_iris) {
		    $opts->SetOCREngine("iris");
		}
		$opts->AddLang("deu");

		$ignore_zones = new RectCollection();
		$rect = new Rect(424.0, 163.0, 493.0, 730.0);
		$ignore_zones->AddRect($rect);
		$opts->AddIgnoreZonesForPage($ignore_zones, 1);

		// C) Run OCR on the .pdf with options

		OCRModule::ProcessPDF($doc, $opts);

		// D) check the result

		$doc->Save($output_path."german_kids_song.pdf", 0);

		echo "Example 3: german_kids_song.pdf \n";

		//--------------------------------------------------------------------------------
		// Example 4) Process multipage tiff with text/ignore zones specified for each page, optionally provide English as the target language
		
		// A) Setup empty destination doc
		
		$doc = new PDFDoc();

		// B) Setup options with a single language plus text/ignore zones

		$opts = new OCROptions();
		if ($use_iris) {
		    $opts->SetOCREngine("iris");
		}
		$opts->AddLang("eng");

		$ignore_zones = new RectCollection();
		// ignore signature box in the first 2 pages
		$ignore_zones->AddRect(new Rect(1492.0, 56.0, 2236.0, 432.0));
		$opts->AddIgnoreZonesForPage($ignore_zones, 1);
		$opts->AddIgnoreZonesForPage($ignore_zones, 2);

		// can use a combination of ignore and text boxes to focus on the page area of interest,
		// as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
		$ignore_zones->Clear();
		$ignore_zones->AddRect(new Rect(992.0, 1276.0, 1368.0, 1372.0));
		$opts->AddIgnoreZonesForPage($ignore_zones, 3);


		$text_zones = new RectCollection();
		// we only have text zones selected in page 3

		// select horizontal BUFFER ZONE sign
		$text_zones->AddRect(new Rect(900.0, 2384.0, 1236.0, 2480.0));
		// select right vertical BUFFER ZONE sign
		$text_zones->AddRect(new Rect(1960.0, 1976.0, 2016.0, 2296.0));
		// select Lot No.
		$text_zones->AddRect(new Rect(696.0, 1028.0, 1196.0, 1128.0));

		// select part of the plan inside the BUFFER ZONE
		$text_zones->AddRect(new Rect(428.0, 1484.0, 1784.0, 2344.0));
		$text_zones->AddRect(new Rect(948.0, 1288.0, 1672.0, 1476.0));
		$opts->AddTextZonesForPage($text_zones, 3);

		// C) Run OCR on the .pdf with options

		OCRModule::ImageToPDF($doc, $input_path."bc_environment_protection.tif", $opts);

		// D) check the result

		$doc->Save($output_path."bc_environment_protection.pdf", 0);

		echo "Example 4: bc_environment_protection.tif \n";


		//--------------------------------------------------------------------------------
		// Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words not in the dictionary or filtering special
		// out special characters), and finally applying modified OCR JSON to the source PDF document 
		// A) Setup empty destination doc
		
		$doc = new PDFDoc($input_path."zero_value_test_no_text.pdf");

		// B) Use the IRIS OCR engine if available

		$opts = new OCROptions();
		if ($use_iris) {
				$opts->SetOCREngine("iris");
		}

		// C) Run OCR on the .pdf with default English language

		$json = OCRModule::GetOCRJsonFromPDF($doc, $opts);

		// D) Post-processing step (whatever it might be)

		echo "Have OCR result JSON, re-applying to PDF \n";

		OCRModule::ApplyOCRJsonToPDF($doc, $json);

		// E) check the result

		$doc->Save($output_path."zero_value_test_no_text.pdf", 0);

		echo "Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf \n";


		//--------------------------------------------------------------------------------
		// Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
		
		// A) Setup empty destination doc

		$doc = new PDFDoc();

		// B) Use the IRIS OCR engine if available

		$opts = new OCROptions();
		if ($use_iris) {
				$opts->SetOCREngine("iris");
		}

		// C) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
		// in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.

		$xml = OCRModule::GetOCRXmlFromImage($doc, $input_path."physics.tif", $opts);

		// D) Post-processing step (whatever it might be)

		echo "Have OCR result XML, re-applying to PDF \n";

		OCRModule::ApplyOCRXmlToPDF($doc, $xml);

		// E) check the result

		$doc->Save($output_path."physics.pdf", 0);

		echo "Example 6: extracting and applying OCR XML from physics.tif \n";

		echo "Done. \n";
	}
	
	PDFNet::Terminate();

?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from apryse_sdk import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

# Relative path to the folder containing test files.
input_path = "../../TestFiles/OCR/"
output_path = "../../TestFiles/Output/"

# ---------------------------------------------------------------------------------------
# The following sample illustrates how to use OCR module
# --------------------------------------------------------------------------------------

def main():

    # The first step in every application using PDFNet is to initialize the
    # library and set the path to common PDF resources. The library is usually
    # initialized only once, but calling Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)

    iris_installed = True # Set to True if the IRIS OCR module is installed and you wish to use it

    # The location of the OCR Module
    if iris_installed:
        PDFNet.AddResourceSearchPath("../../../IRISOCRModuleWindows/Lib/")
    else:
        PDFNet.AddResourceSearchPath("../../../OCRModuleWindows/Lib/")
    
    use_iris = OCRModule.IsIRISModuleAvailable()
    
    if not OCRModule.IsModuleAvailable():

        print("""
        Unable to run OCRTest: PDFTron SDK OCR module not available.
        ---------------------------------------------------------------
        The OCR module is an optional add-on, available for download
        at https://dev.apryse.com/. If you have already downloaded this
        module, ensure that the SDK is able to find the required files
        using the PDFNet::AddResourceSearchPath() function.""")

    else:

        # Example 1) Process image
        # --------------------------------------------------------------------------------

        # A) Setup empty destination doc
        doc = PDFDoc()

        # B) Set English as the language of choice
        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("eng")

        # C) Run OCR on the .png with options
        OCRModule.ImageToPDF(doc, input_path + "psychomachia_excerpt.png", opts)

        # D) Check the result
        doc.Save(output_path + "psychomachia_excerpt.pdf", 0)

        print("Example 1: psychomachia_excerpt.png")

        # Example 2) Process document using multiple languages
        # --------------------------------------------------------------------------------

        # A) Setup empty destination doc
        doc = PDFDoc()

        # B) Setup options with multiple target languages, English will always be considered as secondary language
        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("deu")
        opts.AddLang("fra")
        opts.AddLang("eng")

        # C) Run OCR on the .jpg with options
        OCRModule.ImageToPDF(doc, input_path + "multi_lang.jpg", opts)

        # D) Check the result
        doc.Save(output_path + "multi_lang.pdf", 0)

        print("Example 2: multi_lang.jpg")

        # Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image
        # --------------------------------------------------------------------------------

        # A) Open the .pdf document
        doc = PDFDoc(input_path + "german_kids_song.pdf")

        # B) Setup options with a single language and an ignore zone
        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("deu")

        ignore_zones = RectCollection()
        ignore_zones.AddRect(Rect(424, 163, 493, 730))
        opts.AddIgnoreZonesForPage(ignore_zones, 1)

        # C) Run OCR on the .pdf with options
        OCRModule.ProcessPDF(doc, opts)

        # D) check the result
        doc.Save(output_path + "german_kids_song.pdf", 0)

        print("Example 3: german_kids_song.pdf")

        # Example 4) Process multi-page tiff with text/ignore zones specified for each page,
        # --------------------------------------------------------------------------------

        # A) Setup empty destination doc

        doc = PDFDoc()
        # B) Setup options with a single language plus text/ignore zones

        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("eng")

        ignore_zones = RectCollection()

        # ignore signature box in the first 2 pages
        ignore_zones.AddRect(Rect(1492, 56, 2236, 432))
        opts.AddIgnoreZonesForPage(ignore_zones, 1)
        opts.AddIgnoreZonesForPage(ignore_zones, 2)

        # can use a combination of ignore and text boxes to focus on the page area of interest,
        # as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
        ignore_zones.Clear()
        ignore_zones.AddRect(Rect(992, 1276, 1368, 1372))
        opts.AddIgnoreZonesForPage(ignore_zones, 3)

        text_zones = RectCollection()
        # we only have text zones selected in page 3

        # select horizontal BUFFER ZONE sign
        text_zones.AddRect(Rect(900, 2384, 1236, 2480))

        # select right vertical BUFFER ZONE sign
        text_zones.AddRect(Rect(1960, 1976, 2016, 2296))
        # select Lot No.
        text_zones.AddRect(Rect(696, 1028, 1196, 1128))

        # select part of the plan inside the BUFFER ZONE
        text_zones.AddRect(Rect(428, 1484, 1784, 2344))
        text_zones.AddRect(Rect(948, 1288, 1672, 1476))
        opts.AddTextZonesForPage(text_zones, 3)

        # C) Run OCR on the .pdf with options
        OCRModule.ImageToPDF(doc, input_path + "bc_environment_protection.tif", opts)

        # D) check the result
        doc.Save(output_path + "bc_environment_protection.pdf", 0)

        print("Example 4: bc_environment_protection.tif")

        # Example 5) Alternative workflow for extracting OCR result JSON, postprocessing
        # (e.g., removing words not in the dictionary or filtering special
        # out special characters), and finally applying modified OCR JSON to the source PDF document
        # --------------------------------------------------------------------------------

        # A) Open the .pdf document
        doc = PDFDoc(input_path + "zero_value_test_no_text.pdf")
        
        # B) set English language
        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("eng")

        # C) Run OCR on the .pdf
        json = OCRModule.GetOCRJsonFromPDF(doc, opts)

        # D) Post-processing step (whatever it might be)
        print("Have OCR result JSON, re-applying to PDF")

        # E) Apply potentially modified OCR JSON to the PDF
        OCRModule.ApplyOCRJsonToPDF(doc, json)

        # F) Check the result
        doc.Save(output_path + "zero_value_test_no_text.pdf", 0)

        print("Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf")

        # Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format,
        # similar to the one used by TextExtractor
        # --------------------------------------------------------------------------------

        # A) Setup empty destination doc
        doc = PDFDoc()

        # B) set English language
        opts = OCROptions()
        if use_iris: opts.SetOCREngine("iris")
        opts.AddLang("eng")

        # C) Run OCR on the .tif with English language, extracting OCR results in XML format. Note that
        # in the process we convert the source image into PDF.
        # We reuse this PDF document later to add hidden text layer to it.

        xml = OCRModule.GetOCRXmlFromImage(doc, input_path + "physics.tif", opts)

        # D) Post-processing step (whatever it might be)
        print("Have OCR result XML, re-applying to PDF")

        # E) Apply potentially modified OCR XML to the PDF
        OCRModule.ApplyOCRXmlToPDF(doc, xml)

        # F) Check the result
        doc.Save(output_path + "physics.pdf", 0)

        print("Example 6: extracting and applying OCR XML from physics.tif")

        PDFNet.Terminate()

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

# Relative path to the folder containing test files.
input_path =  "../../TestFiles/OCR/"
output_path = "../../TestFiles/Output/"

#---------------------------------------------------------------------------------------
# The following sample illustrates how to use OCR module
#---------------------------------------------------------------------------------------

# The first step in every application using PDFNet is to initialize the 
# library and set the path to common PDF resources. The library is usually 
# initialized only once, but calling Initialize multiple times is also fine.
PDFNet.Initialize(PDFTronLicense.Key)

# The location of the OCR Module
PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");

#Example 1) Convert the first page to PNG and TIFF at 92 DPI.

begin

   # if the IRIS OCR module is available, will use that instead of the default
   use_iris = OCRModule.IsIRISModuleAvailable
   if !OCRModule.IsModuleAvailable
      puts 'Unable to run OCRTest: PDFTron SDK OCR module not available.'
      puts '---------------------------------------------------------------'
      puts 'The OCR module is an optional add-on, available for download'
      puts 'at https://dev.apryse.com/. If you have already downloaded this'
      puts 'module, ensure that the SDK is able to find the required files'
      puts 'using the PDFNet::AddResourceSearchPath() function.'

   else

      # Example 1) Process image with specifying options, IRIS OCR module and English as the language of choice
      # --------------------------------------------------------------------------------

      # A) Setup empty destination doc
      doc = PDFDoc.new

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. English as the language of choice
      opts.AddLang("eng")

      # C) Run OCR on the .png with options
      OCRModule.ImageToPDF(doc, input_path + "psychomachia_excerpt.png", opts)

      # D) Check the result
      doc.Save(output_path + "psychomachia_excerpt.pdf", 0)
      puts "Example 1: psychomachia_excerpt.png"

      doc.Close

      # Example 2) Process document using multiple languages
      # --------------------------------------------------------------------------------

      # A) Setup empty destination doc
      doc = PDFDoc.new

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. multiple target languages, English will always be considered as secondary language
      opts.AddLang("deu")
      opts.AddLang("fra")
      opts.AddLang("eng")

      # C) Run OCR on the .jpg with options
      OCRModule.ImageToPDF(doc, input_path + "multi_lang.jpg", opts)

      # D) Check the result
      doc.Save(output_path + "multi_lang.pdf", 0)
      puts "Example 2: multi_lang.jpg"

      doc.Close

      # Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image
      # --------------------------------------------------------------------------------

      # A) Open the .pdf document
      doc = PDFDoc.new(input_path + "german_kids_song.pdf")

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. German as the language of choice
      opts.AddLang("deu")

      # B.3. ignore zone comprising a sidebar image
      ignore_zones = RectCollection.new
      ignore_zones.AddRect(Rect.new(424, 163, 493, 730))
      opts.AddIgnoreZonesForPage(ignore_zones, 1)

      # C) Run OCR on the .pdf with options
      OCRModule.ProcessPDF(doc, opts)

      # D) check the result
      doc.Save(output_path + "german_kids_song.pdf", 0)
      puts "Example 3: german_kids_song.pdf"

      doc.Close

      # Example 4) Process multi-page tiff with text/ignore zones specified for each page,
      # optionally provide English as the target language
      # --------------------------------------------------------------------------------

      # A) Setup empty destination doc
      doc = PDFDoc.new

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. English as the language of choice
      opts.AddLang("eng")

      # B.3 text/ignore zones
      ignore_zones = RectCollection.new

      # ignore signature box in the first 2 pages
      ignore_zones.AddRect(Rect.new(1492, 56, 2236, 432))
      opts.AddIgnoreZonesForPage(ignore_zones, 1)

      opts.AddIgnoreZonesForPage(ignore_zones, 2)

      # can use a combination of ignore and text boxes to focus on the page area of interest,
      # as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
      ignore_zones.Clear
      ignore_zones.AddRect(Rect.new(992, 1276, 1368, 1372))
      opts.AddIgnoreZonesForPage(ignore_zones, 3)

      text_zones = RectCollection.new
      # we only have text zones selected in page 3

      # select horizontal BUFFER ZONE sign
      text_zones.AddRect(Rect.new(900, 2384, 1236, 2480))

      # select right vertical BUFFER ZONE sign
      text_zones.AddRect(Rect.new(1960, 1976, 2016, 2296))
      # select Lot No.
      text_zones.AddRect(Rect.new(696, 1028, 1196, 1128))

      # select part of the plan inside the BUFFER ZONE
      text_zones.AddRect(Rect.new(428, 1484, 1784, 2344))
      text_zones.AddRect(Rect.new(948, 1288, 1672, 1476))
      opts.AddTextZonesForPage(text_zones, 3)

      # C) Run OCR on the .pdf with options
      OCRModule.ImageToPDF(doc, input_path + "bc_environment_protection.tif", opts)

      # D) check the result
      doc.Save(output_path + "bc_environment_protection.pdf", 0)
      puts "Example 4: bc_environment_protection.tif"

      doc.Close

      # Example 5) Alternative workflow for extracting OCR result JSON, postprocessing
      # (e.g., removing words not in the dictionary or filtering special
      # out special characters), and finally applying modified OCR JSON to the source PDF document
      # --------------------------------------------------------------------------------

      # A) Open the .pdf document
      doc = PDFDoc.new(input_path + "zero_value_test_no_text.pdf")

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. English as the language of choice
      opts.AddLang("eng")

      # C) Run OCR on the .pdf with options
      json = OCRModule.GetOCRJsonFromPDF(doc, opts)

      # D) Post-processing step (whatever it might be)
      puts "Have OCR result JSON, re-applying to PDF"
      OCRModule.ApplyOCRJsonToPDF(doc, json)

      # E) Check the result
      doc.Save(output_path + "zero_value_test_no_text.pdf", 0)
      puts "Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf"

      doc.Close

      # Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format,
      # similar to the one used by TextExtractor
      # --------------------------------------------------------------------------------

      # A) Setup empty destination doc
      doc = PDFDoc.new

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. English as the language of choice
      opts.AddLang("eng")

      # C) Run OCR on the .tif with options, extracting OCR results in XML format. Note that
      # in the process we convert the source image into PDF.
      # We reuse this PDF document later to add hidden text layer to it.
      xml = OCRModule.GetOCRXmlFromImage(doc, input_path + "physics.tif", opts)

      # D) Post-processing step (whatever it might be)
      puts "Have OCR result XML, re-applying to PDF"
      OCRModule.ApplyOCRXmlToPDF(doc, xml)

      # E) Check the result
      doc.Save(output_path + "physics.pdf", 0)
      puts "Example 6: extracting and applying OCR XML from physics.tif"

      doc.Close

      # Example 7) Resolution can be manually set, when DPI missing from metadata or is wrong
      # --------------------------------------------------------------------------------

      # A) Setup empty destination doc
      doc = PDFDoc.new

      # B) Setup options with:
      opts = OCROptions.new

      # B.1. IRIS OCR module, if available
      if use_iris
         opts.SetOCREngine("iris")
      end

      # B.2. text zone
      text_zones = RectCollection.new
      text_zones.AddRect(Rect.new(140, 870, 310, 920))
      opts.AddIgnoreZonesForPage(text_zones, 1)

      # B.3 Manually override DPI
      opts.AddDPI(100)

      # C) Run OCR on the .jpg with options
      OCRModule.ImageToPDF(doc, input_path + "corrupted_dpi.jpg", opts)

      # D) Check the result
      doc.Save(output_path + "corrupted_dpi.pdf", 0)
      puts "Example 7: converting image with corrupted resolution metadata corrupted_dpi.jpg to pdf with searchable text"

      doc.Close

   end
   rescue Exception=>e
      puts e

end
PDFNet.Terminate

```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'---------------------------------------------------------------------------------------
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
' Consult legal.txt regarding legal and license information.     
'---------------------------------------------------------------------------------------
Imports System

Imports pdftron
Imports pdftron.Common
Imports pdftron.SDF
Imports pdftron.PDF

' <summary>
'---------------------------------------------------------------------------------------
' The following sample illustrates how to use OCR module
'---------------------------------------------------------------------------------------
' </summary>
Module OCRTestVB
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' The main entry point for the application.
    Sub Main()

        ' The first step in every application using PDFNet is to initialize the 
        ' library and set the path to common PDF resources. The library is usually 
        ' initialized only once, but calling Initialize() multiple times is also fine.
        PDFNet.Initialize(PDFTronLicense.Key)

        ' Can optionally set path to the OCR module
        PDFNet.AddResourceSearchPath("../../../../../Lib/")

        Dim useOCR As Boolean = OCRModule.IsIRISModuleAvailable()
        If Not OCRModule.IsModuleAvailable() Then
            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 https://docs.apryse.com/core/guides/info/modules#ocr-module . 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
        End If

        ' Relative path to the folder containing test files.
        Dim input_path As String = "../../../../TestFiles/OCR/"
        Dim output_path As String = "../../../../TestFiles/Output/"

        '--------------------------------------------------------------------------------
        ' Example 1) Process image
        Try
            ' A) Setup empty destination doc.
            Using doc As PDFDoc = New PDFDoc()

                ' B) Set English as the language of choice
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("eng")

                ' C) Run OCR on the .png with options
                OCRModule.ImageToPDF(doc, input_path + "psychomachia_excerpt.png", opts)

                ' D) Check the result
                doc.Save(output_path + "psychomachia_excerpt.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 1: psychomachia_excerpt.png")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '--------------------------------------------------------------------------------
        ' Example 2) Process document using multiple languages
        Try
            ' A) Setup empty destination doc.
            Using doc As PDFDoc = New PDFDoc()

                ' B) Setup options with multiple target languages, English will always be considered as secondary language
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("deu")
                opts.AddLang("fra")
                opts.AddLang("eng")

                ' C) Run OCR on the .jpg with options
                OCRModule.ImageToPDF(doc, input_path + "multi_lang.jpg", opts)

                ' D) Check the result
                doc.Save(output_path + "multi_lang.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 2: multi_lang.jpg")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try


        '--------------------------------------------------------------------------------
        ' Example 3) Process a .pdf specifying a language - German - and ignore zone comprising a sidebar image 
        Try
            ' A) Open the .pdf document.
            Using doc As PDFDoc = New PDFDoc(input_path + "german_kids_song.pdf")

                ' B) Setup options with a single language and an ignore zone
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("deu")

                Dim zones As RectCollection = New RectCollection()
                zones.AddRect(424, 163, 493, 730)
                opts.AddIgnoreZonesForPage(zones, 1)

                ' C) Run OCR on the .pdf with options
                OCRModule.ProcessPDF(doc, opts)

                ' D) Check the result
                doc.Save(output_path + "german_kids_song.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 3: german_kids_song.pdf")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '--------------------------------------------------------------------------------
        ' Example 4) Process multipage tiff with text/ignore zones specified for each page
        Try
            ' A) Setup empty destination doc.
            Using doc As PDFDoc = New PDFDoc()

                ' B) Setup options with a single language plus text/ignore zones
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("eng")

                Dim zones As RectCollection = New RectCollection()

                ' ignore Signature box in the first 2 pages
                zones.AddRect(1492, 56, 2236, 432)
                opts.AddIgnoreZonesForPage(zones, 1)
                zones.Clear()
                
                zones.AddRect(1492, 56, 2236, 432)
                opts.AddIgnoreZonesForPage(zones, 2)
                zones.Clear()

                ' can use a combination of ignore And text boxes to focus on the page area of interest,
                ' as ignore boxes are applied first, we remove the arrows before selecting part of the diagram
                zones.AddRect(992, 1276, 1368, 1372)
                opts.AddIgnoreZonesForPage(zones, 3)
                zones.Clear()
                ' we only have text zones selected in page 3


                ' select horizontal BUFFER ZONE sign
                zones.AddRect(900, 2384, 1236, 2480)
                ' select right vertical BUFFER ZONE sign
                zones.AddRect(1960, 1976, 2016, 2296)
                ' select Lot No.
                zones.AddRect(696, 1028, 1196, 1128)

                ' select part of the plan inside the BUFFER ZONE
                zones.AddRect(428, 1484, 1784, 2344)
                zones.AddRect(948, 1288, 1672, 1476)
                opts.AddIgnoreZonesForPage(zones, 3)

                ' C) Run OCR on the .pdf with options
                OCRModule.ImageToPDF(doc, input_path + "bc_environment_protection.tif", opts)

                ' D) Check the result
                doc.Save(output_path + "bc_environment_protection.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 4: bc_environment_protection.tif")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '--------------------------------------------------------------------------------
        ' Example 5) Alternative workflow for extracting OCR result JSON, postprocessing (e.g., removing words Not in the dictionary Or filtering special
        ' out special characters), And finally applying modified OCR JSON to the source PDF document 
        Try
            ' A) Open the .pdf document.
            Using doc As PDFDoc = New PDFDoc(input_path + "zero_value_test_no_text.pdf")

                ' B) Set English as the language of choice
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("eng")

                ' C) Run OCR on the .pdf 
                Dim json As String = OCRModule.GetOCRJsonFromPDF(doc, opts)

                ' D) Post-processing step (whatever it might be), but we just print JSON here
                Console.WriteLine("Have OCR result JSON, re-applying to PDF")

                ' E) Apply potentially modified OCR JSON to the PDF
                OCRModule.ApplyOCRJsonToPDF(doc, json)

                ' F) Check the result
                doc.Save(output_path + "zero_value_test_no_text.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 5: extracting and applying OCR JSON from zero_value_test_no_text.pdf")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '--------------------------------------------------------------------------------
        ' Example 6) The postprocessing workflow has also an option of extracting OCR results in XML format, similar to the one used by TextExtractor
        Try
            ' A) Setup empty destination doc.
            Using doc As PDFDoc = New PDFDoc()

                ' B) Set English as the language of choice
                Dim opts As OCROptions = New OCROptions()
                If useOCR Then opts.SetOCREngine("iris")
                opts.AddLang("eng")

                ' C) Run OCR on the .tif with default English language, extracting OCR results in XML format. Note that
                ' in the process we convert the source image into PDF. We reuse this PDF document later to add hidden text layer to it.
                Dim xml As String = OCRModule.GetOCRXmlFromImage(doc, input_path + "physics.tif", opts)

                ' D) Post-processing step (whatever it might be), but we just print XML here
                Console.WriteLine("Have OCR result XML, re-applying to PDF")

                ' E) Apply potentially modified OCR XML to the PDF
                OCRModule.ApplyOCRXmlToPDF(doc, xml)

                ' F) Check the result
                doc.Save(output_path + "physics.pdf", SDFDoc.SaveOptions.e_remove_unused)

                Console.WriteLine("Example 6: extracting and applying OCR XML from physics.tif")

            End Using
        Catch e As PDFNetException
            Console.WriteLine(e.Message)
        End Try

        PDFNet.Terminate()
    End Sub

End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/ocrtest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
