OCR tif multipage

Example requests & Code samples for GdPicture Toolkits.
Post Reply
mirkop
Posts: 41
Joined: Wed Jun 24, 2009 5:38 pm

OCR tif multipage

Post by mirkop » Tue Feb 23, 2010 6:55 pm

Hi,

Could you give me a code sample about obtain the OCR of a tif multipage without create pdf file.

Regards,

Mirko

mirkop
Posts: 41
Joined: Wed Jun 24, 2009 5:38 pm

Re: OCR tif multipage

Post by mirkop » Wed Feb 24, 2010 10:11 am

Hi,

Please could you give me this sample, because a need a quick reply for my chief.

Mirko

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: OCR tif multipage

Post by Loïc » Wed Feb 24, 2010 10:23 am

Hi Mirko,

Here an example to OCR a multipage tiff image (also works with single page images).

Code: Select all


Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oGdPictureImaging As New GdPicture.GdPictureImaging
        oGdPictureImaging.SetLicenseNumber("XXXX") 'Replace XXXX by a valid or commercial KEY
        oGdPictureImaging.SetLicenseNumberOCRTesseract("XXXX") 'Replace XXXX by a valid or commercial KEY

        Dim sOCR As String
        Dim hFile As Integer
        Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("")
        Dim PageCount As Integer = 1


        If oGdPictureImaging.GetStat = GdPictureStatus.OK Then
            If oGdPictureImaging.TiffIsMultiPage(ImageID) Then
                PageCount = oGdPictureImaging.TiffGetPageCount(ImageID)
            End If

            If Dir(My.Application.Info.DirectoryPath & "\ocr.txt") <> "" Then Kill((My.Application.Info.DirectoryPath & "\ocr.txt"))
            hFile = FreeFile()
            FileOpen(hFile, My.Application.Info.DirectoryPath & "\ocr.txt", OpenMode.Append)

            For I As Integer = 1 To PageCount
                If I > 1 Then
                    oGdPictureImaging.TiffSelectPage(ImageID, I)
                End If
                oGdPictureImaging.OCRTesseractReinit()
                sOCR = oGdPictureImaging.OCRTesseractDoOCR(ImageID, TesseractDictionary.TesseractDictionaryEnglish, "C:\Program Files\GdPicture.NET\Redist\Commons\OCR", "")
                If oGdPictureImaging.GetStat <> GdPictureStatus.OK Then
                    MsgBox("Error on page " + Str(I) + ": " + oGdPictureImaging.GetStat.ToString)
                End If
                oGdPictureImaging.OCRTesseractClear()
                PrintLine(hFile, "OCR Page " + Str(I))
                PrintLine(hFile, "-------------------------------------------------------------------")
                PrintLine(hFile, sOCR)
            Next I

            FileClose(hFile)
            oGdPictureImaging.ReleaseGdPictureImage(ImageID)

            Call ShellExecute(Me.Handle.ToInt32, vbNullString, My.Application.Info.DirectoryPath & "\ocr.txt", "", "", 1)
        Else
            MsgBox("Can't open selected file !")
        End If
    End Sub

mirkop
Posts: 41
Joined: Wed Jun 24, 2009 5:38 pm

Re: OCR tif multipage

Post by mirkop » Wed Feb 24, 2010 10:49 am

Hi Loic,

Thank you!!

Mirko

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: OCR tif multipage

Post by Loïc » Wed Feb 24, 2010 10:59 am

You are welcome ;)

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: OCR tif multipage

Post by Gabriela » Wed Nov 22, 2017 12:04 pm

Here you can find updated code snippet based on GdPicture.NET 14:

How to OCR a single page or a multipage TIFF file
https://www.gdpicture.com/guides/gdpicture/web ... file.html

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest