C# Barcode Generator Library
How to create, export barcode to PDF?


How to create QR Code and barcode image to new PDF file in C# ASP.NET Core, MVC, WinForms, WPF apps?













How to create barcode images to new PDF file using C#?


One of the most important function in XImage.Barcode Generator C# library is to create barcode and export to PDF. Here we will show how to create barcode as raster image, and export to PDF in three methods: export barcode to PDF files, to PDF in Stream object, and PDF to binary data.



Create, export barcode to PDF file


Now we will explain how to create a new barcode object with options applied, and export the barcode to a new PDF file using C# barcode generator library.

  1. Create a new Linear object with barcode options applied, such as barcode format, data to encode, barcode dimension width and height.
  2. Store the barcode image data to a Bitmap object
  3. Create a new PDFDocument object with the barcode bitmap object loaded
  4. Call method PDFDocument.Save() to save the PDF file with barcode generated.



            Linear barcode = new Linear();
            barcode.Type = BarcodeType.CODE128;
            barcode.Data = "ABC-12345-abc";

            barcode.AutoResize = true;
            barcode.Resolution = 1200;
            barcode.UOM = UnitOfMeasure.INCH;
            barcode.BarcodeWidth = 2;
            barcode.BarcodeHeight = 1f;

            Bitmap bitmap = barcode.ToImage();
            PDFDocument doc = new PDFDocument(new Bitmap[] { bitmap });
            doc.Save(@"C:\Output\RasterEdge.com\demo-create-barcode-new-pdf.pdf");


Create, export barcode to PDF in Stream object


Here we will show you how to create barcode and export it to a new PDF document in Stream object. You can work on the PDF in your C# program.

  1. Get the barcode in Bitmap object with barcode options customized.
  2. Create a new PDFDocument object with the barcode bitmap object loaded
  3. Call method PDFDocument.SaveToStream() to store PDF document to the Stream object



            Bitmap bitmap = barcode.ToImage();
            PDFDocument doc = new PDFDocument(new Bitmap[] { bitmap });
            Stream pdfInStream = new MemoryStream();
            doc.SaveToStream(pdfInStream);


Create, export barcode to PDF in Binary Data byte[] in C#


After you have customized and applied barcode options in C#, you can now create and export barcode to PDF document in Binary Data.

  1. Create a new PDFDocument object with barcode bitmap loaded
  2. Call method PDFDocument.SaveToBytes() to get the PDF document in binary data byte array



            Bitmap bitmap = barcode.ToImage();
            PDFDocument doc = new PDFDocument(new Bitmap[] { bitmap });
            byte[] pdfInBytes = doc.SaveToBytes();






How to create barcode vector image (EPS) to new PDF file using C#?


Coming soon.

XImage.Barcode Generator supports generating barcode images in EPS format. We are working on inserting EPS file to PDF pages.