Aquaforest SDK
Code Samples
There are a number of samples included with the Aquaforest SDK.
Below are some simple samples showing some of the capabilities of the Aquaforest SDK.
Most samples make use of a HELPER file for the license key of the form:
public class Helper
{
public static readonly string LICENSE_KEY ="";
}
Trial sample keys are provided with the download.
- PDF/OCR/Data Extraction
- Data Extraction
- Standard OCR
- Extended OCR
- Cloud OCR
- Barcode Reader
- PDF Toolkit
using System;
using System.Collections.Generic;
using Aquaforest.DataExtractor.Api;
using Aquaforest.ExtendedOCR.Api;
using Aquaforest.PDF;
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
using System.IO;
///
/// This sample demonstrates how to use a combination of the SDK modules to solve a common use case of getting data from a mix of PDF documents.
/// This program will first check if the source PDF documents are text searchable, using the PDF Toolkit module.
/// It will OCR the documents if they are image-only or partically searchable, using the Extended OCR module.
/// Finally, the fully-searchable documents will have values for the 'invoice date' and 'invoice number' extracted, using the Data Extractor module.
/// Note: The source folder used in this sample does not exist in the base version of the SDK and must be created manually
///
namespace Aquaforest_SDK_Sample
{
class Program
{
private static IAquaforestLogger logger;
private static readonly HashSet pdfOperators = new HashSet(StringComparer.OrdinalIgnoreCase);
static void Main(string[] args)
{
Initialize();
DirectoryInfo directory = new DirectoryInfo(@"C:\Aquaforest\Aquaforest SDK\DataExtractor\samples\documents\source\test invoices");
// Iterated through each PDF file in the source directory
foreach (var file in directory.GetFiles("*.pdf", SearchOption.AllDirectories))
{
logger.LogInformation("Processing: " + file.FullName);
PDFDocument pdfDocument = new PDFDocument(file.FullName, logger);
// Checks if the PDF is searchable
if (IsPDFAlreadySearchable(pdfDocument))
{
// Attempts to extract data from the text-searchable file
ExtractData(file.FullName);
}
else
{
pdfDocument.Close();
string ocredFile = Path.Combine(@"C:\Aquaforest\Aquaforest SDK\DataExtractor\samples\documents\output", file.Name);
// If the PDF is not fully-searchable, the program will attempt to OCR the document
if (OcrPdf(file.FullName, ocredFile))
{
pdfDocument = new PDFDocument(ocredFile);
// Attempts to extract data from the new text-searchable file
ExtractData(ocredFile);
}
}
pdfDocument.Close();
logger.LogInformation(Environment.NewLine);
}
Console.WriteLine("Press any key");
Console.ReadKey();
}
private static void Initialize()
{
// Set the PDF Toolkit license
PDFToolkit.LicenseKey = Helper.LICENSE_KEY;
// Set the logger to output any warning messages
logger = new SimpleConsoleLogger(AquaforestLogLevel.Warning);
pdfOperators.Add("Tj");
}
private static bool IsPDFAlreadySearchable(PDFDocument pdfDocument)
{
int numberOfPages = pdfDocument.NumberOfPages;
PDFSearchabilityChecker searchabilityChecker = new PDFSearchabilityChecker(pdfDocument, pdfOperators, numberOfPages, logger);
// Check if PDF has already been OCRed by one of the Aquaforest OCR engines
if (searchabilityChecker.AlreadyOcredByAquaforest())
{
return true;
}
// Checks searchablility, only returning true if the document is fully searchable
switch (searchabilityChecker.SearchabilityStatus)
{
case "searchable": // All pages of the document contains text
logger.LogInformation("PDF is searchable");
return true;
case "imageonly": // All pages of the document are image only
logger.LogInformation("PDF is image-only");
return false;
case "partiallysearchable": //Mix of image and text pages
logger.LogInformation("PDF is partially searchable");
return false;
}
return false;
}
private static bool OcrPdf(string sourceFile, string outputFile)
{
try
{
logger.LogInformation("OCRing file");
string binFolder = @"C:\Aquaforest\Aquaforest SDK\OCR\Extended\bin";
string resourceFolder = Path.Combine(binFolder, "resources");
Helper.SetEnvironmentVariables(binFolder);
ExtendedOcrEngine.SetupOcr(Helper.LICENSE_KEY, resourceFolder);
using (Ocr ocr = new Ocr(logger))
{
// Set OCR options
ocr.Language = SupportedLanguages.English;
ocr.EnablePdfOutput = true;
// Set PreProcessor options
PreProcessor preProcessor = new PreProcessor();
preProcessor.Deskew = true;
// Read source PDF file
ocr.ReadPDFSource(sourceFile);
// Perform OCR recognition
if (ocr.Recognize(preProcessor))
{
// Save output as searchable PDF
ocr.SavePDFOutput(outputFile, true);
}
ocr.DeleteTemporaryFiles();
}
return true;
}
catch (Exception e)
{
logger.LogError("Failed to OCR PDF: " + sourceFile);
logger.LogError(e.Message);
return false;
}
finally
{
ExtendedOcrEngine.UnloadOcr();
}
}
private static void ExtractData(string pdfDocument)
{
string resourcePath = @"C:\Aquaforest\Aquaforest SDK\DataExtractor\bin";
using (RecognitionEngine re = new RecognitionEngine(Helper.LICENSE_KEY, resourcePath, logger))
{
// Add ad-hoc synonyms
re.Settings.ExpectedKeys.Add("Invoice no.", "Invoice Number");
re.Settings.ExpectedKeys.Add("Inv Date", new List() { "Invoice Date", "Date" });
// Read the file
re.ReadPdf(pdfDocument);
// Recognise the contents of the file
if (re.Recognize())
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"With ad-hoc synonyms");
Console.WriteLine($"The invoice number is {re.GetExpectedKeyValue("Invoice no.")}");
Console.WriteLine($"The invoice date is {re.GetExpectedKeyValue("Inv Date")}");
Console.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
}
}
}
}
}
With ad-hoc synonyms The invoice number is A15468 The invoice date is 2012-06-11 With ad-hoc synonyms The invoice number is 2012345 The invoice date is 12/19/2016 Press any key
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
using Aquaforest.DataExtractor.Api;
using System;
using System.IO;
///
/// This program sets expected keys, such as invoice number and invoice date, in the recognition engine.
/// The program then processes a sample invoice, retrieving the values for each expected key from the document.
///
namespace Recognition
{
class Program
{
static void Main(string[] args)
{
string resourcesFolder = Path.GetFullPath(@"..\..\..\..\..\..\bin");
string sourcePath = Path.GetFullPath(@"..\..\..\..\..\documents\source\invoices");
string filename = "invoice2.pdf";
// Create a console logger for output
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Information);
ProcessFile(Path.Combine(sourcePath, filename), resourcesFolder, logger);
Console.WriteLine("Press any key");
Console.ReadKey();
}
///
/// Recognise expected keys in the file and display them on the console
///
/// Full file path to the file to be processed
/// Recognition Engine's resource file path
public static void ProcessFile(string filePath, string resourcePath, IAquaforestLogger logger = null)
{
Console.WriteLine($"File: {filePath}");
using (RecognitionEngine re = new RecognitionEngine(Helper.LICENSE_KEY, resourcePath, logger))
{
// Add expected keys
re.Settings.ExpectedKeys.Add("Invoice Number");
re.Settings.ExpectedKeys.Add("Invoice Date");
re.Settings.ExpectedKeys.Add("City/State/Zip");
// Read the file
re.ReadPdf(filePath);
// Recognise the contents of the file
if (re.Recognize())
{
// Get the expected key values
logger.LogInformation($"The invoice number is {re.GetExpectedKeyValue("Invoice Number")}");
logger.LogInformation($"The invoice date is {re.GetExpectedKeyValue("Invoice Date")}");
logger.LogInformation($"The City/State/Zip is {re.GetExpectedKeyValue("City/State/Zip")}");
}
}
}
}
}
File: C:\Aquaforest\Aquaforest SDK\DataExtractor\samples\documents\source\invoices\invoice2.pdf Total number of pages: 1 The invoice number is A12345678-1 The invoice date is 2018-06-11 The City/State/Zip is NY 10065 Press any key
using System;
using System.IO;
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
using Aquaforest.OCR.Api;
using Aquaforest.OCR.Definitions;
///
/// OCR and get text from page
/// Change the commented code to choose between TIFF and PDF files
/// Note: This example will only get text from image-only PDF pages. If a page already had text in it prior to the OCR, that text won't be retrieved.
/// To extract text from image-only, partially searchable and fully searchable documents, see the "CheckSearchabilityBeforeOCR" sample
///
namespace GetTextFromPage
{
/*
Note: This example will only get text from image-only pages. If a page already had text in it prior to the OCR, that text won't be retrieved.
To extract text from image-only, partially searchable and fully searchable documents, see the "CheckSearchabilityBeforeOCR" sample
*/
class Program
{
private static Ocr ocr;
static void Main(string[] args)
{
try
{
// Get the resource folder
string resourceFolder = Path.GetFullPath(@"..\..\..\..\..\..\bin\");
// Add to the Path Environment variable
string currentEnvironmentVariables = Environment.GetEnvironmentVariable("PATH");
if (!currentEnvironmentVariables.Contains(resourceFolder))
{
Environment.SetEnvironmentVariable("PATH", currentEnvironmentVariables + ";" + resourceFolder);
}
// Create a console logger for output
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Information);
// Create OCR object
using (ocr = new Ocr(Helper.LICENSE_KEY, resourceFolder, logger))
{
// Set OCR options
ocr.EnablePdfOutput = true;
ocr.Language = SupportedLanguages.English;
ocr.StatusUpdate += new Ocr.StatusUpdateEventHandler(OcrStatusUpdate);
// Set PreProcessor options
PreProcessor preProcessor = new PreProcessor();
preProcessor.Deskew = true;
preProcessor.Autorotate = false;
// Read source TIFF file
ocr.ReadTIFFSource(Path.GetFullPath(@"..\..\..\..\..\documents\source\sample.tif"));
// Read source PDF file
// ocr.ReadPDFSource(Path.GetFullPath(@"..\..\..\..\..\documents\source\image_pdf.pdf"));
// Perform OCR recognition
ocr.Recognize(preProcessor);
ocr.DeleteTemporaryFiles();
}
}
catch (Exception e)
{
Console.WriteLine("Error in OCR Processing :" + e.Message);
}
Console.WriteLine("Press any key");
Console.ReadKey();
}
private static void OcrStatusUpdate(object sender, StatusUpdateEventArgs pageCompletedEventArgs)
{
Console.WriteLine("Page {0}:", pageCompletedEventArgs.PageNumber);
if (pageCompletedEventArgs.TextAvailable)
{
Console.WriteLine(ocr.ReadPageString(pageCompletedEventArgs.PageNumber));
}
else
{
Console.WriteLine("No text found");
}
}
}
}
Page 1: (12) United States Patent Gutterman IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII US006409467B1 (10) Patent No.: US 6,409,467 E1 (45) Date of Patent: Jun. 25, 2002 (54) WIND-GENERATED POWER SYSTEM (76) Inventor: Howard Gntterman, P.O. Box 230881 Ansonia Station, New York, NY (US) 10023 4,739,179 A 5,038,049 A 5,134,305 A 5,272,378 A 5,386,146 A 5,734,202 A 4/1988 8/1991 7/1992 12/1993 1/1995 3/1998 Stites Kato Senehi Wither Hickey .. Shuler ... ... cut full output due to size ... Page 6: US 6,409,467 B1 upon leaving said wind-collecting duct, each of said wind-collecting ducts being generally sinusoidal- shaped having a wind intake portion being disposed in said subway system tunnel, and further having a wind outlet portion being disposed upon the wall and support structure; shrouds being mounted to the wall and support structure and being connected to said wind-collecting ducts, each of said shrouds including a front wall and a bottom wall, and also including a hole being disposed through said front wall and an opening being disposed through said bottom wall, said funnels being disposed upon said holes in said front walls of said shrouds, said shrouds being disposed upon the wall and support structure with said openings in said bottom walls being disposed upon the wall and support structure; and turbine generators being mounted in said shrouds and being adapted to transform wind to electrical power, said wind turbine generators including support members and turbine members which are securely mounted upon said support members and which are disposed in said shrouds to electively rotate upon the wind being accelerated into said shrouds through said funnels. 2. A wind-generated power system comprising: a subway system tunnel having a wall and support structure with wind being generated by subway trains passing or traveling at high rates of speed therethrough; wind-collecting ducts being spaced throughout said subway system tunnel and being attached to the wall and support structure; shrouds being mounted to the wall and support structure and being connected to said wind-collecting ducts; and turbine generators being mounted in said shrouds and being adapted to transform wind to electrical power. 5 10 15 20 25 30 3. A wind-generated power system as described in claim 2, wherein each of said wind-collecting ducts includes a wind intake opening and a wind outlet opening, and also includes a venturi disposed near said wind outlet opening to accelerate the wind being collected through said wind intake opening. 4. A wind-generated power system as described in claim 3, wherein each said venturi is generally a funnel having a constricted passageway through which the wind is accelerated upon leaving said wind-collecting duct. 5. A wind-generated power system as described in claim 4, wherein each of said wind-collecting ducts is generally sinusoidal-shaped having a wind intake portion being disposed in said subway system tunnel, and further having a wind outlet portion being disposed upon the wall and support structure. 6. A wind-generated power system as described in claim 4, wherein each of said shrouds includes a front wall and a bottom wall, and also includes a hole being disposed through said front wall and an opening being disposed through said bottom wall, said funnels being disposed upon said holes in said front walls of said shrouds, said shrouds being disposed upon the wall and support structure of the subway system tunnel with said openings in said bottom walls being disposed upon the wall and support structure. 7. A wind-generated power system as described in claim 6, wherein said wind turbine generators include support members and turbine members which are securely mounted upon said support members and which are disposed in said shrouds to electively rotate upon the wind being accelerated into said shrouds through said funnels. OCR page 6 complete. Press any key
using Aquaforest.ExtendedOCR.Api;
using Aquaforest.ExtendedOCR.Shared;
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
using System;
using System.IO;
///
/// This sample demonstrates how to get the text from an image or image PDF using OCR.
///
/// Note: This example will only get text from image-only pages. If a page already had text in it prior to the OCR, that text won’t be retrieved.
///
namespace GetTextFromPage
{
internal class Program
{
private static Ocr ocr;
private static void Main(string[] args)
{
try
{
string resourceFolder = Path.GetFullPath(@"..\..\..\..\..\..\bin\resources");
// Loads the extended OCR module with the license key
ExtendedOcrEngine.SetupOcr(Helper.LICENSE_KEY, resourceFolder);
// Create a console logger for output
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Information);
using (ocr = new Ocr(logger))
{
// Set OCR options
ocr.Language = SupportedLanguages.English;
ocr.StatusUpdate += OcrStatusUpdate;
// Set PreProcessor options
PreProcessor preProcessor = new PreProcessor();
preProcessor.Deskew = true;
preProcessor.Autorotate = false;
// Read source TIFF file
ocr.ReadTIFFSource(Path.GetFullPath(@"..\..\..\..\..\documents\source\sample.tif"));
// Read source PDF file
// ocr.ReadPDFSource(Path.GetFullPath(@"..\..\..\..\..\documents\source\image_pdf.pdf"));
// Perform OCR recognition
ocr.Recognize(preProcessor);
ocr.DeleteTemporaryFiles();
}
}
catch (Exception e)
{
Console.WriteLine("Error in OCR Processing :" + e.Message);
}
finally
{
if (ocr != null) ocr.Dispose();
ExtendedOcrEngine.UnloadOcr();
}
Console.WriteLine("Press any key");
Console.ReadKey();
}
private static void OcrStatusUpdate(object sender, StatusUpdateEventArgs pageCompletedEventArgs)
{
Console.WriteLine("Page {0}:", pageCompletedEventArgs.PageNumber);
if (pageCompletedEventArgs.TextAvailable)
{
Console.WriteLine(ocr.ReadPageString(pageCompletedEventArgs.PageNumber));
}
else
{
Console.WriteLine("No text found");
}
}
}
}
Start time: Monday, 26 October 2020, 13:37:06 PM Loading C:\Aquaforest\Aquaforest SDK\OCR\Extended\samples\documents\source\sample.tif (6) pages... Processing Page 1 Page 1: I 1111111111111111 11111 111111111111111 1111111111 lllll 111111111111111 11111111 US006409467Bl (12) United States Patent Gutterman (10) Patent No.: (45) Date of Patent: US 6,409,467 B1 Jun.25,2002 (54) WIND-GENERATED POWER SYSTEM (76) Inventor: Howard Gutterman, P.O. Box 230881 Ansonia Station, New York, NY (US) 10023 4,739,179 A 4/1988 5,038,049 A 8/1991 5,134,305 A 7/1992 5,272,378 A 12/1993 5,386,146 A * 1/1995 5,734,202 A 3/1998 Stites Kato Senehi Wither 290/1 R Hickey 290/1 R X Shuler 290/1 R X () Notice: Subject to any disclaimer, the term of this patent is extended or adjusted under 35 U.S.C. 154(b) by O days. * cited by examiner Primary Examiner-John E. Ryznic (21) Appl. No.: 09/802,574 (57) ABSTRACT (22) (51) (52) (58) (56) Filed: Mar. 9, 2001 Int. CI.'............................ F03D 1/00; H02P 9/04 U.S. Cl. 415/4.3; 290/1 R Field of Search 290/1 R; 415/4.1, 415/4.2, 4.3, 4.4, 4.5 References Cited U.S. PATENT DOCUMENTS 2,616,506 A 11/1952 Mathias 415/4.5 X 3,720,840 A * 3/1973 Gregg 415/4.3 X 3,876,925 A * 4/1975 Stoeckert................. 415/4.4 X 3,883,750 A * 5/1975 Uzzell, Jr. 415/4.5 X 4,012,163 A 3/1977 Baumgartner et al. 4,516,907 A * 5/1985 Edwards 415/4.5 A wind-generated power system for producing supplemental electrical power from wind-producing resource. The wind- generated power system includes a subway system tunnel having a wall and support structure with wind being gener- ated by subway trains passing or traveling at high rates of speed therethrough; and also includes wind-collecting ducts being spaced throughout the subway system tunnel and being attached to the wall and support structure; and further includes shrouds being mounted to the wall and support structure and being connected to the wind-collecting ducts; and also includes turbine generators being mounted in the shrouds and being adapted to transform wind to electrical power. ... cut full output due to size ... Processing Page 6 Page 6: US 6,409,467 Bl 5 6 k k k k k 3. A wind-generated power system as described in claim 2, wherein each of said wind-collecting ducts includes a wind intake opening and a wind outlet opening, and also includes a venturi disposed near said wind outlet opening to 5 accelerate the wind being collected through said wind intake opening. 4. A wind-generated power system as described in claim 3, wherein each said venturi is generally a funnel having a constricted passageway through which the wind is acceler- ated upon leaving said wind-collecting duct. 5. A wind-generated power system as described in claim 4, wherein each of said wind-collecting ducts is generally sinusoidal-shaped having a wind intake portion being dis- posed in said subway system tunnel, and further having a wind outlet portion being disposed upon the wall and support structure. 6. A wind-generated power system as described in claim 4, wherein each of said shrouds includes a front wall and a bottom wall, and also includes a hole being disposed through said front wall and an opening being disposed through said bottom wall, said funnels being disposed upon said holes in said front walls of said shrouds, said shrouds being disposed 2s upon the wall and support structure of the subway system tunnel with said openings in said bottom walls being dis- posed upon the wall and support structure. 7. A wind-generated power system as described in claim 6, wherein said wind turbine generators include support 30 members and turbine members which are securely mounted upon said support members and which are disposed in said shrouds to effectively rotate upon the wind being accelerated into said shrouds through said funnels. turbine generators being mounted in said shrouds and being adapted to transform wind to electrical power, said wind turbine generators including support mem- bers and turbine members which are securely mounted " upon said support members and which are disposed in said shrouds to effectively rotate upon the wind being accelerated into said shrouds through said funnels. 2. A wind-generated power system comprising: a subway system tunnel having a wall and support struc- ture with wind being generated by subway trains pass- ing or traveling at high rates of speed therethrough; wind-collecting ducts being spaced throughout said sub- way system tunnel and being attached to the wall and support structure; shrouds being mounted to the wall and support structure and being connected to said wind-collecting ducts; and turbine generators being mounted in said shrouds and being adapted to transform wind to electrical power. upon leaving said wind-collecting duct, each of said wind-collecting ducts being generally sinusoidal- shaped having a wind intake portion being disposed in said subway system tunnel, and further having a wind outlet portion being disposed upon the wall and support structure; shrouds being mounted to the wall and support structure and being connected to said wind-collecting ducts, each of said shrouds including a front wall and a bottom wall, and also including a hole being disposed through 10 said front wall and an opening being disposed through said bottom wall, said funnels being disposed upon said holes in said front walls of said shrouds, said shrouds being disposed upon the wall and support structure with said openings in said bottom walls being disposed upon 15 the wall and support structure; and End time: Monday, 26 October 2020, 13:37:10 PM Total elapsed time: 0m 03s 803m Press any key
using System;
using System.IO;
using Aquaforest.CloudOCR.Api;
using Aquaforest.CloudOCR.Shared;
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
///
/// OCR and get text from page using Cloud
/// Change the commented code to choose between TIFF and PDF files
/// Note: This example will only get text from image-only PDF pages. If a page already had text in it prior to the OCR, that text won't be retrieved.
/// To extract text from image-only, partially searchable and fully searchable documents, see the "CheckSearchabilityBeforeOCR" sample
///
namespace GetTextFromPage
{
class Program
{
static CloudOcr ocr;
static void Main(string[] args)
{
try
{
// Initialise variables for CloudOCR constructor
string licenseKey = Helper.LICENSE_KEY;
string resourceFolder = Path.GetFullPath(@"..\bin\");
// Create a console logger for output
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Information);
using (ocr = new CloudOcr(licenseKey, resourceFolder, logger))
{
string currentEnvironmentVariables = Environment.GetEnvironmentVariable("PATH");
if (!currentEnvironmentVariables.Contains(resourceFolder))
{
Environment.SetEnvironmentVariable("PATH", currentEnvironmentVariables + ";" + resourceFolder);
}
// Set OCR options
ocr.EnablePdfOutput = true;
ocr.EnableTextOutput = true;
ocr.StatusUpdate += OcrStatusUpdate;
/* Needed to use Microsoft Cloud
* 1) Microsoft Azure account, you can sign up for this using the following link: https://signup.azure.com/signup?offer=MS-AZR-0044P
* 2) Microsoft Computer Vision API endpoint, you can add this to the azure account you created using the following link: https://azure.microsoft.com/en-us/try/cognitive-services/?api=computer-vision
*/
//Set Microsoft Cloud Engine settings
MicrosoftCloudOCR engine = new MicrosoftCloudOCR(Helper.MICROSOFT_ENDPOINT, Helper.MICROSOFT_LICENSE_KEY);
engine.Language = MicrosoftLanguage.AutoDetect;
engine.TextRecognitionMode = TextRecognitionMode.Printed;
ocr.SetOcrEngine(engine);
/* Needed to use Google Cloud
* 1) Google account, you can sign up for one using the following link: https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp
* 2) Subscription key for the Google Cloud Platform . You can start your free trial using the following link: https://console.cloud.google.com/freetrial/signup/tos?pli=1
* - register for the trial and download your subscription key as a JSON file
* - use the location of this file when instantiating a GoogleCloudOCR instance
*/
//Alternatively, Set Google Cloud Engine settings
//GoogleCloudOCR engine = new GoogleCloudOCR(Helper.GOOGLE_KEYFILE_PATH);
//ocr.SetOcrEngine(engine);
// Set PreProcessor options
PreProcessor preProcessor = new PreProcessor();
preProcessor.Deskew = true;
preProcessor.Autorotate = false;
// Read source TIFF file
ocr.ReadTIFFSource(Path.GetFullPath(@"..\samples\documents\source\PL226938B1_PL.tif"));
// Read source PDF file
//ocr.ReadPDFSource(Path.GetFullPath(@"..\samples\documents\source\image_pdf.pdf"));
// Perform OCR recognition
ocr.Recognize(preProcessor);
ocr.DeleteTemporaryFiles();
}
}
catch (Exception e)
{
Console.WriteLine("Error in OCR Processing :" + e.Message);
}
finally
{
if (ocr != null) ocr.Dispose();
}
Console.WriteLine("Press any key");
Console.ReadKey();
}
static void OcrStatusUpdate(object sender, PageCompletedArgs pageCompletedEventArgs)
{
Console.WriteLine("Page {0}:", pageCompletedEventArgs.PageNumber);
if (pageCompletedEventArgs.TextAvailable)
{
Console.WriteLine(ocr.ReadPageString(pageCompletedEventArgs.PageNumber));
}
else
{
Console.WriteLine("No text found");
}
}
}
}
Microsoft: Start time: Monday, 26 October 2020, 13:25:29 PM Loading C:\Aquaforest\Aquaforest SDK\OCR\Cloud\samples\documents\source\PL226938B1_PL.tif (1) pages... Processing Page 1 Page 1: Cienkowarstwowa masa tynkarska z perlitem Abstract Wynalazek dotyczy cienkowarstwowej masy tynkarskiej z perlitem, zawierajacej 5-15% wagowych perlitu ekspandowanego o uziarnieniu do 4 mm. Co najmniej 5% wagowych, korzystnie 15-85% wagowych perlitu ekspandowanego stanowi granulat uzyskany z odpadowego pylu perlitowego poprzez polaczenie w warunkach ciaglego mieszania pylu perlitowego o uziarnieniu ponizej e, 5 mm z lepiszczem w postaci wodnej dyspersji polimerowej. Stosuje sie 50-150 czesci wagowych lepiszcza na lee czesci wagowych pylu. poczatkowym etapie procesu stosuje sie obroty bebna 1-20 obr/min, a nastepnie, w czasie 3-15 minut zwieksza sie je do 50-10 obr/min i jednoczesnie podgrzewa radiacyjnie mase w calej objetosci promieniowaniem podczerwonym do temperatury nie wyzszej niz 80 oc. Mieszanie kontynuuje sie przez 5-3e minut, po czym mase suszy konwekcyjnie strumieniem powietrza przez okres 60-180 minut utrzymujac temperature nawiewu na poziomie 40-800 C, az do uzyskania kulistych granul o wielkosci e, 5-1,5 mm i zawartosci wilgoci ponizej 1,5% wagowego, w ilosci co najmniej wagowych uzytego pylu perlitowego. End time: Monday, 26 October 2020, 13:25:38 PM Total elapsed time: 0m 08s 460ms Press any key Google: Start time: Monday, 26 October 2020, 13:27:08 PM Loading C:\Aquaforest\Aquaforest SDK\OCR\Cloud\samples\documents\source\PL226938B1_PL.tif (1) pages... Processing Page 1 Page 1: Cienkowarstwowa masa tynkarska z perlitem Abstract Wynalazek dotyczy cienkowarstwowej masy tynkarskiej z perlitem, zawierajacej 5-15% wagowych perlitu ekspandowanego o uziarnieniu do 4 mm. co najmniej 5% wagowych, korzystnie 15-85% wagowych perlitu ekspandowanego stanowi granulat uzyskany z odpadowego pylu perlitowego poprzez polaczenie w warunkach ciaglego mieszania pylu perlitowego o uziarnieniu ponizej 0,5 mm z lepiszczem w postaci wodnej dyspersji polimerowej. Stosuje sie 50-150 czesci wagowych lepiszcza na 100 czesci wagowych pylu. W poczatkowym etapie procesu stosuje sie obroty bebna 1-20 obr/min, a nastepnie, w czasie 3-15 minut zwieksza sie je do 50-100 obr/min i jednoczesnie podgrzewa radiacyjnie mase w calej objetosci promieniowaniem podczerwonym do temperatury nie wyzszej niz 80°C. Mieszanie kontynuuje sie przez 5-30 minut, po czym mase suszy konwekcyjnie strumieniem powietrza przez okres 60-180 minut utrzymujac temperature nawiewu na poziomie 40-80°C, az do uzyskania kulistych granul o wielkosci 0,5-1,5 mm i zawartosci wilgoci ponizej 1,5% wagowego, w ilosci co najmniej 70% wagowych uzytego pylu perlitowego. End time: Monday, 26 October 2020, 13:27:12 PM Total elapsed time: 0m 04s 015ms Press any key
using System;
using System.IO;
using System.Linq;
using Aquaforest.BarcodeReader.Api;
using Aquaforest.BarcodeReader.Common;
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
///
/// This sample processes a page with multiple barcodes, iterating through
/// each result and writing the barcode properties to the console.
///
namespace GetMultipleBarcodesPerPage
{
class Program
{
static void Main(string[] args)
{
try
{
BarcodeReaderSettings settings = new BarcodeReaderSettings();
// Set to read multiple barcodes per page
settings.ReadMultipleBarcodes = true; //read multiple barcodes per page
// Barcode formats to look for
settings.BarcodeFormats[BarcodeFormat.CODE_39] = true;
settings.BarcodeFormats[BarcodeFormat.CODE_128] = true;
settings.BarcodeFormats[BarcodeFormat.CODE_93] = true;
settings.BarcodeFormats[BarcodeFormat.ITF] = true;
settings.BarcodeFormats[BarcodeFormat.QR_CODE] = true;
// Create a console logger for output
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Information);
using (BarcodeReader reader = new BarcodeReader(settings, logger))
{
reader.License = Helper.LICENSE_KEY;
string resourceFolder = Path.GetFullPath(@"..\..\..\..\..\..\bin\");
string currentEnvironmentVariables = Environment.GetEnvironmentVariable("PATH");
if (!currentEnvironmentVariables.Contains(resourceFolder))
{
Environment.SetEnvironmentVariable("PATH", currentEnvironmentVariables + ";" + resourceFolder);
}
reader.ResourceFolder = resourceFolder;
// Scans the input document for barcodes
reader.DecodeImage(Path.GetFullPath(@"..\..\..\..\..\documents\source\sample-barcodes.tif"));
Console.WriteLine();
Console.WriteLine("Decode Results");
Console.WriteLine(new string('-', 30));
// Iterates through each page that contains a barcode
foreach (var result in reader.DecodeResults.Where(r => r.Value.Success))
{
var pageResults = result.Value.BarcodeResults;
Console.WriteLine("Found {0} barcode{1} on page {2}" + Environment.NewLine, pageResults.Count, pageResults.Count > 1 ? "s" : "", result.Key);
// Iterates through each barcode result on the page, writing the barcode text, format, and type to console
foreach (var r in pageResults)
{
Console.WriteLine("Barcode Format: {0}", r.BarcodeFormat.ToString());
Console.WriteLine("Text: {0}", r.Text);
Console.WriteLine("Type: {0}", r.Type.ToString());
Console.WriteLine();
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Press any key");
Console.ReadKey();
}
}
}
Processing page 1 Processing page 2 Decode Results ------------------------------ Found 5 barcodes on page 1 Barcode Format: QR_CODE Text: QR Code Test - 01-02-03 Type: TEXT Barcode Format: CODE_93 Text: CODE-93-AQFRST Type: TEXT Barcode Format: ITF Text: 1122334455 Type: TEXT Barcode Format: CODE_39 Text: AAA-CODE-39 Type: TEXT Barcode Format: CODE_128 Text: AQUA-CODE_128 Type: TEXT Found 2 barcodes on page 2 Barcode Format: QR_CODE Text: Aquaforest QR Code Type: TEXT Barcode Format: ITF Text: 1234567890 Type: TEXT Press any key
using Aquaforest.Logging;
using Aquaforest.Logging.Abstractions;
using Aquaforest.PDF;
using Aquaforest.PDF.Font;
using System;
///
/// This sample creates a blank PDF, adding content to the
/// document and saving the new document to the output location.
///
namespace CreatePDF
{
internal class CreateNewPDF
{
// Create a PDF document
private static void Main(string[] args)
{
//Assign Licence Key
PDFToolkit.LicenseKey = Helper.LICENSE_KEY;
// Create a console logger for output at debug level
IAquaforestLogger logger = new SimpleConsoleLogger(AquaforestLogLevel.Debug);
PDFDocument doc = new PDFDocument(logger);
PDFPage page = new PDFPage();
// Add text to page
PDFPageContentStream contents = new PDFPageContentStream(doc, page);
contents.BeginText();
contents.SetFont(PDFType1Font.COURIER_BOLD, 12);
contents.MoveText(100, 700);
contents.DrawString("Hello World!");
contents.EndText();
contents.Close();
// Add metadata
PDFDocumentInformation info = new PDFDocumentInformation()
{
Author = "Name Surname",
Subject = "Test",
Title = "New PDF",
Keywords = "PDF, OCR, SDK",
CreationDate = new DateTime(2020, 7, 7),
Producer = "Aquaforest"
};
info.SetCustomMetadataValue("AQUAFOREST_PDF_TOOLKIT", "3.0");
doc.SetDocumentInformation(info);
// Add page to PDF document
doc.AddPage(page);
doc.Save(@"..\samples\documents\output\pdf_out.pdf");
doc.Close();
logger.LogInformation("Completed");
}
}
}
Creates the file: C:\Aquaforest\Aquaforest SDK\PDFToolkit\samples\documents\output\pdf_out.pdf Containing the text: Hello World!