You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.6 KiB
122 lines
3.6 KiB
Imports System.IO
|
|
Imports System.Drawing
|
|
Imports Syncfusion.Pdf
|
|
Imports Syncfusion.Pdf.Parsing
|
|
Imports Syncfusion
|
|
Imports Patagames.Ocr
|
|
Imports Patagames.Ocr.Enums
|
|
|
|
Public Class frmDokMgmt
|
|
Private Sub frmDokMgmt_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
Get_Files()
|
|
End Sub
|
|
|
|
|
|
Sub Get_Files()
|
|
Me.ListBox1.Items.Clear()
|
|
Dim fileEntries As String() = Directory.GetFiles(My.Settings.SourcePath)
|
|
' Process the list of files found in the directory.
|
|
Dim fileName As String
|
|
For Each fileName In fileEntries
|
|
If System.IO.Path.GetExtension(fileName) = ".pdf" Then Me.ListBox1.Items.Add(Path.GetFileName(fileName))
|
|
|
|
Next fileName
|
|
|
|
End Sub
|
|
|
|
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
|
|
loadpdf(My.Settings.SourcePath + Me.ListBox1.SelectedItem)
|
|
End Sub
|
|
|
|
Public Sub loadpdf(ByVal filename As String)
|
|
PdfViewerControl1.Load(filename)
|
|
Me.TextBox1.Text = ""
|
|
Me.TextBox2.Text = ""
|
|
Try
|
|
Dim s As String = My.Settings.SourcePath + Me.ListBox1.SelectedItem
|
|
Try
|
|
Dim ldoc As New PdfLoadedDocument(s)
|
|
|
|
Dim page As PdfLoadedPage = ldoc.Pages(0)
|
|
Dim ss As String
|
|
|
|
ss = page.ExtractText()
|
|
Dim splitter() As String
|
|
splitter = ss.Split(vbCrLf)
|
|
Dim splitter2() As String
|
|
splitter2 = splitter(1).ToString.Split(":")
|
|
Me.TextBox2.Text = splitter2(1).ToString.Trim
|
|
splitter2 = splitter(2).ToString.Split(":")
|
|
Me.TextBox1.Text = splitter2(1).ToString.Trim
|
|
Catch
|
|
End Try
|
|
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
|
|
Try
|
|
' If FindTextinPdf("Doktyp:") Then MsgBox("Found")
|
|
Catch ex As Exception
|
|
' MsgBox(ex.Message)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Public Function FindTextinPdf(texttofind As String) As Boolean
|
|
|
|
|
|
Dim IsMatchFound As Boolean
|
|
'Get the occurrences of the target text and location.
|
|
|
|
Dim textSearch As New Dictionary(Of Integer, List(Of RectangleF))()
|
|
Dim gaga As Dictionary(Of Integer, List(Of RectangleF))
|
|
|
|
IsMatchFound = PdfViewerControl1.FindText(texttofind, textSearch)
|
|
|
|
Dim s As String = PdfViewerControl1.FindText(texttofind, textSearch)
|
|
|
|
Return IsMatchFound
|
|
|
|
End Function
|
|
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
OcrApi.PathToEngine = "H:\scan\Tesseract\"
|
|
Using api = OcrApi.Create()
|
|
|
|
api.Init(Languages.German)
|
|
|
|
Using renderer = OcrPdfRenderer.Create("h:\scan\scan0036.pdf", "H:\scan\Tesseract\TessData\")
|
|
renderer.BeginDocument("Title")
|
|
api.ProcessPages("h:\scan\scaned.txt", Nothing, 0, renderer)
|
|
renderer.EndDocument()
|
|
End Using
|
|
End Using
|
|
|
|
End Sub
|
|
|
|
'Using processor As New Syncfusion.OCRProcessor.OCRProcessor("H:\scan\Tesseract\")
|
|
|
|
' 'Load a PDF document
|
|
|
|
' Dim lDoc As New PdfLoadedDocument("h:\scan\scan0036.pdf")
|
|
|
|
' 'Set OCR language to process
|
|
|
|
' processor.Settings.Language = OCRProcessor.Languages.English
|
|
|
|
' 'Process OCR by providing the PDF document and Tesseract data
|
|
|
|
' processor.PerformOCR(lDoc, "H:\scan\Tesseract\TessData\")
|
|
|
|
' 'Save the OCR processed PDF document in the disk
|
|
|
|
' lDoc.Save("h:\scan\Sample.pdf")
|
|
|
|
' lDoc.Close(True)
|
|
|
|
' End Using
|
|
'End Sub
|
|
End Class |