Imports System.Windows.Forms Imports Gnostice.Documents.Controls.WinForms Imports Gnostice.Documents Public Class frmScan Dim licenseKey As String = "530B-ED36-D5D0-CB1D-DD48-B443-AE22-6E19-0264-3D59-FA7A-9FAD" Dim barcode As SoftekBarcodeNet.BarcodeReader Dim nBarCodes As Integer Sub New() ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. Try Framework.ActivateLicense(licenseKey) Catch ex As Exception MsgBox(ex.Message) End Try initBarcode() End Sub Private Sub frmScan_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.ListBox1.Items.Clear() Dim di As New IO.DirectoryInfo("E:\Software-Projekte\EDOKA\__Barcode\DOcs") Dim diar1 As IO.FileInfo() = di.GetFiles() Dim dra As IO.FileInfo 'list the names of all files in the specified directory For Each dra In diar1 If UCase(dra.Extension) = ".PDF" Then ListBox1.Items.Add(dra.Name) Next End Sub Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged Me.DocumentViewer1.LoadDocument("E:\Software-Projekte\EDOKA\__Barcode\DOcs\" + Me.ListBox1.SelectedItem) End Sub Private Sub TSBtnLast_Click(sender As Object, e As EventArgs) Handles TSBtnLast.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.LastPage() End Sub Private Sub TSBtnPrevious_Click(sender As Object, e As EventArgs) Handles TSBtnPrevious.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.PreviousPage() End Sub Private Sub TSBtnNext_Click(sender As Object, e As EventArgs) Handles TSBtnNext.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.NextPage() End Sub Private Sub TSBtnFirst_Click(sender As Object, e As EventArgs) Handles TSBtnFirst.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.FirstPage() End Sub Private Sub tsZoomOut_Click(sender As Object, e As EventArgs) Handles tsZoomOut.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.ZoomOut() End If End Sub Private Sub tsZoomIn_Click(sender As Object, e As EventArgs) Handles tsZoomIn.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.ZoomIn() End If End Sub Private Sub txtZoom_Click(sender As Object, e As EventArgs) End Sub Private Sub tsFitPage_Click(sender As Object, e As EventArgs) Handles tsFitPage.Click If DocumentViewer1.IsDocumentLoaded Then Me.DocumentViewer1.Zoom.ZoomMode = ZoomMode.FitPage End If End Sub Private Sub btnFirstPage_Click(sender As Object, e As EventArgs) End Sub Private Sub tsFitWidth_Click(sender As Object, e As EventArgs) Handles tsFitWidth.Click If DocumentViewer1.IsDocumentLoaded Then DocumentViewer1.Zoom.ZoomMode = ZoomMode.FitWidth End If End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Results.Text = "" 'DocumentViewer1.CloseDocument() nBarCodes = barcode.ScanBarCode("E:\Software-Projekte\EDOKA\__Barcode\DOcs\" + ListBox1.SelectedItem) getResults() End Sub Private Sub getResults() Dim i As Integer Dim nDirection As Integer Dim nPage As Integer Dim rect As System.Drawing.Rectangle If nBarCodes <= -6 Then SetText("License key error: either an evaluation key has expired or the license key is not valid for processing pdf documents") ElseIf nBarCodes < 0 Then SetText("ScanBarCode returned error number " & nBarCodes) SetText("Last Softek Error Number = " & barcode.GetLastError()) SetText("Last Windows Error Number = " & barcode.GetLastWinError()) End If If nBarCodes = 0 Then SetText("Sorry - no barcodes were found in this image") End If For i = 1 To nBarCodes SetText("Barcode " & i & ":") SetText("Value = " & barcode.GetBarString(i)) SetText("Type = " & barcode.GetBarStringType(i)) nDirection = barcode.GetBarStringDirection(i) If nDirection = 1 Then SetText("Direction = Left to Right") Else If nDirection = 2 Then SetText("Direction = Top to Bottom") Else If nDirection = 4 Then SetText("Direction = Right to Left") Else If nDirection = 8 Then SetText("Direction = Bottom to Top") End If End If End If End If nPage = barcode.GetBarStringPage(i) rect = barcode.GetBarStringRect(i) SetText("Page = " & nPage) SetText("Top Left = (" & rect.X & "," & rect.Y & ")") SetText("Bottom Right = (" & (rect.X + rect.Width) & "," & (rect.Y + rect.Height) & ")") SetText("") Next i GC.Collect() End Sub Delegate Sub SetTextCallback(ByVal [text] As String) Private Sub SetText(ByVal [text] As String) ' InvokeRequired required compares the thread ID of the ' calling thread to the thread ID of the creating thread. ' If these threads are different, it returns true. If Me.Results.InvokeRequired Then Dim d As New SetTextCallback(AddressOf SetText) Me.Invoke(d, New Object() {[text]}) Else Me.Results.Text += [text] + vbNewLine End If End Sub Private Sub initBarcode() ' For the purposes of this demo we first give a path to the installation folder ' and the class adds either x86 or x64 to the end and tries to load the other dll files. ' If that fails (perhaps this project has been moved) then we give no path and the class ' assumes that the dll files will be somewhere on the PATH. ' ' In this project we give the path to the Softek DLL files when we create the BarcodeReader class ' Another way is to include the following files with your project: ' SoftekBarcodeDLL.dll ' SoftekBarcode64DLL.dll ' DebenuPDFLibraryDLLXXXX.dll ' DebenuPDFLibrary64DLLXXXX.dll barcode = New SoftekBarcodeNet.BarcodeReader("E:\Software-Projekte\EDOKA\__Barcode\Barcode.com\bin") ' Enter your license key here ' You can get a trial license key from sales@bardecode.com ' Example: ' barcode.LicenseKey = "MY LICENSE KEY" ' Turn on the barcode types you want to read. ' Turn off the barcode types you don't want to read (this will increase the speed of your application) barcode.ReadCode128 = True barcode.ReadCode39 = True barcode.ReadCode25 = True barcode.ReadEAN13 = True barcode.ReadEAN8 = True barcode.ReadUPCA = True barcode.ReadUPCE = True barcode.ReadCodabar = True barcode.ReadPDF417 = True barcode.ReadDataMatrix = True barcode.ReadDatabar = True barcode.ReadMicroPDF417 = False barcode.ReadQRCode = True ' Databar Options is a mask that controls which type of databar barcodes will be read and whether or not ' the software will look for a quiet zone around the barcode. ' 1 = 2D-Linkage flag (handle micro-PDf417 barcodes as supplementary data - requires ReadMicroPDF417 to be true). ' 2 = Read RSS14 ' 4 = Read RSS14 Stacked ' 8 = Read Limited ' 16 = Read Expanded ' 32 = Read Expanded Stacked ' 64 = Require quiet zone barcode.DatabarOptions = 255 ' If you want to read more than one barcode then set Multiple Read to 1 ' Setting MutlipleRead to False will make the recognition faster barcode.MultipleRead = True ' If you know the max number of barcodes for a single page then increase speed by setting MaxBarcodesPerPage barcode.MaxBarcodesPerPage = 0 ' In certain conditions (MultipleRead = false or MaxBarcodesPerPage = 1) the SDK can make fast scan of an image before performing the normal scan. This is useful if only 1 bar code is expected per page. barcode.UseFastScan = True ' If MultipleRead = false or MaxBarcodesPerPage = 1 and the bar code is always closer to the top of a page then set BarcodesAtTopOfPage to True to increase speed. barcode.BarcodesAtTopOfPage = False ' Noise reduction takes longer but can make it possible to read some difficult barcodes ' When using noise reduction a typical value is 10 - the smaller the value the more effect it has. ' A zero value turns off noise reduction. ' barcode.NoiseReduction = 0 ' You may need to set a small quiet zone if your barcodes are close to text and pictures in the image. ' A value of zero uses the default. barcode.QuietZoneSize = 0 ' LineJump controls the frequency at which scan lines in an image are sampled. ' The default is 1. barcode.LineJump = 1 ' You can restrict your search to a particular area of the image if you wish. ' This example limits the search to the upper half of the page ' Dim scanArea As System.Drawing.Rectangle ' scanArea = New System.Drawing.Rectangle(0, 0, 100, 50) ' barcode.SetScanRect(scanArea, 1) ' Set the direction that the barcode reader should scan for barcodes ' The value is a mask where 1 = Left to Right, 2 = Top to Bottom, 4 = Right To Left, 8 = Bottom to Top barcode.ScanDirection = 15 ' Set the page number to read from in a multi-page TIF file. The default is 0, which will make the ' toolkit check every page. ' barcode.PageNo = 1 ' SkewTolerance controls the angle of skew that the barcode toolkit will tolerate and ranges from 0 to 5 (45 degrees) ' Note that from version 7.6.1 the SDK is able to read some skewed barcodes with this setting. See below. barcode.SkewTolerance = 0 ' Read most skewed linear barcodes without the need to set SkewTolerance. Currently applies to Codabar, Code 25, Code 39 and Code 128 barcodes only. barcode.SkewedLinear = True ' Read most skewed datamatrix barcodes without the need to set SkewTolerance barcode.SkewedDatamatrix = True ' ColorProcessingLevel controls how much time the toolkit will searching a color image for a barcode. ' The default value is 2 and the range of values is 0 to 5. If ColorThreshold is non-zero then ' ColorProcessingLevel is effectively set to 0. barcode.ColorProcessingLevel = 2 ' MaxLength and MinLength can be used to specify the number of characters you expect to ' find in a barcode. This can be useful to increase accuracy or if you wish to ignore some ' barcodes in an image. barcode.MinLength = 4 barcode.MaxLength = 999 ' When the toolkit scans an image it records the number of hits it gets for each barcode that ' MIGHT be in the image. If the hits recorded for any of the barcodes are >= PrefOccurrence ' then only these barcodes are returned. Otherwise, any barcode whose hits are >= MinOccurrence ' are reported. If you have a very poor quality image then try setting MinOccurrence to 1, but you ' may find that some false positive results are returned. ' barcode.MinOccurrence = 2 ' barcode.PrefOccurrence = 4 ' Read Code 39 barcodes in extended mode ' barcode.ExtendedCode39 = True ' Barcode string is numeric ' barcode.ReadNumeric = True ' Set a regular expression for the barcode ' barcode.Pattern = "^[A-Z]{2}[0-9]{5}$" ' If you are scanning at a high resolution and the spaces between bars are ' larger than 1 pixel then set MinSpaceBarWidth to 2 and increase your read rate. ' barcode.MinSpaceBarWidth = 2 ' MedianFilter is a useful way to clean up higher resolution images where the black bars contain white dots ' and the spaces contain black dots. It does not work if the space between bars is only 1 pixel wide. barcode.MedianFilter = False ' ReportUnreadBarcodes can be used to warn of the presence of a barcode on a page that the SDK has not been able to decode. ' It currently has the following important limitations: ' 1. An unread linear barcode will only be reported if no other barcode was found in the same page. ' 2. The height of the area for an unread linear barcode will only cover a portion of the barcode. ' 3. Only 2-D barcodes that fail to error correct will be reported. ' 4. The barcode type and value will both be set to UNREAD for all unread barcodes. ' 5. The reporting of unread linear barcodes takes no account of settings for individual barcode types. For example, if ReadCode39 is True and ' an image contains a single Code 39 barcode then this will be reported as an unread barcode. ' 6. 2-D barcodes are only reported as unread if the correct barcode types have been enabled. ' 7. Not all unread barcodes will be detected. ' ' The value is a mask with the following values: 1 = linear barcodes, 2 = Datamatrix, 4 = QR-Code, 8 = PDF-417 barcode.ReportUnreadBarcodes = 0 ' Time out for reading a barcode from a page in ms. Note that this does not include the time to load the page. ' 0 means no time out. barcode.TimeOut = 5000 ' Flags for handling PDF files ' PdfImageOnly defaults to true and indicates that the PDF documents are simple images. barcode.PdfImageOnly = True ' PdfImageExtractOptions is no longer required in version 8 of the SDK but is retained for future possible use. ' barcode.PdfImageExtractOptions = 0 ' The PdfImageRasterOptions mask controls how images are rasterized when PdfImageOnly is false or when image extraction fails ' 0 = Use Debenu to render image ' 4 = Use VeryPDF to render image (x86 only) barcode.PdfImageRasterOptions = 0 ' PdfDpi and PdfBpp control what sort of image the PDF document is rasterized into barcode.PdfDpi = 300 barcode.PdfBpp = 8 ' Or you can load the settings from a xml format file ' See the manual for more details. ' barcode.LoadXMLSettings("settings.xml") End Sub End Class