原創|其它|編輯:郝浩|2012-12-19 10:30:43.000|閱讀 400 次
概述:使用GdPicture.NET可以不用創建PDF文件而直接獲取Tiff文件中的OCR,下面給出這一示例的代碼,適用于單頁或者多頁的Tiff文件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
使用GdPicture.NET可以不用創建PDF文件而直接獲取Tiff文件中的OCR,下面給出這一示例的代碼,適用于單頁或者多頁的Tiff文件。
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
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網