PerformOcrAnalysisAndExtractText.vbs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | ' This example demonstrates the use of OCR Analyser - a tooling class for analysis of scanned documents ' in PDF or raster image formats to find best parameters for Optical Character Recognition (OCR) that ' provide highest recognition quality. ' Input document inputDocument = "..\..\sample_ocr.pdf" ' Document page index pageIndex = 0 ' Location of "tessdata" folder containing language data files ocrLanguageDataFolder = "c:\Program Files\Bytescout PDF Extractor SDK\Redistributable\net2.00\tessdata\" ' OCR language ocrLanguage = "eng" ' "eng" for english, "deu" for German, "fra" for French, "spa" for Spanish etc - according to files in /tessdata ' Find more language files at https://github.com/tesseract-ocr/tessdata/tree/3.04.00 ' Create OCRAnalyzer object and activate it with your registration information Set ocrAnalyzer = CreateObject( "Bytescout.PDFExtractor.OCRAnalyzer" ) ocrAnalyzer.RegistrationName = "demo" ocrAnalyzer.RegistrationKey = "demo" ' Load document to OCRAnalyzer ocrAnalyzer.LoadDocumentFromFile(inputDocument) ' Setup OCRAnalyzer ocrAnalyzer.OCRLanguage = ocrLanguage ocrAnalyzer.OCRLanguageDataFolder = ocrLanguageDataFolder WScript.Echo "Starting the OCR analysis. Click OK and wait, it may last long." & outputDocument ' Perform analysis and get results Set analysisResults = ocrAnalyzer.AnalyzeByOCRConfidence(pageIndex) ' Now extract page text using detected OCR parameters outputDocument = ".\result.txt" ' Create TextExtractor object Set textExtractor = CreateObject( "Bytescout.PDFExtractor.TextExtractor" ) textExtractor.RegistrationName = "demo" textExtractor.RegistrationKey = "demo" ' Load document to TextExtractor textExtractor.LoadDocumentFromFile(inputDocument) ' Setup TextExtractor textExtractor.OCRMode = 1 ' OCRMode.Auto textExtractor.OCRLanguageDataFolder = ocrLanguageDataFolder textExtractor.OCRLanguage = ocrLanguage ' Apply analysys results to TextExtractor instance ocrAnalyzer.ApplyResults (analysisResults), (textExtractor) ' Save extracted text to file textExtractor.SaveTextToFile(outputDocument) WScript.Echo "Extracted text saved to " & outputDocument Set textExtractor = Nothing Set ocrAnalyzer = Nothing |
Click here to get your Free Trial version of the SDK
also available as: