GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureOCR Class / SaveAsText Method / SaveAsText(ICollection<String>,Stream,OCROutputTextFormat,Boolean) Method
A collection of the unique OCR result identifiers. It specifies the OCR results you want to save.
A Stream object where the results will be saved to. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
The text format of the output text file. A member of the OCROutputTextFormat enumeration.
The flag indicating whether to keep line breaks or not when saving the results.
Example





In This Topic
SaveAsText(ICollection<String>,Stream,OCROutputTextFormat,Boolean) Method
In This Topic
Saves the provided collection of OCR results, identifiable by their unique IDs, to a stream in the text format.
Syntax
'Declaration
 
Public Overloads Function SaveAsText( _
   ByVal OCRResultIDs As ICollection(Of String), _
   ByVal Stream As Stream, _
   ByVal TextFormat As OCROutputTextFormat, _
   ByVal KeepLineBreaks As Boolean _
) As GdPictureStatus
public GdPictureStatus SaveAsText( 
   ICollection<string> OCRResultIDs,
   Stream Stream,
   OCROutputTextFormat TextFormat,
   bool KeepLineBreaks
)
public function SaveAsText( 
    OCRResultIDs: ICollection;
    Stream: Stream;
    TextFormat: OCROutputTextFormat;
    KeepLineBreaks: Boolean
): GdPictureStatus; 
public function SaveAsText( 
   OCRResultIDs : ICollection,
   Stream : Stream,
   TextFormat : OCROutputTextFormat,
   KeepLineBreaks : boolean
) : GdPictureStatus;
public: GdPictureStatus SaveAsText( 
   ICollection<string*>* OCRResultIDs,
   Stream* Stream,
   OCROutputTextFormat TextFormat,
   bool KeepLineBreaks
) 
public:
GdPictureStatus SaveAsText( 
   ICollection<String^>^ OCRResultIDs,
   Stream^ Stream,
   OCROutputTextFormat TextFormat,
   bool KeepLineBreaks
) 

Parameters

OCRResultIDs
A collection of the unique OCR result identifiers. It specifies the OCR results you want to save.
Stream
A Stream object where the results will be saved to. This Stream object must be initialized before it can be sent into this method and it should remain open for subsequent use.
TextFormat
The text format of the output text file. A member of the OCROutputTextFormat enumeration.
KeepLineBreaks
The flag indicating whether to keep line breaks or not when saving the results.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
The output stream should be open for writing and should be closed/disposed by the user as well.
Example
How to save a collection of the OCR results to a text-formatted stream.
Dim caption As String = "Example: SaveAsText"
Using gdpictureOCR As GdPictureOCR = New GdPictureOCR()
    'Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\GdPicture.Net 14\redist\OCR"
    If gdpictureOCR.AddLanguage(OCRLanguage.English) = GdPictureStatus.OK Then
        'Set up the image you want to process.
        Dim gdpictureImaging As GdPictureImaging = New GdPictureImaging()
        'The standard open file dialog displays to allow you to select the file.
        Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
        If (gdpictureImaging.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpictureOCR.SetImage(image) = GdPictureStatus.OK) Then
            Dim results As List(Of String) = New List(Of String)()
            'Define the required ROI.
            gdpictureOCR.SetROI(100, 100, 200, 50)
            'Define the character set for phone numbers.
            gdpictureOCR.CharacterSet = "0123456789"
            'Run the OCR process.
            gdpictureOCR.RunOCR("PhoneNumberRegion")
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                results.Add("PhoneNumberRegion")
            Else
                MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
            End If
            'Reset the required ROI.
            gdpictureOCR.SetROI(150, 300, 200, 200)
            'Define the character set for addresses.
            gdpictureOCR.CharacterSet = ""
            gdpictureOCR.Context = OCRContext.OCRContextSingleBlock
            'Run the OCR process.
            gdpictureOCR.RunOCR("AddressRegion")
            If gdpictureOCR.GetStat() = GdPictureStatus.OK Then
                results.Add("AddressRegion")
            Else
                MessageBox.Show("The second OCR process has failed with the status: " & gdpictureOCR.GetStat().ToString(), caption)
            End If
            If results.Count > 0 Then
                'Save the results.
                Dim oStream As System.IO.FileStream = New System.IO.FileStream("OCR_result.txt", System.IO.FileMode.Create)
                If gdpictureOCR.SaveAsText(results, oStream, OCROutputTextFormat.Utf16, True) = GdPictureStatus.OK Then
                    MessageBox.Show("The OCR results has been successfully saved.", caption)
                Else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
                End If
                oStream.Dispose()
            End If
            'Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image)
        Else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption)
        End If
        gdpictureImaging.Dispose()
    Else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption)
    End If
    gdpictureOCR.ReleaseOCRResults()
End Using
string caption = "Example: SaveAsText";
using (GdPictureOCR gdpictureOCR = new GdPictureOCR())
{
    //Set up your prefered parameters for OCR.
    gdpictureOCR.ResourcesFolder = "\\GdPicture.Net 14\\redist\\OCR";
    if (gdpictureOCR.AddLanguage(OCRLanguage.English) == GdPictureStatus.OK)
    {
        //Set up the image you want to process.
        GdPictureImaging gdpictureImaging = new GdPictureImaging();
        //The standard open file dialog displays to allow you to select the file.
        int image = gdpictureImaging.CreateGdPictureImageFromFile("");
        if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
            (gdpictureOCR.SetImage(image) == GdPictureStatus.OK))
        {
            List<string> results = new List<string>();
 
            //Define the required ROI.
            gdpictureOCR.SetROI(100, 100, 200, 50);
            //Define the character set for phone numbers.
            gdpictureOCR.CharacterSet = "0123456789";
 
            //Run the OCR process.
            gdpictureOCR.RunOCR("PhoneNumberRegion");
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
                results.Add("PhoneNumberRegion");
            else
                MessageBox.Show("The first OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
 
            //Reset the required ROI.
            gdpictureOCR.SetROI(150, 300, 200, 200);
            //Define the character set for addresses.
            gdpictureOCR.CharacterSet = "";
            gdpictureOCR.Context = OCRContext.OCRContextSingleBlock;
 
            //Run the OCR process.
            gdpictureOCR.RunOCR("AddressRegion");
            if (gdpictureOCR.GetStat() == GdPictureStatus.OK)
                results.Add("AddressRegion");
            else
                MessageBox.Show("The second OCR process has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
 
            if (results.Count > 0)
            {
                System.IO.FileStream oStream = new System.IO.FileStream("OCR_result.txt", System.IO.FileMode.Create);
                if (gdpictureOCR.SaveAsText(results, oStream, OCROutputTextFormat.Utf16, true) == GdPictureStatus.OK)
                    MessageBox.Show("The OCR results has been successfully saved.", caption);
                else
                    MessageBox.Show("The SaveAsText() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
                oStream.Dispose();
            }
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureOCR.GetStat().ToString(), caption);
        gdpictureImaging.Dispose();
    }
    else
        MessageBox.Show("The AddLanguage() method has failed with the status: " + gdpictureOCR.GetStat().ToString(), caption);
    gdpictureOCR.ReleaseOCRResults();
}
See Also