IronBarcode How-Tos Create Barcode from Text, URLs, IDs, Numbers & Binary Data Create Barcode from Text, URLs, IDs, Numbers, Binary Data & Memory Streams ByHairil Hasyimi Bin Omar August 15, 2023 Updated June 22, 2025 Share: Barcodes can be generated from strings, binary data, or memory streams. These data formats can be used as input in the BarcodeWriter.CreateBarcode() method. View the IronBarcode YouTube Playlist Barcodes can be generated from strings, binary data, or memory streams. These data formats can be used as input in the BarcodeWriter.CreateBarcode() method. Create Barcode from Text, URLs, IDs, Numbers, Binary Data & Memory Streams Download the C# library to create barcode from data Create barcodes with System.String input using the CreateBarcode method Create barcodes with System.Byte[] input using the CreateBarcode method Create barcodes with System.IO.Stream input using the CreateBarcode method Save the resulting barcode in multiple image formats Get started with IronBarcode Start using IronBarcode in your project today with a free trial. First Step: Start for Free Create Barcode From String The following code snippet demonstrates how to write barcodes with a string: :path=/static-assets/barcode/content-code-examples/how-to/create-barcode-from-string.cs // Import the IronBarCode library to enable barcode creation using IronBarCode; // Define the text and URL to be encoded into barcodes string text = "Hello, World!"; string url = "https://ironsoftware.com/csharp/barcode/"; // Define identifiers to be encoded string receiptID = "2023-08-04-12345"; // Receipt ID (numeric id) string flightID = "FLT2023NYC-LAX123456"; // Flight ID (alphanumeric id) string number = "1234"; // Some numeric identifier // Create an Aztec barcode from the text and save it as a PNG file var aztecBarcode = BarcodeWriter.CreateBarcode(text, BarcodeEncoding.Aztec); // Save the Aztec barcode image to a file aztecBarcode.SaveAsPng("text.png"); // Create a QR code from the URL and save it as a PNG file var qrCode = BarcodeWriter.CreateBarcode(url, BarcodeEncoding.QRCode); // Save the QR code image to a file qrCode.SaveAsPng("url.png"); // Create a Code93 barcode from the receipt ID, set dimensions, and save as a PNG file var code93Barcode = BarcodeWriter.CreateBarcode(receiptID, BarcodeEncoding.Code93, 250, 67); // Save the Code93 barcode image to a file code93Barcode.SaveAsPng("receiptID.png"); // Create a PDF417 barcode from the flight ID, set dimensions, and save as a PNG file var pdf417Barcode = BarcodeWriter.CreateBarcode(flightID, BarcodeEncoding.PDF417, 250, 67); // Save the PDF417 barcode image to a file pdf417Barcode.SaveAsPng("flightID.png"); // Create a Codabar barcode from the number, set dimensions, and save as a PNG file var codabar = BarcodeWriter.CreateBarcode(number, BarcodeEncoding.Codabar, 250, 67); // Save the Codabar barcode image to a file codabar.SaveAsPng("number.png"); ' Import the IronBarCode library to enable barcode creation Imports IronBarCode ' Define the text and URL to be encoded into barcodes Private text As String = "Hello, World!" Private url As String = "https://ironsoftware.com/csharp/barcode/" ' Define identifiers to be encoded Private receiptID As String = "2023-08-04-12345" ' Receipt ID (numeric id) Private flightID As String = "FLT2023NYC-LAX123456" ' Flight ID (alphanumeric id) Private number As String = "1234" ' Some numeric identifier ' Create an Aztec barcode from the text and save it as a PNG file Private aztecBarcode = BarcodeWriter.CreateBarcode(text, BarcodeEncoding.Aztec) ' Save the Aztec barcode image to a file aztecBarcode.SaveAsPng("text.png") ' Create a QR code from the URL and save it as a PNG file Dim qrCode = BarcodeWriter.CreateBarcode(url, BarcodeEncoding.QRCode) ' Save the QR code image to a file qrCode.SaveAsPng("url.png") ' Create a Code93 barcode from the receipt ID, set dimensions, and save as a PNG file Dim code93Barcode = BarcodeWriter.CreateBarcode(receiptID, BarcodeEncoding.Code93, 250, 67) ' Save the Code93 barcode image to a file code93Barcode.SaveAsPng("receiptID.png") ' Create a PDF417 barcode from the flight ID, set dimensions, and save as a PNG file Dim pdf417Barcode = BarcodeWriter.CreateBarcode(flightID, BarcodeEncoding.PDF417, 250, 67) ' Save the PDF417 barcode image to a file pdf417Barcode.SaveAsPng("flightID.png") ' Create a Codabar barcode from the number, set dimensions, and save as a PNG file Dim codabar = BarcodeWriter.CreateBarcode(number, BarcodeEncoding.Codabar, 250, 67) ' Save the Codabar barcode image to a file codabar.SaveAsPng("number.png") $vbLabelText $csharpLabel In this code snippet, we encode five different examples of data into five different barcode types: simple text to Aztec, URL to QR Code, a numeric ID to Code 93, an alphanumeric ID to PDF417, and a number to Codabar. The images are then saved as PNG. Text URL Receipt ID Flight ID Number Create Barcode From Byte Array To create barcodes from data from a byte array, ensure the character encoding aligns with the required BarcodeEncoding, since each barcode type accepts a different character encoding. Here are the different character encodings that can be used in IronBarcode: ASCII (American Standard Code for Information Interchange): Uses 7 bits to represent each character, including English letters, digits, punctuation, and control characters. Example: The ASCII code for the letter 'A' is 65, 'B' is 66, and so on. UTF-8 (Unicode Transformation Format 8-bit): UTF-8 is a variable-length character encoding that can represent all Unicode characters. Example: The UTF-8 encoding of the Euro symbol (€) is the sequence 0xE2 0x82 0xAC. UTF-16 (Unicode Transformation Format 16-bit): Uses 16-bit sequences to encode characters, representing the entire Unicode character set. Example: The UTF-16 encoding of the Greek letter alpha (α) is 0x03B1. UTF-32 (Unicode Transformation Format 32-bit): Uses a fixed 32-bit sequence for each character. Example: The UTF-32 encoding of the Greek letter alpha (α) is 0x000003B1. ISO-8859-1 (Latin-1): Extends ASCII to include characters from Western European languages, using 8 bits for each character. Example: The ISO-8859-1 code for 'é' is 233. [{i:The default character encoding in IronBarcode is ISO-8859-1.}] The following code snippet demonstrates generating a barcode from byte data: :path=/static-assets/barcode/content-code-examples/how-to/create-barcode-from-byte.cs using IronBarCode; using System.Text; // Program to generate various types of barcodes and save them as PNG files // Convert text data to byte arrays using UTF8 encoding byte[] text = Encoding.UTF8.GetBytes("Hello, World!"); // A simple text message byte[] url = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/"); // URL to encode as a QR Code byte[] receiptID = Encoding.UTF8.GetBytes("2023-08-04-12345"); // Receipt ID in numeric format byte[] flightID = Encoding.UTF8.GetBytes("FLT2023NYC-LAX123456"); // Flight ID in alphanumeric format byte[] number = Encoding.UTF8.GetBytes("1234"); // Simple numeric code // Generate barcodes for each byte array and save as PNG images // 1. Aztec Barcode for 'text' // The Aztec encoding can encode both text and binary data efficiently BarcodeWriter.CreateBarcode(text, BarcodeEncoding.Aztec).SaveAsPng("text.png"); // 2. QR Code for 'url' // QR codes have high data capacity for URLs BarcodeWriter.CreateBarcode(url, BarcodeEncoding.QRCode).SaveAsPng("url.png"); // 3. Code 93 Barcode for 'receiptID' with specific dimensions // Code 93 is a high-density barcode for alphanumeric and numeric data BarcodeWriter.CreateBarcode(receiptID, BarcodeEncoding.Code93, 250, 67).SaveAsPng("receiptID.png"); // 4. PDF417 Barcode for 'flightID' with specific dimensions // PDF417 is a versatile 2D barcode format used for various types of information storage BarcodeWriter.CreateBarcode(flightID, BarcodeEncoding.PDF417, 250, 67).SaveAsPng("flightID.png"); // 5. Codabar Barcode for 'number' with specific dimensions // Codabar is often used in libraries, blood banks, and FedEx for simple numeric codes BarcodeWriter.CreateBarcode(number, BarcodeEncoding.Codabar, 250, 67).SaveAsPng("number.png"); Imports IronBarCode Imports System.Text ' Program to generate various types of barcodes and save them as PNG files ' Convert text data to byte arrays using UTF8 encoding Private text() As Byte = Encoding.UTF8.GetBytes("Hello, World!") ' A simple text message Private url() As Byte = Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/") ' URL to encode as a QR Code Private receiptID() As Byte = Encoding.UTF8.GetBytes("2023-08-04-12345") ' Receipt ID in numeric format Private flightID() As Byte = Encoding.UTF8.GetBytes("FLT2023NYC-LAX123456") ' Flight ID in alphanumeric format Private number() As Byte = Encoding.UTF8.GetBytes("1234") ' Simple numeric code ' Generate barcodes for each byte array and save as PNG images ' 1. Aztec Barcode for 'text' ' The Aztec encoding can encode both text and binary data efficiently BarcodeWriter.CreateBarcode(text, BarcodeEncoding.Aztec).SaveAsPng("text.png") ' 2. QR Code for 'url' ' QR codes have high data capacity for URLs BarcodeWriter.CreateBarcode(url, BarcodeEncoding.QRCode).SaveAsPng("url.png") ' 3. Code 93 Barcode for 'receiptID' with specific dimensions ' Code 93 is a high-density barcode for alphanumeric and numeric data BarcodeWriter.CreateBarcode(receiptID, BarcodeEncoding.Code93, 250, 67).SaveAsPng("receiptID.png") ' 4. PDF417 Barcode for 'flightID' with specific dimensions ' PDF417 is a versatile 2D barcode format used for various types of information storage BarcodeWriter.CreateBarcode(flightID, BarcodeEncoding.PDF417, 250, 67).SaveAsPng("flightID.png") ' 5. Codabar Barcode for 'number' with specific dimensions ' Codabar is often used in libraries, blood banks, and FedEx for simple numeric codes BarcodeWriter.CreateBarcode(number, BarcodeEncoding.Codabar, 250, 67).SaveAsPng("number.png") $vbLabelText $csharpLabel In the given snippet, 5 string inputs are transformed into a System.Byte[] object. To convert these byte arrays into barcodes, include them as parameters in BarcodeWriter, along with the desired BarcodeEncoding. Optionally, set MaxWidth and MaxHeight for barcode size. Create Barcode From Memory Stream The following code snippet demonstrates how to generate a barcode from a memory stream: :path=/static-assets/barcode/content-code-examples/how-to/create-barcode-from-stream.cs using IronBarCode; // Import the IronBarCode library for barcode generation using System.IO; // Import System.IO to work with MemoryStream using System.Text; // Import System.Text for encoding support // Create MemoryStreams containing UTF-8 encoded byte arrays from the given strings MemoryStream text = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")); MemoryStream url = new MemoryStream(Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/")); MemoryStream receiptID = new MemoryStream(Encoding.UTF8.GetBytes("2023-08-04-12345")); // Receipt ID (numeric id) MemoryStream flightID = new MemoryStream(Encoding.UTF8.GetBytes("FLT2023NYC-LAX123456")); // Flight id (alphanumeric id) MemoryStream number = new MemoryStream(Encoding.UTF8.GetBytes("1234")); // Example numeric ID // Generate an Aztec barcode from the text MemoryStream and save it as a PNG file BarcodeWriter.CreateBarcode(text.ToArray(), BarcodeEncoding.Aztec).SaveAsPng("text.png"); // Generate a QR Code from the URL MemoryStream and save it as a PNG file BarcodeWriter.CreateBarcode(url.ToArray(), BarcodeEncoding.QRCode).SaveAsPng("url.png"); // Generate a Code-93 barcode for the receipt ID MemoryStream and save it as a PNG file // The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(receiptID.ToArray(), BarcodeEncoding.Code93, 250, 67).SaveAsPng("receiptID.png"); // Generate a PDF417 barcode for the flight ID MemoryStream and save it as a PNG file // The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(flightID.ToArray(), BarcodeEncoding.PDF417, 250, 67).SaveAsPng("flightID.png"); // Generate a Codabar barcode for the number MemoryStream and save it as a PNG file // The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(number.ToArray(), BarcodeEncoding.Codabar, 250, 67).SaveAsPng("number.png"); Imports IronBarCode ' Import the IronBarCode library for barcode generation Imports System.IO ' Import System.IO to work with MemoryStream Imports System.Text ' Import System.Text for encoding support ' Create MemoryStreams containing UTF-8 encoded byte arrays from the given strings Private text As New MemoryStream(Encoding.UTF8.GetBytes("Hello, World!")) Private url As New MemoryStream(Encoding.UTF8.GetBytes("https://ironsoftware.com/csharp/barcode/")) Private receiptID As New MemoryStream(Encoding.UTF8.GetBytes("2023-08-04-12345")) ' Receipt ID (numeric id) Private flightID As New MemoryStream(Encoding.UTF8.GetBytes("FLT2023NYC-LAX123456")) ' Flight id (alphanumeric id) Private number As New MemoryStream(Encoding.UTF8.GetBytes("1234")) ' Example numeric ID ' Generate an Aztec barcode from the text MemoryStream and save it as a PNG file BarcodeWriter.CreateBarcode(text.ToArray(), BarcodeEncoding.Aztec).SaveAsPng("text.png") ' Generate a QR Code from the URL MemoryStream and save it as a PNG file BarcodeWriter.CreateBarcode(url.ToArray(), BarcodeEncoding.QRCode).SaveAsPng("url.png") ' Generate a Code-93 barcode for the receipt ID MemoryStream and save it as a PNG file ' The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(receiptID.ToArray(), BarcodeEncoding.Code93, 250, 67).SaveAsPng("receiptID.png") ' Generate a PDF417 barcode for the flight ID MemoryStream and save it as a PNG file ' The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(flightID.ToArray(), BarcodeEncoding.PDF417, 250, 67).SaveAsPng("flightID.png") ' Generate a Codabar barcode for the number MemoryStream and save it as a PNG file ' The barcode is resized to specified dimensions (width: 250, height: 67) BarcodeWriter.CreateBarcode(number.ToArray(), BarcodeEncoding.Codabar, 250, 67).SaveAsPng("number.png") $vbLabelText $csharpLabel In this snippet, a MemoryStream is created from a System.Byte[] object. This MemoryStream is then used as input in BarcodeWriter.CreateBarcode(), generating a barcode from memory stream data. Frequently Asked Questions How can I create a barcode from a string? You can use the BarcodeWriter.CreateBarcode method from IronBarcode, providing a string as input. For example, to encode 'Hello, World!' to an Aztec barcode, you would call: BarcodeWriter.CreateBarcode('Hello, World!', BarcodeEncoding.Aztec). What barcode types can be created from a URL? URLs can be encoded into different barcode types using IronBarcode, such as QR Code. For example, using BarcodeWriter.CreateBarcode('https://example.com', BarcodeEncoding.QRCode) will generate a QR Code from a URL. What character encodings are supported for creating barcodes from byte arrays? IronBarcode supports multiple character encodings including ASCII, UTF-8, UTF-16, UTF-32, and ISO-8859-1. You can choose the appropriate encoding based on your data and the barcode type. How do I generate a barcode from a memory stream? To generate a barcode from a memory stream using IronBarcode, first convert your data into a byte array, then create a MemoryStream from it. Use the BarcodeWriter.CreateBarcode method with the MemoryStream as input. Can I save the generated barcode images in different formats? Yes, using IronBarcode, the resulting barcodes can be saved in multiple image formats. In the examples provided, the barcodes are saved as PNG files using the SaveAsPng method. What is the default character encoding used? The default character encoding in IronBarcode is ISO-8859-1. Hairil Hasyimi Bin Omar Chat with engineering team now Software Engineer Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree in Chemical and Process Engineering. Ready to Get Started? Free NuGet Download Total downloads: 1,737,581 View Licenses