Free Trial
Web API version
Licensing
Request A Quote
HAVE QUESTIONS OR NEED HELP? SUBMIT THE SUPPORT REQUEST FORM or write email to SUPPORT@BYTESCOUT.COM
Download and Process file | C#
Program.cs:
C#
using System; using System.IO; using Bytescout.BarCodeReader; namespace BarcodesFromPDF { class Program { static void Main() { Reader reader = new Reader(); reader.RegistrationName = "demo"; reader.RegistrationKey = "demo"; // Limit search to 1-dimensional barcodes only (exclude 2D barcodes to speed up the processing). // Change to barcodeReader.BarcodeTypesToFind.SetAll() to scan for all supported 1D and 2D barcode types // or select specific type, e.g. barcodeReader.BarcodeTypesToFind.PDF417 = True reader.BarcodeTypesToFind.All1D = true; Console.WriteLine("Reading barcodes from PDF document..."); /* ----------------------------------------------------------------------- NOTE: We can read barcodes from specific page to increase performance. For sample please refer to "Decoding barcodes from PDF by pages" program. ----------------------------------------------------------------------- */ // Input url of pdf document containing barcodes string inputUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf"; // Get memory stream from url var oStream = GetStreamFromUrl(inputUrl); // Read from input stream reader.ReadFromStream(oStream); foreach (FoundBarcode barcode in reader.FoundBarcodes) { Console.WriteLine("Found barcode with type '{0}' and value '{1}' on page {2} at {3}", barcode.Type, barcode.Value, barcode.Page, barcode.Rect); } // Cleanup reader.Dispose(); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } /// <summary> /// Get stream from Url /// </summary> private static Stream GetStreamFromUrl(string url) { byte[] oData = null; using (var wc = new System.Net.WebClient()) oData = wc.DownloadData(url); return new MemoryStream(oData); } } }