VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
In This Topic
OCR: How to import the OCR result from hOCR file?
In This Topic
OCR results can be imported from hOCR file.

Here is C#/VB.NET code that shows how to import OCR result from hOCR file and save imported result to a text file as formatted text:
// OCR result
Vintasoft.Imaging.Ocr.Results.OcrDocument ocrResult = null;

// path to hOCR file
string hOcrFilePath = @"..\..\Resources\ocrResult.hocr";
// open hOCR file
using (System.IO.Stream stream = System.IO.File.Open(hOcrFilePath, System.IO.FileMode.Open))
{
    // create the HOcr codec
    Vintasoft.Imaging.Ocr.Results.HOcrCodec hOcrCodec = new Vintasoft.Imaging.Ocr.Results.HOcrCodec();
    // import the OCR result from hOCR file
    ocrResult = hOcrCodec.Import(stream);
}

// if OCR result is imported successfully
if (ocrResult != null)
{
    // get text of the first page
    string firstPageText = ocrResult.Pages[0].GetFormattedText();
    // save text to a text file
    System.IO.File.WriteAllText("ocrResult.txt", firstPageText, System.Text.Encoding.UTF8);
}
' OCR result
Dim ocrResult As Vintasoft.Imaging.Ocr.Results.OcrDocument = Nothing

' path to hOCR file
Dim hOcrFilePath As String = "..\..\Resources\ocrResult.hocr"
' open hOCR file
Using stream As System.IO.Stream = System.IO.File.Open(hOcrFilePath, System.IO.FileMode.Open)
    ' create the HOcr codec
    Dim hOcrCodec As New Vintasoft.Imaging.Ocr.Results.HOcrCodec()
    ' import the OCR result from hOCR file
    ocrResult = hOcrCodec.Import(stream)
End Using

' if OCR result is imported successfully
If ocrResult IsNot Nothing Then
    ' get text of the first page
    Dim firstPageText As String = ocrResult.Pages(0).GetFormattedText()
    ' save text to a text file
    System.IO.File.WriteAllText("ocrResult.txt", firstPageText, System.Text.Encoding.UTF8)
End If