How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Barcode Generator Library
How to create, add barcode on existing PDF file using C# .NET. Free open source examples


C# Sample Codes for Creating 1D & 2D Barcodes on PDF Page in C#.NET Imaging Program





In this tutorial, you learn how to create linear and 2d barcode images in PDF file using C#

  • Create Data Matrix, PDF-417 and QR Code 2d barcodes
  • Generate Code 39, Code 128, EAN/UPC, GS1 128 linear barcodes in PDF

How to create barcode images in PDF file using C#

  1. Download XDoc.PDF barcode generator C# library
  2. Install C# library to create barcodes in PDF document
  3. Step by Step Tutorial












C# PDF Barcode Creation Overview

RasterEdge C#.NET PDF Barcode Creation SDK offers mature APIs for developers to generate, write and create 1d and 2d barcodes on PDF document page using C#.NET code. Besides, using this C#.NET barcode creator control package, you can easily adjust and customize most attribute properties of generated barcodes on PDF document file, like color, size and positional parameters.

Details about C# PDF Document Barcode Creation features:

  • 100% C#.NET PDF barcode creating solution compacted in small-sized dlls
  • Mature C# PDF barcode generation controls available for both ASP.NET Web and WinForms programs
  • Compatible with Microsoft .NET Framework from version 2.0 to 4.5
  • Generate over 20 linear and 2d barcodes on PDF document page using C#.NET
  • Create 1d & 2d barcodes on accurate location of PDF document page using C# code for .NET
  • Able to use C#.NET class code to customize created PDF barcode image properties



Supported Barcode Types

Linear Barcodes 2D Barcodes
  • Codabar
  • Code 11
  • Code 2 of 5
  • Code 39
  • Code 128
  • EAN-8
  • EAN-13
  • GS1-128
  • Identcode
  • Intelligent Mail (OneCode)
  • Interleaved 2 of 5
  • ISBN
  • ISSN
  • ITF-14
  • Leitcode
  • MSI Plessey
  • PLANET
  • POSTNET
  • RM4SCC
  • UPC-A
  • UPC-E
  • Data Matrix
  • Micro PDF-417
  • Micro QR Code
  • PDF-417
  • QR Code









How to generate linear barcodes on PDF Page in C#.NET


This is a simple C# example for PDF barcode creation.



// generate a Code 39 barcode
Linear linearBarcode = new Linear();
linearBarcode.Type = BarcodeType.CODE39;
linearBarcode.Data = "123456789";
linearBarcode.Resolution = 96;
linearBarcode.Rotate = Rotate.Rotate0;

// load PDF document, you can also load document like TIFF, Word, Excel & PPT
PDFDocument doc = new PDFDocument(@"c:\sample.pdf");

// get the first page
PDFPage page = (PDFPage)doc.GetPage(0);

// generate reimage of this barcode
Bitmap barcodeImage = linearBarcode.ToImage();

// add barcode image to the first page and the top left vertex of barcode image rectangle is at point(100,100)
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the PDF
doc.Save(@"c:\output.pdf ");






How to create QR Code 2D barcodes using C#.NET


Below are the steps and C# sample code to add QR Code barcode to a PDF page, and add a web link over the QR Code area on page.


  1. Create a QRCode object
  2. Set the QR Code properties
  3. Set the QR Code data value to a web link "https://www.rasteredge.com"
  4. Set QR Code image width and height to 1 inch both.
  5. Create a PDFDocument object from an existing PDF file
  6. Add the qr code to the first page of the PDF document.
  7. Add a link action PDFLinkAction object to jump to a web page
  8. Save the PDF file


//  Create an QRCode
RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();
//  Set QRCode Version
qrcode.Version = RasterEdge.XImage.BarcodeCreator.QRCodeVersion.V1;
//  Set data encoding mode
qrcode.DataMode = RasterEdge.XImage.BarcodeCreator.QRCodeDataMode.Auto;
//  Set error correction level
qrcode.ECL = RasterEdge.XImage.BarcodeCreator.QRCodeECL.M;
//  Set data message to encode
qrcode.Data = "https://www.rasteredge.com";
//  Set barcode size to 1 inch x 1 inch
qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
qrcode.BarcodeWidth = 1F;
qrcode.BarcodeHeight = 1F;
//  Set image resolution to 96 dpi.
qrcode.Resolution = 96;
qrcode.AutoResize = true;
//  Set all margins to 0
qrcode.LeftMargin = 0;
qrcode.RightMargin = 0;
qrcode.TopMargin = 0;
qrcode.BottomMargin = 0;

String inputFilePath = "C:\\1.pdf";
String outputFilePath = "C:\\output.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
//  Draw the barcode at position (100, 200) in pixels on the 1st page.
BasePage page = doc.GetPage(0);
qrcode.DrawBarcode(page, 100, 200);

//  Create and add a link to the same area of the QRCode
PDFLinkAction action = PDFLinkActionURI.Create("https://www.rasteredge.com");
//  Position (100, 200) in pixels; Width 96 pixels, Height 96 pixels
RectangleF area = new RectangleF(100, 200, 96, 96);
PDFLinkSetting link = new PDFLinkSetting(area, action);
//  Add the link to the 1st page.
PDFLinkHandler.AddLink(doc, 0, link);

doc.Save(outputFilePath);