Exemple #1
0
        private bool Rand(FoundBarcode barcode)
        {
            if (eckpunkteFinal.Count() == 4)
            {
                barcodeEckpunkte.Clear();
                barcodeEckpunkte.Add(new Point(barcode.Rect.X, barcode.Rect.Y));
                barcodeEckpunkte.Add(new Point(barcode.Rect.X + barcode.Rect.Width, barcode.Rect.Y));
                barcodeEckpunkte.Add(new Point(barcode.Rect.X + barcode.Rect.Width, barcode.Rect.Y + barcode.Rect.Height));
                barcodeEckpunkte.Add(new Point(barcode.Rect.X, barcode.Rect.Y + barcode.Rect.Height));
                int outside = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (outside < 2)
                    {
                        if (barcodeEckpunkte[i].X <eckpunkteFinal[0].X || barcodeEckpunkte[i].X> eckpunkteFinal[1].X || barcodeEckpunkte[i].Y <eckpunkteFinal[0].Y || barcodeEckpunkte[i].Y> eckpunkteFinal[3].Y)
                        {
                            outside++;
                        }
                        if (outside == 2)
                        {
                            Alarm("Achtung ausserhalb des Bereichs");
                        }
                    }
                }
            }

            return(true);
        }
        static void Main(string[] args)
        {
            // Create Bytescout.BarCodeReader.Reader instance
            using (Reader reader = new Reader())
            {
                // Enable QR Code decoding
                reader.BarcodeTypesToFind.QRCode = true;

                // Decode QR Code from image
                FoundBarcode[] barcodes = reader.ReadFrom("sample_vcard.gif");

                if (barcodes.Length > 0)
                {
                    FoundBarcode vcardBarcode = barcodes[0];

                    // Decode vCard information from barcode value
                    StringReader stringReader = new StringReader(vcardBarcode.Value);
                    vCard        vCard        = new vCard(stringReader);

                    // Display some decoded info:
                    Console.WriteLine("GivenName: " + vCard.GivenName);
                    Console.WriteLine("FamilyName: " + vCard.FamilyName);
                    Console.WriteLine("Organization: " + vCard.Organization);
                    Console.WriteLine("Title: " + vCard.Title);
                    Console.WriteLine("Phone: " + vCard.Phones[0].FullNumber);
                    Console.WriteLine("EmailAddresses: " + vCard.EmailAddresses[0]);
                    Console.WriteLine("DeliveryAddress: " + vCard.DeliveryAddresses[0].Street + " " + vCard.DeliveryAddresses[0].City + " " +
                                      vCard.DeliveryAddresses[0].Region + " " + vCard.DeliveryAddresses[0].PostalCode + " " + vCard.DeliveryAddresses[0].Country);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
        private void btnDecode_Click(object sender, RoutedEventArgs e)
        {
            // Create barcode reader instance
            Reader reader = new Reader();

            reader.RegistrationName = "demo";
            reader.RegistrationKey  = "demo";

            // Specify barcode types to find
            reader.BarcodeTypesToFind.All = true;
            // Select specific barcode types to speed up the decoding process and avoid false positives.

            // Show wait cursor
            Mouse.OverrideCursor = Cursors.Wait;

            /* -----------------------------------------------------------------------
            *  NOTE: We can read barcodes from specific page to increase performance.
            *  For sample please refer to "Decoding barcodes from PDF by pages" program.
            *  ----------------------------------------------------------------------- */

            try
            {
                // Search for barcodes
                reader.ReadFrom(tbFileName.Text);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }

            // Display found barcode inforamtion:

            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < reader.FoundBarcodes.Length; i++)
            {
                FoundBarcode barcode = reader.FoundBarcodes[i];
                stringBuilder.AppendFormat("{0}) Type: {1}; Value: {2}.\r\n", i + 1, barcode.Type, barcode.Value);
            }

            tbFoundBarcodes.Text = stringBuilder.ToString();

            // Cleanup
            reader.Dispose();
        }
Exemple #4
0
        static void Main()
        {
            Console.WriteLine("Reading barcode(s) from PDF document {0}", Path.GetFullPath(InputFIle));

            // Create Bytescout.BarCodeReader.Reader instance
            Reader reader = new Reader();

            reader.RegistrationName = "demo";
            reader.RegistrationKey  = "demo";

            // Set barcode type to find
            reader.BarcodeTypesToFind.Code39 = true;

            // Find barcode in PDF document
            reader.ReadFrom(InputFIle);


            // Method 1: Split PDF document in two parts by found barcode
            // NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only.

            reader.SplitDocument(@"barcodes.pdf", @"part1.pdf", @"part2.pdf", reader.FoundBarcodes[0].Page + 1);


            // Method 2: Extract page containing the barcode from PDF document
            // NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only.

            reader.ExtractPageFromDocument(@"barcodes.pdf", @"extracted_page.pdf", reader.FoundBarcodes[0].Page + 1);


            // Method 3: Split PDF document into parts in one pass.
            // NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only.

            StringBuilder pageRanges = new StringBuilder();

            // Create string containing page ranges to extract in the form "1-4,6-8,10-11,12-". Page numbers are 1-based!
            for (int i = 0; i < reader.FoundBarcodes.Length; i++)
            {
                FoundBarcode barcode = reader.FoundBarcodes[i];

                // Add pages before the first barcode found
                if (i == 0 && barcode.Page > 0)
                {
                    pageRanges.Append("1");
                    if (barcode.Page > 1)
                    {
                        pageRanges.Append("-");
                        pageRanges.Append(barcode.Page);
                    }
                    pageRanges.Append(",");
                }

                // Add page with barcode
                pageRanges.Append(barcode.Page + 1); // +1 because we skip the page with barcode and another +1 because need 1-based page numbers

                // Add range untill the next barcode
                if (i < reader.FoundBarcodes.Length - 1)
                {
                    if (reader.FoundBarcodes[i + 1].Page - barcode.Page > 1)
                    {
                        pageRanges.Append("-");
                        pageRanges.Append(reader.FoundBarcodes[i + 1].Page);
                    }

                    pageRanges.Append(",");
                }
                else // for the last found barcode add ending "-" meaning "to the last page"
                {
                    pageRanges.Append("-");
                }
            }

            // Split document
            string[] splittedParts = reader.SplitDocument(@"barcodes.pdf", pageRanges.ToString());
            // The method returns array of file names. Rename files as desired.
        }
        static void Main()
        {
            Console.WriteLine("Reading barcode(s) from image {0}", Path.GetFullPath(InputFile));

            Reader reader = new Reader();

            reader.RegistrationName = "demo";
            reader.RegistrationKey  = "demo";

            // Set barcode type to find
            reader.BarcodeTypesToFind.PDF417 = true;

            /* -----------------------------------------------------------------------
            *  NOTE: We can read barcodes from specific page to increase performance.
            *  For sample please refer to "Decoding barcodes from PDF by pages" program.
            *  ----------------------------------------------------------------------- */

            // Read barcodes
            FoundBarcode[] barcodes = reader.ReadFrom(InputFile);

            if (barcodes.Length > 0)
            {
                FoundBarcode barcode = barcodes[0];

                // Get specific fields:

                IdentificationCard identificationCard = barcode.Metadata as IdentificationCard;

                if (identificationCard != null)
                {
                    Console.WriteLine("ID Numer: " + identificationCard.IdNumber);
                    Console.WriteLine("First Name: " + identificationCard.Name.First);
                    Console.WriteLine("Middle Name: " + identificationCard.Name.Middle);
                    Console.WriteLine("Last Name: " + identificationCard.Name.Last);
                    Console.WriteLine("Sex: " + identificationCard.Sex);
                    Console.WriteLine("Date Of Birth: " + identificationCard.DateOfBirth);
                    Console.WriteLine("Address: " + identificationCard.Address);

                    if (identificationCard is DriversLicense)
                    {
                        DriversLicense driverLicense = (DriversLicense)identificationCard;

                        Console.WriteLine("Vehicle Class: " + driverLicense.Jurisdiction.VehicleClass);
                        Console.WriteLine("Endorsement Codes: " + driverLicense.Jurisdiction.EndorsementCodes);
                        Console.WriteLine("Restriction Codes: " + driverLicense.Jurisdiction.RestrictionCodes);
                    }
                }
                else
                {
                    Console.WriteLine("Could not retrieve AAMVA data from this barcode. Raw value: \r\n" + barcode.Value);
                }

                // ... or get the full information as JSON:
                Console.WriteLine("\n\n-----------------\n");

                string jsonString = reader.ExportFoundBarcodesToJSON();
                Console.WriteLine(jsonString);
            }
            else
            {
                Console.WriteLine("No barcodes found!");
            }

            // Cleanup
            reader.Dispose();

            Console.WriteLine("Press any key to exit..");
            Console.ReadKey();
        }