You are viewing limited content. For full access, please sign in.

Question

Question

DocumentInfo.GetPageInfos - Read Text of a document

asked on February 13, 2015

How do I use DocumentInfo.GetPageInfos to retrieve the pages of a LF document and then read out the text for each page. I want to read the text into a string object. Please provide some sample code. Thanks.

 

Priya

0 0

Replies

replied on February 13, 2015 Show version history

If I follow correctly, you want to get the OCR'd text from each page of a document in a repository and read the text into a string.  If so, here is a bare-bones code snippet that will open a repository, retrieve a reference to a document, and read the text of each page into a List(Of String) object.

        Dim pageText As List(Of String) = New List(Of String)
        Dim raSession As Session = New Session

        'Open the session and login...
        raSession.Connect(New RepositoryRegistration("SAMANTHA-PC", "LFMAIN"))
        raSession.LogIn("admin", "admin")

        'Get a reference to the Document...
        Dim docInfo As DocumentInfo = Document.GetDocumentInfo(96960, raSession)

        'Instantiate a new PageInfoReader...
        Dim pageReader As PageInfoReader = docInfo.GetPageInfos

        'Step through each page of the document and read the text into the list...
        For Each pInfo As PageInfo In pageReader
            Using reader As StreamReader = pInfo.ReadTextPagePart
                pageText.Add(reader.ReadLine)
            End Using
        Next

        'Cleanup...
        pageReader.Close()
        docInfo.Dispose()
        raSession.Close()

Note:  You could even omit instantiating the DocumentInfo object if you don't need it in the routine and instead instantiate the PageInfoReader like this;

        'Instantiate a new PageInfoReader...
        Dim pageReader As PageInfoReader = Document.GetDocumentInfo(96960, raSession).GetPageInfos

But some might say that it is a little harder to follow what is happening...

0 0
replied on February 17, 2015

Thanks

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.