using IronBarCode;
using System;
using System.Drawing; // Include a reference to System.Drawing.Dll
/*** GET STARED WITH BARCODE READING ***/
// Read almost any Barcode or QR in 1 line of Code.
BarcodeResult QRResult = BarcodeReader.QuicklyReadOneBarcode("QR.png");
// Work with the results
if (QRResult != null)
{
string Value = QRResult.Value;
Bitmap Img = QRResult.BarcodeImage;
BarcodeEncoding BarcodeType = QRResult.BarcodeType;
byte[] Binary = QRResult.BinaryValue;
Console.WriteLine(QRResult.Value);
}
// Setting the optional BarcodeEncoding and TryHarder settings will improve performance
BarcodeResult QRBetterResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode, true);
// Multiple Barcode Formats May be Specified using the | Pipe Operator
BarcodeResult FormatsResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode | BarcodeEncoding.PDF417 | BarcodeEncoding.Code128);
/*** READING MULTIPLE BARCODES FROM 1 IMAGE OR PDF DOCUMENT ***/
// Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
BarcodeResult[] PDFResults = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, true);
// Work with the results
foreach (var PDFResult in PDFResults)
{
string Value = PDFResult.Value;
Bitmap Img = PDFResult.BarcodeImage;
BarcodeEncoding BarcodeType = PDFResult.BarcodeType;
byte[] Binary = PDFResult.BinaryValue;
Console.WriteLine(PDFResult.Value);
}
// Multi frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
BarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.None);
// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarCode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);
/*** READING BARCODES FROM ONLY PART OF AN IMAGE OR DOCUMENT ***/
// All BarcodeResult.Read methods all have counterparts that support only scanning for barcodes in specific parts of documents.
// This really helps performance when processing batches of similar documents, forms, tickets, financial documents etc.
System.Drawing.Rectangle MyCropArea = new Rectangle { X = 165, Y = 225, Width = 500, Height = 200 }; // measured in pixels
BarcodeResult[] InvoiceResults = BarcodeReader.ReadAllBarcodesInCropArea("Invoice.Tiff", MyCropArea, BarcodeEncoding.Code128);
// To read barcodes from only 1 or selected pages of a PDF, the ReadBarcodesFromPdfPage and ReadBarcodesFromPdfPages methods can be used.
// Page numbers are 1 based (the first page is 1 not zero)
PagedBarcodeResult[] Page3ScanResults = BarcodeReader.ReadBarcodesFromPdfPage("PileofInvoices.pdf", 3, BarcodeEncoding.PDF417);
Imports IronBarCode
Imports System
Imports System.Drawing ' Include a reference to System.Drawing.Dll
'''* GET STARED WITH BARCODE READING **
' Read almost any Barcode or QR in 1 line of Code.
Private QRResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png")
' Work with the results
If QRResult IsNot Nothing Then
Dim Value As String = QRResult.Value
Dim Img As Bitmap = QRResult.BarcodeImage
Dim BarcodeType As BarcodeEncoding = QRResult.BarcodeType
Dim Binary() As Byte = QRResult.BinaryValue
Console.WriteLine(QRResult.Value)
End If
' Setting the optional BarcodeEncoding and TryHarder settings will improve performance
Dim QRBetterResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode, True)
' Multiple Barcode Formats May be Specified using the | Pipe Operator
Dim FormatsResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QR.png", BarcodeEncoding.QRCode Or BarcodeEncoding.PDF417 Or BarcodeEncoding.Code128)
'''* READING MULTIPLE BARCODES FROM 1 IMAGE OR PDF DOCUMENT **
' Multiple barcodes may be scanned up from a single document or image. A PDF document may also used as the input image
Dim PDFResults() As BarcodeResult = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, True)
' Work with the results
For Each PDFResult In PDFResults
Dim Value As String = PDFResult.Value
Dim Img As Bitmap = PDFResult.BarcodeImage
Dim BarcodeType As BarcodeEncoding = PDFResult.BarcodeType
Dim Binary() As Byte = PDFResult.BinaryValue
Console.WriteLine(PDFResult.Value)
Next PDFResult
' Multi frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
Dim MultiFrameResults() As BarcodeResult = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.None)
' The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarCode.
Dim ListOfDocuments = { "Image1.png", "image2.JPG", "image3.pdf" }
Dim BatchResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments)
'''* READING BARCODES FROM ONLY PART OF AN IMAGE OR DOCUMENT **
' All BarcodeResult.Read methods all have counterparts that support only scanning for barcodes in specific parts of documents.
' This really helps performance when processing batches of similar documents, forms, tickets, financial documents etc.
Dim MyCropArea As System.Drawing.Rectangle = New Rectangle With {
.X = 165,
.Y = 225,
.Width = 500,
.Height = 200
}
Dim InvoiceResults() As BarcodeResult = BarcodeReader.ReadAllBarcodesInCropArea("Invoice.Tiff", MyCropArea, BarcodeEncoding.Code128)
' To read barcodes from only 1 or selected pages of a PDF, the ReadBarcodesFromPdfPage and ReadBarcodesFromPdfPages methods can be used.
' Page numbers are 1 based (the first page is 1 not zero)
Dim Page3ScanResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPage("PileofInvoices.pdf", 3, BarcodeEncoding.PDF417)
using IronBarCode;
/****** WRITE *******/
// Create A Barcode in 1 Line of Code
BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode).SaveAsJpeg("QuickStart.jpg");
/****** READ *******/
// Read A Barcode in 1 Line of Code. Gets Text, Numeric Codes, Binary Data and an Image of the barcode
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg");
// Assert that IronBarCode Works :-)
if (Result!=null && Result.Text == "https://ironsoftware.com/csharp/barcode")
{
System.Console.WriteLine("Success");
}
Imports IronBarCode
'''**** WRITE ******
' Create A Barcode in 1 Line of Code
BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode).SaveAsJpeg("QuickStart.jpg")
'''**** READ ******
' Read A Barcode in 1 Line of Code. Gets Text, Numeric Codes, Binary Data and an Image of the barcode
Dim Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg")
' Assert that IronBarCode Works :-)
If Result IsNot Nothing AndAlso Result.Text = "https://ironsoftware.com/csharp/barcode" Then
System.Console.WriteLine("Success")
End If
using IronBarCode;
/*** READING BARCODES FROM IMPERFECT IMAGES, PHOTOS AND SCANS ***/
// Shorthand:: BarcodeReader.QuicklyReadOneBarcode will automatically try to clean and deskew barcodes from images if you add 'true' as the last TryHarder parameter
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.All, true);
// All BarcodeResult 'Read' methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection - un-skews and removes perspective from barcode images.
// * ImageCorrection - separates Barcodes from background imagery and digital noise.
// * BarcodeEncoding - BarcodeEncoding.Code128 Setting a specific Barcode format improves speed and reduces the risk of false positive results
// Example with a photo image
BarcodeResult PhotoResults = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
// Example with a scanned document as a PDF
PagedBarcodeResult[] ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.QRCode | BarcodeEncoding.PDF417, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);
// Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
Imports IronBarCode
'''* READING BARCODES FROM IMPERFECT IMAGES, PHOTOS AND SCANS **
' Shorthand:: BarcodeReader.QuicklyReadOneBarcode will automatically try to clean and deskew barcodes from images if you add 'true' as the last TryHarder parameter
Private Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.All, True)
' All BarcodeResult 'Read' methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
' * RotationCorrection - un-skews and removes perspective from barcode images.
' * ImageCorrection - separates Barcodes from background imagery and digital noise.
' * BarcodeEncoding - BarcodeEncoding.Code128 Setting a specific Barcode format improves speed and reduces the risk of false positive results
' Example with a photo image
Private PhotoResults As BarcodeResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels)
' Example with a scanned document as a PDF
Private ScanResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.QRCode Or BarcodeEncoding.PDF417, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels)
' Small or 'Thumbnail' barcode images are automatically detected by IronBarCode and corrected for wherever possible even if they have much digital noise.
Private SmallResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128)
using IronBarCode;
using System.Drawing; // Include a reference to System.Drawing.Dll
/*** CREATING BARCODE IMAGES ***/
// Shorthand:: Create and save a barcode in a single line of code
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg");
/***** IN-DEPTH BARCODE CREATION OPTIONS *****/
// BarcodeWriter.CreateBarcode creates a GeneratedBarcode which can be styles and exported as an Image object or File
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("Any Number, String or Binary Value", BarcodeWriterEncoding.Code128);
// Style the Barcode in a fluent LINQ style fashion
MyBarCode.ResizeTo(300, 150).SetMargins(20).AddAnnotationTextAboveBarcode("Example EAN8 Barcode").AddBarcodeValueTextBelowBarcode();
MyBarCode.ChangeBackgroundColor(Color.LightGoldenrodYellow);
// Save MyBarCode as an image file
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
// Save MyBarCode as a .Net native objects
Image MyBarCodeImage = MyBarCode.Image;
Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
byte[] PngBytes = MyBarCode.ToPngBinaryData();
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
// Stream barcode image output also works for GIF,JPEG, PDF, PNG, BMP and TIFF
}
// Save MyBarCode as HTML files and tags
MyBarCode.SaveAsHtmlFile("MyBarCode.Html");
string ImgTagForHTML = MyBarCode.ToHtmlTag();
string DataURL = MyBarCode.ToDataUrl();
// Save MyBarCode to a new PDF, or stamp it in any position on any page(s) of an existing Document
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1); // position 200x50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, new[] { 1, 2, 3 }, "Password123"); // multiple pages of an encrypted PDF
Imports IronBarCode
Imports System.Drawing ' Include a reference to System.Drawing.Dll
'''* CREATING BARCODE IMAGES **
' Shorthand:: Create and save a barcode in a single line of code
BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8).ResizeTo(400, 100).SaveAsImage("EAN8.jpeg")
'''*** IN-DEPTH BARCODE CREATION OPTIONS ****
' BarcodeWriter.CreateBarcode creates a GeneratedBarcode which can be styles and exported as an Image object or File
Dim MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("Any Number, String or Binary Value", BarcodeWriterEncoding.Code128)
' Style the Barcode in a fluent LINQ style fashion
MyBarCode.ResizeTo(300, 150).SetMargins(20).AddAnnotationTextAboveBarcode("Example EAN8 Barcode").AddBarcodeValueTextBelowBarcode()
MyBarCode.ChangeBackgroundColor(Color.LightGoldenrodYellow)
' Save MyBarCode as an image file
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif")
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff")
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
' Save MyBarCode as a .Net native objects
Dim MyBarCodeImage As Image = MyBarCode.Image
Dim MyBarCodeBitmap As Bitmap = MyBarCode.ToBitmap()
Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData()
Using PdfStream As System.IO.Stream = MyBarCode.ToPdfStream()
' Stream barcode image output also works for GIF,JPEG, PDF, PNG, BMP and TIFF
End Using
' Save MyBarCode as HTML files and tags
MyBarCode.SaveAsHtmlFile("MyBarCode.Html")
Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag()
Dim DataURL As String = MyBarCode.ToDataUrl()
' Save MyBarCode to a new PDF, or stamp it in any position on any page(s) of an existing Document
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1) ' position 200x50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, { 1, 2, 3 }, "Password123") ' multiple pages of an encrypted PDF
using IronBarCode;
using System.Drawing; // Include a reference to System.Drawing.Dll
/*** READING BARCODES & BARCODEENCODING ***/
// When reading a barcode we can select One or Many IronBarCode.BarcodeEncoding to read. The fewer chosen the faster the results.
BarcodeResult ResultOneFormat = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.Rss14); // 1 format selected
// Multiple formats can selected using the Bitwise OR (| pipe) operator.
BarcodeResult ResultMultiFormat = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.Rss14 | BarcodeEncoding.UPCA | BarcodeEncoding.QRCode);
// Not specifying a BarcodeEncoding will attempt to read every known type of barcode which is slower and may lead to false positive results in noisy images occasionally
BarcodeResult ResultAnyFormat = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg");
/*** WRITING BARCODES & BARCODEWRITERENCODING ***/
// When creating a barcode we must choose ONE type of barcode using a IronBarCode.BarcodeWriterEncoding
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.UPCA);
// SUPPORTED BARCODE FORMATS:
// * QR Codes including decorated QR Codes with Logos and colors
// * Multi-Format Barcodes: Aztec, Data Matrix, Code 93 and Code 128
// * RSS Expanded "Databar", UPS MaxiCode and USPS IMB OneCode Barcodes (Read-Only)
// * Linear Stacked Barcodes: RSS14 & PDF417
// * Numerical Formats: UPC-A, UPC-E, EAN-8, EAN-13, Codabar, ITF, MSI & Plessey
// BARCODE FORMAT ERROR CORRECTION:
// * BarcodeWriter will automatically check and correct/add Checksums to UPC-A and UPC-E barcodes
// * BarcodeWriter will automatically 'zero pad' numbers which are too short for any fixed length numeric format such as UPC-A
// * If your data can not be encoded to a specific BarcodeWriterEncoding, an IronBarcodeEncodingError with detailed instructions to solve the issue will be raised.
/*** BARCODE EXPORT FORMATS ***/
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");
Image MyBarCodeImage = MyBarCode.Image;
Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
byte[] PngBytes = MyBarCode.ToPngBinaryData();
System.IO.Stream PngStream = MyBarCode.ToStream();
System.IO.Stream PdfStream = MyBarCode.ToPdfStream();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1); // position 200x50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, new[] { 1, 2, 3 }, "Password123"); // multiple pages of an encrypted PDF
Imports IronBarCode
Imports System.Drawing ' Include a reference to System.Drawing.Dll
'''* READING BARCODES & BARCODEENCODING **
' When reading a barcode we can select One or Many IronBarCode.BarcodeEncoding to read. The fewer chosen the faster the results.
Private ResultOneFormat As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.Rss14) ' 1 format selected
' Multiple formats can selected using the Bitwise OR (| pipe) operator.
Private ResultMultiFormat As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg", BarcodeEncoding.Rss14 Or BarcodeEncoding.UPCA Or BarcodeEncoding.QRCode)
' Not specifying a BarcodeEncoding will attempt to read every known type of barcode which is slower and may lead to false positive results in noisy images occasionally
Private ResultAnyFormat As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("QuickStart.jpg")
'''* WRITING BARCODES & BARCODEWRITERENCODING **
' When creating a barcode we must choose ONE type of barcode using a IronBarCode.BarcodeWriterEncoding
Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.UPCA)
' SUPPORTED BARCODE FORMATS:
' * QR Codes including decorated QR Codes with Logos and colors
' * Multi-Format Barcodes: Aztec, Data Matrix, Code 93 and Code 128
' * RSS Expanded "Databar", UPS MaxiCode and USPS IMB OneCode Barcodes (Read-Only)
' * Linear Stacked Barcodes: RSS14 & PDF417
' * Numerical Formats: UPC-A, UPC-E, EAN-8, EAN-13, Codabar, ITF, MSI & Plessey
' BARCODE FORMAT ERROR CORRECTION:
' * BarcodeWriter will automatically check and correct/add Checksums to UPC-A and UPC-E barcodes
' * BarcodeWriter will automatically 'zero pad' numbers which are too short for any fixed length numeric format such as UPC-A
' * If your data can not be encoded to a specific BarcodeWriterEncoding, an IronBarcodeEncodingError with detailed instructions to solve the issue will be raised.
'''* BARCODE EXPORT FORMATS **
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif")
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff")
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")
Dim MyBarCodeImage As Image = MyBarCode.Image
Dim MyBarCodeBitmap As Bitmap = MyBarCode.ToBitmap()
Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData()
Dim PngStream As System.IO.Stream = MyBarCode.ToStream()
Dim PdfStream As System.IO.Stream = MyBarCode.ToPdfStream()
Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag()
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1) ' position 200x50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, { 1, 2, 3 }, "Password123") ' multiple pages of an encrypted PDF
using System;
using IronBarCode;
using System.Drawing; // Include a reference to System.Drawing.Dll
/*** STYING GENERATED BARCODES ***/
// BarcodeWriter.CreateBarcode creates a GeneratedBarcode object which allows the barcode to be styled and annotated.
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("Iron Software", BarcodeWriterEncoding.QRCode);
// Any text (or commonly, the value of the barcode) can be added to the image in a default or specified font.
// Text positions are automatically centered, above or below. Fonts that are too large for a given image are automatically scaled down.
MyBarCode.AddBarcodeValueTextBelowBarcode();
MyBarCode.AddAnnotationTextAboveBarcode("This is My Barcode", new Font(new FontFamily("Arial"), 12, FontStyle.Regular, GraphicsUnit.Pixel), Color.DarkSlateBlue);
// Resize, add Margins and Check final Image Dimensions
MyBarCode.ResizeTo(300, 300); // pixels
MyBarCode.SetMargins(0, 20, 0, 20);
int FinalWidth = MyBarCode.Width;
int FinalHeight = MyBarCode.Height;
//Recolor the barcode and its background
MyBarCode.ChangeBackgroundColor(Color.LightGray);
MyBarCode.ChangeBarCodeColor(Color.DarkSlateBlue);
if (!MyBarCode.Verify())
{
Console.WriteLine("Color contrast should be at least 50% or a barcode may become unreadable. Test using GeneratedBarcode.Verify()");
}
// Finally save the result
MyBarCode.SaveAsHtmlFile("StyledBarcode.html");
/*** STYING BARCODES IN A SINGLE LINQ STYLE EXPRESSION ***/
// Fluent API
BarcodeWriter.CreateBarcode("https://ironsoftware.com", BarcodeWriterEncoding.Aztec).ResizeTo(250, 250).SetMargins(10).AddBarcodeValueTextAboveBarcode().SaveAsImage("StyledBarcode.png");
/*** STYING QR CODES WITH LOGO IMAGES OR BRANDING ***/
// Use the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode
// Logo will automatically be sized appropriately and snapped to the QR grid.
GeneratedBarcode QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://visualstudio.microsoft.com/", "visual-studio-logo.png");
QRWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
QRWithLogo.SaveAsPng("QRWithLogo.Png").SaveAsPdf("MyVerifiedQR.html"); // save as 2 formats
Imports System
Imports IronBarCode
Imports System.Drawing ' Include a reference to System.Drawing.Dll
'''* STYING GENERATED BARCODES **
' BarcodeWriter.CreateBarcode creates a GeneratedBarcode object which allows the barcode to be styled and annotated.
Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("Iron Software", BarcodeWriterEncoding.QRCode)
' Any text (or commonly, the value of the barcode) can be added to the image in a default or specified font.
' Text positions are automatically centered, above or below. Fonts that are too large for a given image are automatically scaled down.
MyBarCode.AddBarcodeValueTextBelowBarcode()
MyBarCode.AddAnnotationTextAboveBarcode("This is My Barcode", New Font(New FontFamily("Arial"), 12, FontStyle.Regular, GraphicsUnit.Pixel), Color.DarkSlateBlue)
' Resize, add Margins and Check final Image Dimensions
MyBarCode.ResizeTo(300, 300) ' pixels
MyBarCode.SetMargins(0, 20, 0, 20)
Dim FinalWidth As Integer = MyBarCode.Width
Dim FinalHeight As Integer = MyBarCode.Height
'Recolor the barcode and its background
MyBarCode.ChangeBackgroundColor(Color.LightGray)
MyBarCode.ChangeBarCodeColor(Color.DarkSlateBlue)
If Not MyBarCode.Verify() Then
Console.WriteLine("Color contrast should be at least 50% or a barcode may become unreadable. Test using GeneratedBarcode.Verify()")
End If
' Finally save the result
MyBarCode.SaveAsHtmlFile("StyledBarcode.html")
'''* STYING BARCODES IN A SINGLE LINQ STYLE EXPRESSION **
' Fluent API
BarcodeWriter.CreateBarcode("https://ironsoftware.com", BarcodeWriterEncoding.Aztec).ResizeTo(250, 250).SetMargins(10).AddBarcodeValueTextAboveBarcode().SaveAsImage("StyledBarcode.png")
'''* STYING QR CODES WITH LOGO IMAGES OR BRANDING **
' Use the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode
' Logo will automatically be sized appropriately and snapped to the QR grid.
Dim QRWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://visualstudio.microsoft.com/", "visual-studio-logo.png")
QRWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen)
QRWithLogo.SaveAsPng("QRWithLogo.Png").SaveAsPdf("MyVerifiedQR.html") ' save as 2 formats
using System;
using IronBarCode;
using System.Drawing; // Include a reference to System.Drawing.Dll
/*** GENERATING QR CODES WITH THE QRCODEWRITER CLASS ***/
// Using the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode exposes additional QR creation options.
// Choosing a high QRCodeWriter.QrErrorCorrectionLevel makes QR codes more fault tolerant and faster to read
GeneratedBarcode RandomQR = QRCodeWriter.CreateQrCode(Guid.NewGuid().ToString(), 500, QRCodeWriter.QrErrorCorrectionLevel.Highest);
RandomQR.AddAnnotationTextAboveBarcode("Your Random Key is" + RandomQR.Value).SaveAsJpeg("RandomQR.jpeg");
/*** STYING QR CODES WITH LOGO IMAGES OR BRANDING ***/
// Use the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode
// Logo will automatically be sized appropriately and snapped to the QR grid.
GeneratedBarcode QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://visualstudio.microsoft.com/", "visual-studio-logo.png");
QRWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen);
QRWithLogo.SaveAsPng("QRWithLogo.Png").SaveAsPdf("MyVerifiedQR.html"); // save as 2 formats
Imports System
Imports IronBarCode
Imports System.Drawing ' Include a reference to System.Drawing.Dll
'''* GENERATING QR CODES WITH THE QRCODEWRITER CLASS **
' Using the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode exposes additional QR creation options.
' Choosing a high QRCodeWriter.QrErrorCorrectionLevel makes QR codes more fault tolerant and faster to read
Private RandomQR As GeneratedBarcode = QRCodeWriter.CreateQrCode(Guid.NewGuid().ToString(), 500, QRCodeWriter.QrErrorCorrectionLevel.Highest)
RandomQR.AddAnnotationTextAboveBarcode("Your Random Key is" & RandomQR.Value).SaveAsJpeg("RandomQR.jpeg")
'''* STYING QR CODES WITH LOGO IMAGES OR BRANDING **
' Use the QRCodeWriter.CreateQrCodeWithLogo Method instead of BarcodeWriter.CreateBarcode
' Logo will automatically be sized appropriately and snapped to the QR grid.
Dim QRWithLogo As GeneratedBarcode = QRCodeWriter.CreateQrCodeWithLogo("https://visualstudio.microsoft.com/", "visual-studio-logo.png")
QRWithLogo.ResizeTo(500, 500).SetMargins(10).ChangeBarCodeColor(Color.DarkGreen)
QRWithLogo.SaveAsPng("QRWithLogo.Png").SaveAsPdf("MyVerifiedQR.html") ' save as 2 formats
using IronBarCode;
/*** EXPORTING BARCODES AS HTML FILES OR TAGS ***/
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);
// Save as a stand-alone HTML file with no image assets required
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
// Save as a stand-alone HTML image tag which can be served in HTML files, ASPX or MVC Views. No image assets required, the tag embeds the entire image in its Src contents
string ImgTag = MyBarCode.ToHtmlTag();
// Turn the image into an Html/CSS Data URI. https://en.wikipedia.org/wiki/Data_URI_scheme
string DataURI = MyBarCode.ToDataUrl();
Imports IronBarCode
'''* EXPORTING BARCODES AS HTML FILES OR TAGS **
Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128)
' Save as a stand-alone HTML file with no image assets required
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
' Save as a stand-alone HTML image tag which can be served in HTML files, ASPX or MVC Views. No image assets required, the tag embeds the entire image in its Src contents
Dim ImgTag As String = MyBarCode.ToHtmlTag()
' Turn the image into an Html/CSS Data URI. https://en.wikipedia.org/wiki/Data_URI_scheme
Dim DataURI As String = MyBarCode.ToDataUrl()
using IronBarCode;
/*** READ BARCODES FROM A PDF DOCUMENT ***/
// A PDF document may be easily scanned for 1 or multiple Barcodes
BarcodeResult[] PDFResults = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, true);
// Read only a specific barcode type
BarcodeResult[] InvoiceResults = BarcodeReader.ReadBarcodesFromPdf("PileofInvoices.pdf", BarcodeEncoding.Code128);
// Read only specific pages
PagedBarcodeResult[] InvoiceResultsPage123 = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.pdf", new[] { 1, 2, 3 }, BarcodeEncoding.Code128);
// Read even from badly scanned or noisy PDFs
PagedBarcodeResult[] InvoiceResultsCorrected = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.BadScan.pdf", new[] { 1, 2, 3 }, BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.CleanNonBlackPixels);
/*** WRITE BARCODES TO A NEW OR EXISTING PDF DOCUMENT ***/
GeneratedBarcode MyBarCode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128);
// Save to a new PDF
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
/// Add the barcode to any page or pages of an existing PDF
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1); // position x=200 y=50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, new[] { 1, 2, 3 }, "Password123"); // multiple pages of an encrypted PDF
Imports IronBarCode
'''* READ BARCODES FROM A PDF DOCUMENT **
' A PDF document may be easily scanned for 1 or multiple Barcodes
Private PDFResults() As BarcodeResult = BarcodeReader.QuicklyReadAllBarcodes("MultipleBarcodes.pdf", BarcodeEncoding.AllOneDimensional, True)
' Read only a specific barcode type
Private InvoiceResults() As BarcodeResult = BarcodeReader.ReadBarcodesFromPdf("PileofInvoices.pdf", BarcodeEncoding.Code128)
' Read only specific pages
Private InvoiceResultsPage123() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.pdf", { 1, 2, 3 }, BarcodeEncoding.Code128)
' Read even from badly scanned or noisy PDFs
Private InvoiceResultsCorrected() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdfPages("PileofInvoices.BadScan.pdf", { 1, 2, 3 }, BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.CleanNonBlackPixels)
'''* WRITE BARCODES TO A NEW OR EXISTING PDF DOCUMENT **
Private MyBarCode As GeneratedBarcode = BarcodeWriter.CreateBarcode("1234567890", BarcodeWriterEncoding.Code128)
' Save to a new PDF
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
''' Add the barcode to any page or pages of an existing PDF
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 200, 50, 1) ' position x=200 y=50 on page 1
MyBarCode.StampToExistingPdfPages("ExistingPDF.pdf", 200, 50, { 1, 2, 3 }, "Password123") ' multiple pages of an encrypted PDF
Install-Package BarCode
Have a question? Get in touch with our development team.