How to Export Barcodes as PDF
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.
How to Export Barcodes as PDF in C#
- Download C# library to Export Barcodes as PDFs in C#
- Export Barcodes as PDF File
- Export Barcodes as PDF Binary Data
- Export Barcodes as PDF Stream
Start using IronBarcode in your project today with a free trial.
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")
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()
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()