How to Export Barcodes as PDF

by Hairil Hasyimi Bin Omar

In this article, we'll explore how we can use IronBarcode to export barcodes to PDF. With IronBarcode, barcodes can be exported as either a file, binary data, or memory stream.

Start using IronBarcode in your project today with a free trial.

First Step:
green arrow pointer



Export Barcodes as PDF File

To save a barcode as a PDF file, first create a GeneratedBarcode object with BarcodeWriter.CreateBarcode and then use the SaveAsPdf() method to convert and save a file to disk. The following code snippet demonstrates how this works.

:path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfFile.cs
using IronBarCode;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix);
myBarcode.SaveAsPdf("myBarcode.pdf");
Imports IronBarCode

Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix)
myBarcode.SaveAsPdf("myBarcode.pdf")
VB   C#

Export Barcodes as PDF Binary Data

To export as PDF binary data, generate a barcode and then call the ToPdfBinaryData()—the outputs the PDF binary data as a byte[] array. The following code snippet demonstrates how this works.

:path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfBinaryData.cs
using IronBarCode;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix);
byte[] myBarcodeByte = myBarcode.ToPdfBinaryData();
Imports IronBarCode

Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix)
Private myBarcodeByte() As Byte = myBarcode.ToPdfBinaryData()
VB   C#

Export Barcodes as PDF Stream

To export as a memory stream, generate a barcode and then call the ToPdfStream() method. This method returns a System.IO.Stream object. The following code snippet demonstrates how this works.

:path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfStream.cs
using IronBarCode;
using System.IO;

GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix);
Stream myBarcodeStream = myBarcode.ToPdfStream();
Imports IronBarCode
Imports System.IO

Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix)
Private myBarcodeStream As Stream = myBarcode.ToPdfStream()
VB   C#
Hairil related to Export Barcodes as PDF Stream

Hairil Hasyimi Bin Omar

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.