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
Learn more about our Server SDK and OCR capabilities.
To run this sample, you will need:
To use this feature in production, your license key will need the ICR Package. Trial keys already include this package.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6using System;
7using pdftron;
8using pdftron.Common;
9using pdftron.SDF;
10using pdftron.PDF;
11
12namespace HandwritingICRTestCS
13{
14
15 /// <summary>
16 //---------------------------------------------------------------------------------------
17 // The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
18 // handwriting from image-based pages and apply them as hidden text.
19 //
20 // The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
21 //---------------------------------------------------------------------------------------
22 /// </summary>
23 class Class1
24 {
25 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
26 static Class1() {}
27
28 /// <summary>
29 /// The main entry point for the application.
30 /// </summary>
31 static void Main(string[] args)
32 {
33 // The first step in every application using PDFNet is to initialize the
34 // library and set the path to common PDF resources. The library is usually
35 // initialized only once, but calling Initialize() multiple times is also fine.
36 PDFNet.Initialize(PDFTronLicense.Key);
37
38 // The location of the Handwriting ICR Module
39 PDFNet.AddResourceSearchPath("../../../../../Lib/");
40
41 // Test if the add-on is installed
42 if (!HandwritingICRModule.IsModuleAvailable())
43 {
44 Console.WriteLine("");
45 Console.WriteLine("Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module");
46 Console.WriteLine("not available.");
47 Console.WriteLine("---------------------------------------------------------------");
48 Console.WriteLine("The Handwriting ICR Module is an optional add-on, available for download");
49 Console.WriteLine("at https://dev.apryse.com/. If you have already downloaded this");
50 Console.WriteLine("module, ensure that the SDK is able to find the required files");
51 Console.WriteLine("using the PDFNet.AddResourceSearchPath() function.");
52 Console.WriteLine("");
53 return;
54 }
55
56 // Relative path to the folder containing test files.
57 string input_path = "../../../../TestFiles/HandwritingICR/";
58 string output_path = "../../../../TestFiles/Output/";
59
60 //--------------------------------------------------------------------------------
61 // Example 1) Process a PDF without specifying options
62 try
63 {
64 Console.WriteLine("Example 1: processing icr.pdf");
65
66 // Open the .pdf document
67 using (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
68 {
69 // Run ICR on the .pdf with the default options
70 HandwritingICRModule.ProcessPDF(doc);
71
72 // Save the result with hidden text applied
73 doc.Save(output_path + "icr-simple.pdf", SDFDoc.SaveOptions.e_linearized);
74 doc.Close();
75 }
76 }
77 catch (PDFNetException e)
78 {
79 Console.WriteLine(e.Message);
80 }
81
82 //--------------------------------------------------------------------------------
83 // Example 2) Process a subset of PDF pages
84 try
85 {
86 Console.WriteLine("Example 2: processing pages from icr.pdf");
87
88 // Open the .pdf document
89 using (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
90 {
91 // Process handwriting with custom options
92 HandwritingICROptions options = new HandwritingICROptions();
93
94 // Optionally, process a subset of pages
95 options.SetPages("2-3");
96
97 // Run ICR on the .pdf
98 HandwritingICRModule.ProcessPDF(doc, options);
99
100 // Save the result with hidden text applied
101 doc.Save(output_path + "icr-pages.pdf", SDFDoc.SaveOptions.e_linearized);
102 doc.Close();
103 }
104 }
105 catch (PDFNetException e)
106 {
107 Console.WriteLine(e.Message);
108 }
109
110 //--------------------------------------------------------------------------------
111 // Example 3) Ignore zones specified for each page
112 try
113 {
114 Console.WriteLine("Example 3: processing & ignoring zones");
115
116 // Open the .pdf document
117 using (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
118 {
119 // Process handwriting with custom options
120 HandwritingICROptions options = new HandwritingICROptions();
121
122 // Process page 2 by ignoring the signature area on the bottom
123 options.SetPages("2");
124 RectCollection ignore_zones_page2 = new RectCollection();
125 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
126 // Coordinates rotate with the page, if it has rotation applied.
127 ignore_zones_page2.AddRect(78, 850.1 - 770, 340, 850.1 - 676);
128 options.AddIgnoreZonesForPage(ignore_zones_page2, 2);
129
130 // Run ICR on the .pdf
131 HandwritingICRModule.ProcessPDF(doc, options);
132
133 // Save the result with hidden text applied
134 doc.Save(output_path + "icr-ignore.pdf", SDFDoc.SaveOptions.e_linearized);
135 doc.Close();
136 }
137 }
138 catch (PDFNetException e)
139 {
140 Console.WriteLine(e.Message);
141 }
142
143 //--------------------------------------------------------------------------------
144 // Example 4) The postprocessing workflow has also an option of extracting ICR results
145 // in JSON format, similar to the one used by the OCR Module
146 try
147 {
148 Console.WriteLine("Example 4: extract & apply");
149
150 // Open the .pdf document
151 using (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
152 {
153 // Extract ICR results in JSON format
154 string json = HandwritingICRModule.GetICRJsonFromPDF(doc);
155 System.IO.File.WriteAllText(output_path + "icr-get.json", json);
156
157 // Insert your post-processing step (whatever it might be)
158 // ...
159
160 // Apply potentially modified ICR JSON to the PDF
161 HandwritingICRModule.ApplyICRJsonToPDF(doc, json);
162
163 // Save the result with hidden text applied
164 doc.Save(output_path + "icr-get-apply.pdf", SDFDoc.SaveOptions.e_linearized);
165 doc.Close();
166 }
167 }
168 catch (PDFNetException e)
169 {
170 Console.WriteLine(e.Message);
171 }
172
173 Console.WriteLine("Done.");
174 PDFNet.Terminate();
175 }
176
177 }
178}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult LICENSE.txt regarding license information.
4//---------------------------------------------------------------------------------------
5
6package main
7import (
8 "fmt"
9 "testing"
10 "os"
11 "flag"
12 . "github.com/pdftron/pdftron-go/v2"
13)
14
15var licenseKey string
16var modulePath string
17
18func init() {
19 flag.StringVar(&licenseKey, "license", "", "License key for Apryse SDK")
20 flag.StringVar(&modulePath, "modulePath", "", "Path for downloaded modules")
21}
22
23// Relative path to the folder containing test files.
24var inputPath = "../TestFiles/HandwritingICR/"
25var outputPath = "../TestFiles/Output/"
26
27func WriteTextToFile(outputFile string, text string) {
28 f, err := os.Create(outputFile)
29 if err != nil {
30 fmt.Println(err)
31 }
32
33 defer f.Close()
34
35 _, err2 := f.WriteString(text)
36 if err2 != nil {
37 fmt.Println(err2)
38 }
39}
40
41// ---------------------------------------------------------------------------------------
42// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
43// handwriting from image-based pages and apply them as hidden text.
44//
45// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
46// --------------------------------------------------------------------------------------
47
48func TestHandwritingICR(t *testing.T) {
49
50 // The first step in every application using PDFNet is to initialize the
51 // library and set the path to common PDF resources. The library is usually
52 // initialized only once, but calling Initialize() multiple times is also fine.
53 PDFNetInitialize(licenseKey)
54
55 // The location of the Handwriting ICR Module
56 PDFNetAddResourceSearchPath(modulePath)
57
58 // Test if the add-on is installed
59 if !HandwritingICRModuleIsModuleAvailable() {
60
61 fmt.Println("Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module\n" +
62 "not available.\n" +
63 "---------------------------------------------------------------\n" +
64 "The Handwriting ICR Module is an optional add-on, available for download\n" +
65 "at https://dev.apryse.com/. If you have already downloaded this\n" +
66 "module, ensure that the SDK is able to find the required files\n" +
67 "using the PDFNetAddResourceSearchPath() function.")
68
69 } else {
70
71 // --------------------------------------------------------------------------------
72 // Example 1) Process a PDF without specifying options
73 fmt.Println("Example 1: processing icr.pdf")
74
75 // Open the .pdf document
76 doc := NewPDFDoc(inputPath + "icr.pdf")
77
78 // Run ICR on the .pdf with the default options
79 HandwritingICRModuleProcessPDF(doc)
80
81 // Save the result with hidden text applied
82 doc.Save(outputPath + "icr-simple.pdf", uint(SDFDocE_linearized))
83 doc.Close()
84
85 // --------------------------------------------------------------------------------
86 // Example 2) Process a subset of PDF pages
87 fmt.Println("Example 2: processing pages from icr.pdf")
88
89 // Open the .pdf document
90 doc = NewPDFDoc(inputPath + "icr.pdf")
91
92 // Process handwriting with custom options
93 options := NewHandwritingICROptions()
94
95 // Optionally, process a subset of pages
96 options.SetPages("2-3")
97
98 // Run ICR on the .pdf
99 HandwritingICRModuleProcessPDF(doc, options)
100
101 // Save the result with hidden text applied
102 doc.Save(outputPath + "icr-pages.pdf", uint(SDFDocE_linearized))
103 doc.Close()
104
105 // --------------------------------------------------------------------------------
106 // Example 3) Ignore zones specified for each page
107 fmt.Println("Example 3: processing & ignoring zones")
108
109 // Open the .pdf document
110 doc = NewPDFDoc(inputPath + "icr.pdf")
111
112 // Process handwriting with custom options
113 options = NewHandwritingICROptions()
114
115 // Process page 2 by ignoring the signature area on the bottom
116 options.SetPages("2")
117 ignoreZonesPage2 := NewRectCollection()
118 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
119 // Coordinates rotate with the page, if it has rotation applied.
120 ignoreZonesPage2.AddRect(NewRect(78.0, 850.1 - 770.0, 340.0, 850.1 - 676.0))
121 options.AddIgnoreZonesForPage(ignoreZonesPage2, 2)
122
123 // Run ICR on the .pdf
124 HandwritingICRModuleProcessPDF(doc, options)
125
126 // Save the result with hidden text applied
127 doc.Save(outputPath + "icr-ignore.pdf", uint(SDFDocE_linearized))
128 doc.Close()
129
130 // --------------------------------------------------------------------------------
131 // Example 4) The postprocessing workflow has also an option of extracting ICR results
132 // in JSON format, similar to the one used by the OCR Module
133 fmt.Println("Example 4: extract & apply")
134
135 // Open the .pdf document
136 doc = NewPDFDoc(inputPath + "icr.pdf")
137
138 // Extract ICR results in JSON format
139 json := HandwritingICRModuleGetICRJsonFromPDF(doc)
140 WriteTextToFile(outputPath + "icr-get.json", json)
141
142 // Insert your post-processing step (whatever it might be)
143 // ...
144
145 // Apply potentially modified ICR JSON to the PDF
146 HandwritingICRModuleApplyICRJsonToPDF(doc, json)
147
148 // Save the result with hidden text applied
149 doc.Save(outputPath + "icr-get-apply.pdf", uint(SDFDocE_linearized))
150 doc.Close()
151
152 fmt.Println("Done.")
153
154 PDFNetTerminate()
155 }
156}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5#include <PDF/PDFNet.h>
6#include <PDF/PDFDoc.h>
7#include <PDF/HandwritingICRModule.h>
8#include <PDF/HandwritingICROptions.h>
9#include <iostream>
10#include <fstream>
11#include <vector>
12#include <string>
13#include "../../LicenseKey/CPP/LicenseKey.h"
14
15using namespace std;
16using namespace pdftron;
17using namespace PDF;
18using namespace SDF;
19
20static void WriteTextToFile(const std::string& filename, const UString& text)
21{
22 ofstream out_file(filename.c_str(), ofstream::binary);
23 string out_buf = text.ConvertToUtf8();
24 out_file.write(out_buf.c_str(), out_buf.size());
25 out_file.close();
26}
27
28//---------------------------------------------------------------------------------------
29// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
30// handwriting from image-based pages and apply them as hidden text.
31//
32// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
33//---------------------------------------------------------------------------------------
34int main(int argc, char *argv[])
35{
36 try
37 {
38 // The first step in every application using PDFNet is to initialize the
39 // library and set the path to common PDF resources. The library is usually
40 // initialized only once, but calling Initialize() multiple times is also fine.
41 PDFNet::Initialize(LicenseKey);
42
43 // The location of the Handwriting ICR Module
44 PDFNet::AddResourceSearchPath("../../../Lib/");
45
46 // Test if the add-on is installed
47 if (!HandwritingICRModule::IsModuleAvailable())
48 {
49 cout << endl;
50 cout << "Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module" << endl;
51 cout << "not available." << endl;
52 cout << "---------------------------------------------------------------" << endl;
53 cout << "The Handwriting ICR Module is an optional add-on, available for download" << endl;
54 cout << "at https://dev.apryse.com/. If you have already downloaded this" << endl;
55 cout << "module, ensure that the SDK is able to find the required files" << endl;
56 cout << "using the PDFNet::AddResourceSearchPath() function." << endl << endl;
57 return 0;
58 }
59
60 // Relative path to the folder containing test files.
61 string input_path = "../../TestFiles/HandwritingICR/";
62 string output_path = "../../TestFiles/Output/";
63
64 //--------------------------------------------------------------------------------
65 // Example 1) Process a PDF without specifying options
66 try
67 {
68 cout << "Example 1: processing icr.pdf" << endl;
69
70 // Open the .pdf document
71 PDFDoc doc(input_path + "icr.pdf");
72
73 // Run ICR on the .pdf with the default options
74 HandwritingICRModule::ProcessPDF(doc);
75
76 // Save the result with hidden text applied
77 doc.Save(output_path + "icr-simple.pdf", SDFDoc::e_linearized);
78 }
79 catch (Common::Exception& e)
80 {
81 cout << e << endl;
82 }
83 catch (...)
84 {
85 cout << "Unknown Exception" << endl;
86 }
87
88 //--------------------------------------------------------------------------------
89 // Example 2) Process a subset of PDF pages
90 try
91 {
92 cout << "Example 2: processing pages from icr.pdf" << endl;
93
94 // Open the .pdf document
95 PDFDoc doc(input_path + "icr.pdf");
96
97 // Process handwriting with custom options
98 HandwritingICROptions options;
99
100 // Optionally, process a subset of pages
101 options.SetPages("2-3");
102
103 // Run ICR on the .pdf
104 HandwritingICRModule::ProcessPDF(doc, &options);
105
106 // Save the result with hidden text applied
107 doc.Save(output_path + "icr-pages.pdf", SDFDoc::e_linearized);
108 }
109 catch (Common::Exception& e)
110 {
111 cout << e << endl;
112 }
113 catch (...)
114 {
115 cout << "Unknown Exception" << endl;
116 }
117
118 //--------------------------------------------------------------------------------
119 // Example 3) Ignore zones specified for each page
120 try
121 {
122 cout << "Example 3: processing & ignoring zones" << endl;
123
124 // Open the .pdf document
125 PDFDoc doc(input_path + "icr.pdf");
126
127 // Process handwriting with custom options
128 HandwritingICROptions options;
129
130 // Process page 2 by ignoring the signature area on the bottom
131 options.SetPages("2");
132 RectCollection ignore_zones_page2;
133 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
134 // Coordinates rotate with the page, if it has rotation applied.
135 ignore_zones_page2.AddRect(78, 850.1 - 770, 340, 850.1 - 676);
136 options.AddIgnoreZonesForPage(ignore_zones_page2, 2);
137
138 // Run ICR on the .pdf
139 HandwritingICRModule::ProcessPDF(doc, &options);
140
141 // Save the result with hidden text applied
142 doc.Save(output_path + "icr-ignore.pdf", SDFDoc::e_linearized);
143 }
144 catch (Common::Exception& e)
145 {
146 cout << e << endl;
147 }
148 catch (...)
149 {
150 cout << "Unknown Exception" << endl;
151 }
152
153 //--------------------------------------------------------------------------------
154 // Example 4) The postprocessing workflow has also an option of extracting ICR results
155 // in JSON format, similar to the one used by the OCR Module
156 try
157 {
158 cout << "Example 4: extract & apply" << endl;
159
160 // Open the .pdf document
161 PDFDoc doc(input_path + "icr.pdf");
162
163 // Extract ICR results in JSON format
164 UString json = HandwritingICRModule::GetICRJsonFromPDF(doc);
165 WriteTextToFile(output_path + "icr-get.json", json);
166
167 // Insert your post-processing step (whatever it might be)
168 // ...
169
170 // Apply potentially modified ICR JSON to the PDF
171 HandwritingICRModule::ApplyICRJsonToPDF(doc, json);
172
173 // Save the result with hidden text applied
174 doc.Save(output_path + "icr-get-apply.pdf", SDFDoc::e_linearized);
175 }
176 catch (Common::Exception& e)
177 {
178 cout << e << endl;
179 }
180 catch (...)
181 {
182 cout << "Unknown Exception" << endl;
183 }
184
185 cout << "Done." << endl;
186
187 PDFNet::Terminate();
188 }
189 catch (Common::Exception& e)
190 {
191 cout << e << endl;
192 }
193 catch (...)
194 {
195 cout << "Unknown Exception" << endl;
196 }
197
198 return 0;
199}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import java.io.FileWriter;
7import java.io.BufferedWriter;
8import java.io.IOException;
9
10import com.pdftron.common.PDFNetException;
11import com.pdftron.pdf.*;
12import com.pdftron.sdf.SDFDoc;
13
14//---------------------------------------------------------------------------------------
15// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
16// handwriting from image-based pages and apply them as hidden text.
17//
18// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
19//---------------------------------------------------------------------------------------
20public class HandwritingICRTest {
21
22 static void writeTextToFile(String filename, String text) throws IOException
23 {
24 BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
25 writer.write(text);
26 writer.close();
27 }
28
29 public static void main(String[] args) {
30 try {
31 // The first step in every application using PDFNet is to initialize the
32 // library and set the path to common PDF resources. The library is usually
33 // initialized only once, but calling Initialize() multiple times is also fine.
34 PDFNet.initialize(PDFTronLicense.Key());
35
36 // The location of the Handwriting ICR Module
37 PDFNet.addResourceSearchPath("../../../Lib/");
38
39 // Test if the add-on is installed
40 if (!HandwritingICRModule.isModuleAvailable())
41 {
42 System.out.println("");
43 System.out.println("Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module");
44 System.out.println("not available.");
45 System.out.println("---------------------------------------------------------------");
46 System.out.println("The Handwriting ICR Module is an optional add-on, available for download");
47 System.out.println("at https://dev.apryse.com/. If you have already downloaded this");
48 System.out.println("module, ensure that the SDK is able to find the required files");
49 System.out.println("using the PDFNet.addResourceSearchPath() function.");
50 System.out.println("");
51 return;
52 }
53
54 // Relative path to the folder containing test files.
55 String input_path = "../../TestFiles/HandwritingICR/";
56 String output_path = "../../TestFiles/Output/";
57
58 //--------------------------------------------------------------------------------
59 // Example 1) Process a PDF without specifying options
60 System.out.println("Example 1: processing icr.pdf");
61
62 // Open the .pdf document
63 try (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
64 {
65 // Run ICR on the .pdf with the default options
66 HandwritingICRModule.processPDF(doc);
67
68 // Save the result with hidden text applied
69 doc.save(output_path + "icr-simple.pdf", SDFDoc.SaveMode.LINEARIZED, null);
70 doc.close();
71 } catch (PDFNetException e) {
72 e.printStackTrace();
73 }
74
75 //--------------------------------------------------------------------------------
76 // Example 2) Process a subset of PDF pages
77 System.out.println("Example 2: processing pages from icr.pdf");
78
79 // Open the .pdf document
80 try (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
81 {
82 // Process handwriting with custom options
83 HandwritingICROptions options = new HandwritingICROptions();
84
85 // Optionally, process a subset of pages
86 options.setPages("2-3");
87
88 // Run ICR on the .pdf
89 HandwritingICRModule.processPDF(doc, options);
90
91 // Save the result with hidden text applied
92 doc.save(output_path + "icr-pages.pdf", SDFDoc.SaveMode.LINEARIZED, null);
93 doc.close();
94 } catch (PDFNetException e) {
95 e.printStackTrace();
96 }
97
98 //--------------------------------------------------------------------------------
99 // Example 3) Ignore zones specified for each page
100 System.out.println("Example 3: processing & ignoring zones");
101
102 // Open the .pdf document
103 try (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
104 {
105 // Process handwriting with custom options
106 HandwritingICROptions options = new HandwritingICROptions();
107
108 // Process page 2 by ignoring the signature area on the bottom
109 options.setPages("2");
110 RectCollection ignore_zones_page2 = new RectCollection();
111 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
112 // Coordinates rotate with the page, if it has rotation applied.
113 ignore_zones_page2.addRect(78, 850.1 - 770, 340, 850.1 - 676);
114 options.addIgnoreZonesForPage(ignore_zones_page2, 2);
115
116 // Run ICR on the .pdf
117 HandwritingICRModule.processPDF(doc, options);
118
119 // Save the result with hidden text applied
120 doc.save(output_path + "icr-ignore.pdf", SDFDoc.SaveMode.LINEARIZED, null);
121 doc.close();
122 } catch (PDFNetException e) {
123 e.printStackTrace();
124 }
125
126 //--------------------------------------------------------------------------------
127 // Example 4) The postprocessing workflow has also an option of extracting ICR results
128 // in JSON format, similar to the one used by the OCR Module
129 System.out.println("Example 4: extract & apply");
130
131 // Open the .pdf document
132 try (PDFDoc doc = new PDFDoc(input_path + "icr.pdf"))
133 {
134 // Extract ICR results in JSON format
135 String json = HandwritingICRModule.getICRJsonFromPDF(doc);
136 writeTextToFile(output_path + "icr-get.json", json);
137
138 // Insert your post-processing step (whatever it might be)
139 // ...
140
141 // Apply potentially modified ICR JSON to the PDF
142 HandwritingICRModule.applyICRJsonToPDF(doc, json);
143
144 // Save the result with hidden text applied
145 doc.save(output_path + "icr-get-apply.pdf", SDFDoc.SaveMode.LINEARIZED, null);
146 doc.close();
147 } catch (PDFNetException e) {
148 e.printStackTrace();
149 }
150 catch (IOException e) {
151 System.out.println(e);
152 }
153 System.out.println("Done.");
154 PDFNet.terminate();
155 } catch (PDFNetException e) {
156 e.printStackTrace();
157 }
158 }
159}
1<?php
2//---------------------------------------------------------------------------------------
3// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
4// Consult LICENSE.txt regarding license information.
5//---------------------------------------------------------------------------------------
6if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
7include("../../../PDFNetC/Lib/PDFNetPHP.php");
8include("../../LicenseKey/PHP/LicenseKey.php");
9
10// Relative path to the folder containing the test files.
11$input_path = getcwd()."/../../TestFiles/HandwritingICR/";
12$output_path = getcwd()."/../../TestFiles/Output/";
13
14function WriteTextToFile($outputFile, $text)
15{
16 $outfile = fopen($outputFile, "w");
17 fwrite($outfile, $text);
18 fclose($outfile);
19}
20
21//---------------------------------------------------------------------------------------
22// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
23// handwriting from image-based pages and apply them as hidden text.
24//
25// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
26//---------------------------------------------------------------------------------------
27
28 // The first step in every application using PDFNet is to initialize the
29 // library and set the path to common PDF resources. The library is usually
30 // initialized only once, but calling Initialize() multiple times is also fine.
31 PDFNet::Initialize($LicenseKey);
32 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.
33
34 // The location of the Handwriting ICR Module
35 PDFNet::AddResourceSearchPath("../../../PDFNetC/Lib/");
36
37 // Test if the add-on is installed
38 if(!HandwritingICRModule::IsModuleAvailable()) {
39 echo "Unable to run HandwritingICRTest: PDFTron SDK Handwriting ICR Module\n
40 not available.\n
41 ---------------------------------------------------------------\n
42 The Handwriting ICR Module is an optional add-on, available for download\n
43 at https://dev.apryse.com/. If you have already downloaded this\n
44 module, ensure that the SDK is able to find the required files\n
45 using the PDFNet::AddResourceSearchPath() function.\n";
46 } else
47 {
48 //--------------------------------------------------------------------------------
49 // Example 1) Process a PDF without specifying options
50 echo "Example 1: processing icr.pdf\n";
51
52 // Open the .pdf document
53 $doc = new PDFDoc($input_path."icr.pdf");
54
55 // Run ICR on the .pdf with the default options
56 HandwritingICRModule::ProcessPDF($doc);
57
58 // Save the result with hidden text applied
59 $doc->Save($output_path."icr-simple.pdf", SDFDoc::e_linearized);
60 $doc->Close();
61
62 //--------------------------------------------------------------------------------
63 // Example 2) Process a subset of PDF pages
64 echo "Example 2: processing pages from icr.pdf\n";
65
66 // Open the .pdf document
67 $doc = new PDFDoc($input_path."icr.pdf");
68
69 // Process handwriting with custom options
70 $options = new HandwritingICROptions();
71
72 // Optionally, process a subset of pages
73 $options->SetPages("2-3");
74
75 // Run ICR on the .pdf
76 HandwritingICRModule::ProcessPDF($doc, $options);
77
78 // Save the result with hidden text applied
79 $doc->Save($output_path."icr-pages.pdf", SDFDoc::e_linearized);
80 $doc->Close();
81
82 //--------------------------------------------------------------------------------
83 // Example 3) Ignore zones specified for each page
84 echo "Example 3: processing & ignoring zones\n";
85
86 // Open the .pdf document
87 $doc = new PDFDoc($input_path."icr.pdf");
88
89 // Process handwriting with custom options
90 $options = new HandwritingICROptions();
91
92 // Process page 2 by ignoring the signature area on the bottom
93 $options->SetPages("2");
94 $ignore_zones_page2 = new RectCollection();
95 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
96 // Coordinates rotate with the page, if it has rotation applied.
97 $rect = new Rect(78.0, 850.1 - 770.0, 340.0, 850.1 - 676.0);
98 $ignore_zones_page2->AddRect($rect);
99 $options->AddIgnoreZonesForPage($ignore_zones_page2, 2);
100
101 // Run ICR on the .pdf
102 HandwritingICRModule::ProcessPDF($doc, $options);
103
104 // Save the result with hidden text applied
105 $doc->Save($output_path."icr-ignore.pdf", SDFDoc::e_linearized);
106 $doc->Close();
107
108 //--------------------------------------------------------------------------------
109 // Example 4) The postprocessing workflow has also an option of extracting ICR results
110 // in JSON format, similar to the one used by the OCR Module
111 echo "Example 4: extract & apply\n";
112
113 // Open the .pdf document
114 $doc = new PDFDoc($input_path."icr.pdf");
115
116 // Extract ICR results in JSON format
117 $json = HandwritingICRModule::GetICRJsonFromPDF($doc);
118 WriteTextToFile($output_path."icr-get.json", $json);
119
120 // Insert your post-processing step (whatever it might be)
121 // ...
122
123 // Apply potentially modified ICR JSON to the PDF
124 HandwritingICRModule::ApplyICRJsonToPDF($doc, $json);
125
126 // Save the result with hidden text applied
127 $doc->Save($output_path."icr-get-apply.pdf", SDFDoc::e_linearized);
128 $doc->Close();
129
130 echo "Done.\n";
131 }
132 PDFNet::Terminate();
133
134?>
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14# Relative path to the folder containing test files.
15input_path = "../../TestFiles/HandwritingICR/"
16output_path = "../../TestFiles/Output/"
17
18def WriteTextToFile(outputFile, text):
19 # Write the contents of text to the disk
20 f = open(outputFile, "w")
21 try:
22 f.write(text)
23 finally:
24 f.close()
25
26# ---------------------------------------------------------------------------------------
27# The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
28# handwriting from image-based pages and apply them as hidden text.
29#
30# The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
31# --------------------------------------------------------------------------------------
32
33def main():
34
35 # The first step in every application using PDFNet is to initialize the
36 # library and set the path to common PDF resources. The library is usually
37 # initialized only once, but calling Initialize() multiple times is also fine.
38 PDFNet.Initialize(LicenseKey)
39
40 # The location of the Handwriting ICR Module
41 PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")
42
43 # Test if the add-on is installed
44 if not HandwritingICRModule.IsModuleAvailable():
45
46 print("""
47 Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module
48 not available.
49 ---------------------------------------------------------------
50 The Handwriting ICR Module is an optional add-on, available for download
51 at https://dev.apryse.com/. If you have already downloaded this
52 module, ensure that the SDK is able to find the required files
53 using the PDFNet.AddResourceSearchPath() function.""")
54
55 else:
56
57 # --------------------------------------------------------------------------------
58 # Example 1) Process a PDF without specifying options
59 print("Example 1: processing icr.pdf")
60
61 # Open the .pdf document
62 doc = PDFDoc(input_path + "icr.pdf")
63
64 # Run ICR on the .pdf with the default options
65 HandwritingICRModule.ProcessPDF(doc)
66
67 # Save the result with hidden text applied
68 doc.Save(output_path + "icr-simple.pdf", SDFDoc.e_linearized)
69 doc.Close()
70
71 # --------------------------------------------------------------------------------
72 # Example 2) Process a subset of PDF pages
73 print("Example 2: processing pages from icr.pdf")
74
75 # Open the .pdf document
76 doc = PDFDoc(input_path + "icr.pdf")
77
78 # Process handwriting with custom options
79 options = HandwritingICROptions()
80
81 # Optionally, process a subset of pages
82 options.SetPages("2-3")
83
84 # Run ICR on the .pdf
85 HandwritingICRModule.ProcessPDF(doc, options)
86
87 # Save the result with hidden text applied
88 doc.Save(output_path + "icr-pages.pdf", SDFDoc.e_linearized)
89 doc.Close()
90
91 # --------------------------------------------------------------------------------
92 # Example 3) Ignore zones specified for each page
93 print("Example 3: processing & ignoring zones")
94
95 # Open the .pdf document
96 doc = PDFDoc(input_path + "icr.pdf")
97
98 # Process handwriting with custom options
99 options = HandwritingICROptions()
100
101 # Process page 2 by ignoring the signature area on the bottom
102 options.SetPages("2")
103 ignore_zones_page2 = RectCollection()
104 # These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
105 # Coordinates rotate with the page, if it has rotation applied.
106 ignore_zones_page2.AddRect(Rect(78, 850.1 - 770, 340, 850.1 - 676))
107 options.AddIgnoreZonesForPage(ignore_zones_page2, 2)
108
109 # Run ICR on the .pdf
110 HandwritingICRModule.ProcessPDF(doc, options)
111
112 # Save the result with hidden text applied
113 doc.Save(output_path + "icr-ignore.pdf", SDFDoc.e_linearized)
114 doc.Close()
115
116 # --------------------------------------------------------------------------------
117 # Example 4) The postprocessing workflow has also an option of extracting ICR results
118 # in JSON format, similar to the one used by the OCR Module
119 print("Example 4: extract & apply")
120
121 # Open the .pdf document
122 doc = PDFDoc(input_path + "icr.pdf")
123
124 # Extract ICR results in JSON format
125 json = HandwritingICRModule.GetICRJsonFromPDF(doc)
126 WriteTextToFile(output_path + "icr-get.json", json)
127
128 # Insert your post-processing step (whatever it might be)
129 # ...
130
131 # Apply potentially modified ICR JSON to the PDF
132 HandwritingICRModule.ApplyICRJsonToPDF(doc, json)
133
134 # Save the result with hidden text applied
135 doc.Save(output_path + "icr-get-apply.pdf", SDFDoc.e_linearized)
136 doc.Close()
137
138 print("Done.")
139
140 PDFNet.Terminate()
141
142
143if __name__ == '__main__':
144 main()
145
1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6require '../../../PDFNetC/Lib/PDFNetRuby'
7include PDFNetRuby
8require '../../LicenseKey/RUBY/LicenseKey'
9
10$stdout.sync = true
11
12# Relative path to the folder containing test files.
13$input_path = "../../TestFiles/HandwritingICR/"
14$output_path = "../../TestFiles/Output/"
15
16#---------------------------------------------------------------------------------------
17# The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
18# handwriting from image-based pages and apply them as hidden text.
19#
20# The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
21#---------------------------------------------------------------------------------------
22
23# The first step in every application using PDFNet is to initialize the
24# library and set the path to common PDF resources. The library is usually
25# initialized only once, but calling Initialize multiple times is also fine.
26PDFNet.Initialize(PDFTronLicense.Key)
27
28# The location of the Handwriting ICR Module
29PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/");
30
31begin
32
33 # Test if the add-on is installed
34 if !HandwritingICRModule.IsModuleAvailable
35 puts 'Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module'
36 puts 'not available.'
37 puts '---------------------------------------------------------------'
38 puts 'The Handwriting ICR Module is an optional add-on, available for download'
39 puts 'at https://dev.apryse.com/. If you have already downloaded this'
40 puts 'module, ensure that the SDK is able to find the required files'
41 puts 'using the PDFNet.AddResourceSearchPath() function.'
42
43 else
44
45 # --------------------------------------------------------------------------------
46 # Example 1) Process a PDF without specifying options
47 puts "Example 1: processing icr.pdf"
48
49 # Open the .pdf document
50 doc = PDFDoc.new($input_path + "icr.pdf")
51
52 # Run ICR on the .pdf with the default options
53 HandwritingICRModule.ProcessPDF(doc)
54
55 # Save the result with hidden text applied
56 doc.Save($output_path + "icr-simple.pdf", SDFDoc::E_linearized)
57 doc.Close
58
59 # --------------------------------------------------------------------------------
60 # Example 2) Process a subset of PDF pages
61 puts "Example 2: processing pages from icr.pdf"
62
63 # Open the .pdf document
64 doc = PDFDoc.new($input_path + "icr.pdf")
65
66 # Process handwriting with custom options
67 options = HandwritingICROptions.new
68
69 # Optionally, process a subset of pages
70 options.SetPages("2-3")
71
72 # Run ICR on the .pdf
73 HandwritingICRModule.ProcessPDF(doc, options)
74
75 # Save the result with hidden text applied
76 doc.Save($output_path + "icr-pages.pdf", SDFDoc::E_linearized)
77 doc.Close
78
79 # --------------------------------------------------------------------------------
80 # Example 3) Ignore zones specified for each page
81 puts "Example 3: processing & ignoring zones"
82
83 # Open the .pdf document
84 doc = PDFDoc.new($input_path + "icr.pdf")
85
86 # Process handwriting with custom options
87 options = HandwritingICROptions.new
88
89 # Process page 2 by ignoring the signature area on the bottom
90 options.SetPages("2")
91 ignore_zones_page2 = RectCollection.new
92 # These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
93 # Coordinates rotate with the page, if it has rotation applied.
94 ignore_zones_page2.AddRect(Rect.new(78, 850.1 - 770, 340, 850.1 - 676))
95 options.AddIgnoreZonesForPage(ignore_zones_page2, 2)
96
97 # Run ICR on the .pdf
98 HandwritingICRModule.ProcessPDF(doc, options)
99
100 # Save the result with hidden text applied
101 doc.Save($output_path + "icr-ignore.pdf", SDFDoc::E_linearized)
102 doc.Close
103
104 # --------------------------------------------------------------------------------
105 # Example 4) The postprocessing workflow has also an option of extracting ICR results
106 # in JSON format, similar to the one used by the OCR Module
107 puts "Example 4: extract & apply"
108
109 # Open the .pdf document
110 doc = PDFDoc.new($input_path + "icr.pdf")
111
112 # Extract ICR results in JSON format
113 json = HandwritingICRModule.GetICRJsonFromPDF(doc)
114 File.open($output_path + "icr-get.json", 'w') { |file| file.write(json) }
115
116 # Insert your post-processing step (whatever it might be)
117 # ...
118
119 # Apply potentially modified ICR JSON to the PDF
120 HandwritingICRModule.ApplyICRJsonToPDF(doc, json)
121
122 # Save the result with hidden text applied
123 doc.Save($output_path + "icr-get-apply.pdf", SDFDoc::E_linearized)
124 doc.Close
125
126 print("Done.")
127 end
128
129rescue => error
130 puts "Unable to extract handwriting, error: " + error.message
131end
132
133PDFNet.Terminate
1'---------------------------------------------------------------------------------------
2' Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3' Consult legal.txt regarding legal and license information.
4'---------------------------------------------------------------------------------------
5Imports System
6
7Imports pdftron
8Imports pdftron.Common
9Imports pdftron.SDF
10Imports pdftron.PDF
11
12' <summary>
13'---------------------------------------------------------------------------------------
14' The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
15' handwriting from image-based pages and apply them as hidden text.
16'
17' The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
18'---------------------------------------------------------------------------------------
19' </summary>
20Module HandwritingICRTestVB
21 Dim pdfNetLoader As PDFNetLoader
22 Sub New()
23 pdfNetLoader = pdftron.PDFNetLoader.Instance()
24 End Sub
25
26 ' The main entry point for the application.
27 Sub Main()
28
29 ' The first step in every application using PDFNet is to initialize the
30 ' library and set the path to common PDF resources. The library is usually
31 ' initialized only once, but calling Initialize() multiple times is also fine.
32 PDFNet.Initialize(PDFTronLicense.Key)
33
34 ' The location of the Handwriting ICR Module
35 PDFNet.AddResourceSearchPath("../../../../../Lib/")
36
37 ' Test if the add-on is installed
38 If Not HandwritingICRModule.IsModuleAvailable() Then
39 Console.WriteLine("")
40 Console.WriteLine("Unable to run HandwritingICRTest: Apryse SDK Handwriting ICR Module")
41 Console.WriteLine("not available.")
42 Console.WriteLine("---------------------------------------------------------------")
43 Console.WriteLine("The Handwriting ICR Module is an optional add-on, available for download")
44 Console.WriteLine("at https://dev.apryse.com/. If you have already downloaded this")
45 Console.WriteLine("module, ensure that the SDK is able to find the required files")
46 Console.WriteLine("using the PDFNet.AddResourceSearchPath() function.")
47 Console.WriteLine("")
48 Return
49 End If
50
51 ' Relative path to the folder containing test files.
52 Dim input_path As String = "../../../../TestFiles/HandwritingICR/"
53 Dim output_path As String = "../../../../TestFiles/Output/"
54
55 '--------------------------------------------------------------------------------
56 ' Example 1) Process a PDF without specifying options
57 Try
58 Console.WriteLine("Example 1: processing icr.pdf")
59
60 ' Open the .pdf document
61 Using doc As PDFDoc = New PDFDoc(input_path + "icr.pdf")
62 ' Run ICR on the .pdf with the default options
63 HandwritingICRModule.ProcessPDF(doc)
64
65 ' Save the result with hidden text applied
66 doc.Save(output_path + "icr-simple.pdf", SDFDoc.SaveOptions.e_linearized)
67 doc.Close()
68 End Using
69 Catch e As PDFNetException
70 Console.WriteLine(e.Message)
71 End Try
72
73 '--------------------------------------------------------------------------------
74 ' Example 2) Process a subset of PDF pages
75 Try
76 Console.WriteLine("Example 2: processing pages from icr.pdf")
77
78 ' Open the .pdf document
79 Using doc As PDFDoc = New PDFDoc(input_path + "icr.pdf")
80 ' Process handwriting with custom options
81 Dim options As New HandwritingICROptions()
82
83 ' Optionally, process a subset of pages
84 options.SetPages("2-3")
85
86 ' Run ICR on the .pdf
87 HandwritingICRModule.ProcessPDF(doc, options)
88
89 ' Save the result with hidden text applied
90 doc.Save(output_path + "icr-pages.pdf", SDFDoc.SaveOptions.e_linearized)
91 doc.Close()
92 End Using
93 Catch e As PDFNetException
94 Console.WriteLine(e.Message)
95 End Try
96
97 '--------------------------------------------------------------------------------
98 ' Example 3) Ignore zones specified for each page
99 Try
100 Console.WriteLine("Example 3: processing & ignoring zones")
101
102 ' Open the .pdf document
103 Using doc As PDFDoc = New PDFDoc(input_path + "icr.pdf")
104 ' Process handwriting with custom options
105 Dim options As New HandwritingICROptions()
106
107 ' Process page 2 by ignoring the signature area on the bottom
108 options.SetPages("2")
109 Dim ignore_zones_page2 As New RectCollection()
110 ' These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
111 ' Coordinates rotate with the page, if it has rotation applied.
112 ignore_zones_page2.AddRect(78, 850.1 - 770, 340, 850.1 - 676)
113 options.AddIgnoreZonesForPage(ignore_zones_page2, 2)
114
115 ' Run ICR on the .pdf
116 HandwritingICRModule.ProcessPDF(doc, options)
117
118 ' Save the result with hidden text applied
119 doc.Save(output_path + "icr-ignore.pdf", SDFDoc.SaveOptions.e_linearized)
120 doc.Close()
121 End Using
122 Catch e As PDFNetException
123 Console.WriteLine(e.Message)
124 End Try
125
126 '--------------------------------------------------------------------------------
127 ' Example 4) The postprocessing workflow has also an option of extracting ICR results
128 ' in JSON format, similar to the one used by the OCR Module
129 Try
130 Console.WriteLine("Example 4: extract & apply")
131
132 ' Open the .pdf document
133 Using doc As PDFDoc = New PDFDoc(input_path + "icr.pdf")
134 ' Extract ICR results in JSON format
135 Dim json As String = HandwritingICRModule.GetICRJsonFromPDF(doc)
136 System.IO.File.WriteAllText(output_path + "icr-get.json", json)
137
138 ' Insert your post-processing step (whatever it might be)
139 ' ...
140
141 ' Apply potentially modified ICR JSON to the PDF
142 HandwritingICRModule.ApplyICRJsonToPDF(doc, json)
143
144 ' Save the result with hidden text applied
145 doc.Save(output_path + "icr-ignore.pdf", SDFDoc.SaveOptions.e_linearized)
146 doc.Close()
147 End Using
148 Catch e As PDFNetException
149 Console.WriteLine(e.Message)
150 End Try
151
152 Console.WriteLine("Done.")
153 PDFNet.Terminate()
154 End Sub
155
156End Module
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2026 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#import <OBJC/PDFNetOBJC.h>
7#import <Foundation/Foundation.h>
8
9//---------------------------------------------------------------------------------------
10// The Handwriting ICR Module is an optional PDFNet add-on that can be used to extract
11// handwriting from image-based pages and apply them as hidden text.
12//
13// The Apryse SDK Handwriting ICR Module can be downloaded from https://dev.apryse.com/
14//---------------------------------------------------------------------------------------
15
16int main (int argc, const char * argv[])
17{
18 @autoreleasepool {
19
20 // The first step in every application using PDFNet is to initialize the
21 // library. The library is usually initialized only once, but calling
22 // Initialize() multiple times is also fine.
23 [PTPDFNet Initialize: 0];
24 // The location of the Handwriting ICR Module
25 [PTPDFNet AddResourceSearchPath:@"../../../Lib/"];
26
27 // Test if the add-on is installed
28 if (![PTHandwritingICRModule IsModuleAvailable]) {
29 NSLog(@"");
30 NSLog(@"Unable to run HandwritingICRTest: Apryse Handwriting ICR Module");
31 NSLog(@"not available.");
32 NSLog(@"---------------------------------------------------------------");
33 NSLog(@"The Handwriting ICR Module is an optional add-on, available for download");
34 NSLog(@"at https://docs.apryse.com/documentation/core/info/modules/. If you have already");
35 NSLog(@"downloaded this module, ensure that the SDK is able to find the required files");
36 NSLog(@"using the [PDFNet AddResourceSearchPath:] function.");
37 NSLog(@"");
38
39 return 1;
40 }
41
42 NSString *inputPath = @"../../TestFiles/HandwritingICR/";
43 NSString *outputPath = @"../../TestFiles/Output/";
44
45 int ret = 0;
46
47 //--------------------------------------------------------------------------------
48 // Example 1) Process a PDF without specifying options
49 @try {
50 NSLog(@"Example 1: processing icr.pdf");
51
52 // Open the .pdf document
53 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: [inputPath stringByAppendingString:@"icr.pdf"]];
54
55 // Run ICR on the .pdf with the default options
56 [PTHandwritingICRModule ProcessPDF: doc options: nil];
57
58 // Save the result with hidden text applied
59 [doc SaveToFile: [outputPath stringByAppendingString: @"icr-simple.pdf"] flags: e_ptlinearized];
60 [doc Close];
61 }
62 @catch (NSException *e) {
63 NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
64 ret = 1;
65 }
66
67 //--------------------------------------------------------------------------------
68 // Example 2) Process a subset of PDF pages
69 @try {
70 NSLog(@"Example 2: processing pages from icr.pdf");
71
72 // Open the .pdf document
73 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: [inputPath stringByAppendingString:@"icr.pdf"]];
74
75 // Process handwriting with custom options
76 PTHandwritingICROptions* options = [[PTHandwritingICROptions alloc] init];
77
78 // Optionally, process a subset of pages
79 [options SetPages: @"2-3"];
80
81 // Run ICR on the .pdf
82 [PTHandwritingICRModule ProcessPDF: doc options: options];
83
84 // Save the result with hidden text applied
85 [doc SaveToFile: [outputPath stringByAppendingString: @"icr-pages.pdf"] flags: e_ptlinearized];
86 [doc Close];
87 }
88 @catch (NSException *e) {
89 NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
90 ret = 1;
91 }
92
93 //--------------------------------------------------------------------------------
94 // Example 3) Ignore zones specified for each page
95 @try {
96 NSLog(@"Example 3: processing & ignoring zones");
97
98 // Open the .pdf document
99 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: [inputPath stringByAppendingString:@"icr.pdf"]];
100
101 // Process handwriting with custom options
102 PTHandwritingICROptions* options = [[PTHandwritingICROptions alloc] init];
103
104 // Process page 2 by ignoring the signature area on the bottom
105 [options SetPages: @"2"];
106 PTPDFRectCollection* ignore_zones_page2 = [[PTPDFRectCollection alloc] init];
107 // These coordinates are in PDF user space, with the origin at the bottom left corner of the page.
108 // Coordinates rotate with the page, if it has rotation applied.
109 [ignore_zones_page2 AddRect: [[PTPDFRect alloc] initWithX1: 78 y1: 850.1 - 770 x2: 340 y2: 850.1 - 676]];
110 [options AddIgnoreZonesForPage: ignore_zones_page2 page_num: 2];
111
112 // Run ICR on the .pdf
113 [PTHandwritingICRModule ProcessPDF: doc options: options];
114
115 // Save the result with hidden text applied
116 [doc SaveToFile: [outputPath stringByAppendingString: @"icr-ignore.pdf"] flags: e_ptlinearized];
117 [doc Close];
118 }
119 @catch (NSException *e) {
120 NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
121 ret = 1;
122 }
123
124 //--------------------------------------------------------------------------------
125 // Example 4) The postprocessing workflow has also an option of extracting ICR results
126 // in JSON format, similar to the one used by the OCR Module
127 @try {
128 NSLog(@"Example 4: extract & apply");
129
130 // Open the .pdf document
131 PTPDFDoc *doc = [[PTPDFDoc alloc] initWithFilepath: [inputPath stringByAppendingString:@"icr.pdf"]];
132
133 // Extract ICR results in JSON format
134 NSString *json = [PTHandwritingICRModule GetICRJsonFromPDF: doc options: nil];
135 [json writeToFile: [outputPath stringByAppendingString: @"icr-get.json"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
136
137 // Insert your post-processing step (whatever it might be)
138 // ...
139
140 // Apply potentially modified ICR JSON to the PDF
141 [PTHandwritingICRModule ApplyICRJsonToPDF: doc json: json];
142
143 // Save the result with hidden text applied
144 [doc SaveToFile: [outputPath stringByAppendingString: @"icr-get-apply.pdf"] flags: e_ptlinearized];
145 [doc Close];
146 }
147 @catch (NSException *e) {
148 NSLog(@"Exception: %@ - %@\n", e.name, e.reason);
149 ret = 1;
150 }
151
152 NSLog(@"Done.");
153 [PTPDFNet Terminate: 0];
154 return ret;
155 }
156}
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales