C# QR Code Generator Library
QR Code Image Generation Tutorial


Create QR Code Barcode on C# Images, TIFF, PDF, Word, Excel and PowerPoint





In this C# tutorial, you will learn how to create a QR Code 2d barcode image using C# in ASP.NET MVC Web, Windows applications.

  • Generate high quality QR Code barcode images
  • Advanced options for barcode size, barcode color, and QR Code data encoding
  • Generate GS1 compatible QR Code, and QR Code for international text
  • Draw, print QR Code in PNG, JPG, and Bitmap raster images
  • Create QR Code in PDF, TIFF, Office Word, Excel, PowerPoint files

How to create a QR Code in JPG, PDF, Tiff, Word, BMP file using C#

  1. Download XImage.Barcode Generator C# library
  2. Install C# library to draw QR Code barcodes
  3. Step by Step Tutorial










By using this .NET QR Code barcode generator add-on component, developers can create & draw scannable QR Codes on different image files (png, jpeg, gif and bmp) and insert them into common documents like TIFF, PDF, MS Word, Excel and PowerPoint using Visual C#.NET programming code. Following are some barcoding features offered by this .NET QR Code encoder DLL.

Related .net document control helps:
asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net pdf page: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net edit pdf text: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET
asp.net edit pdf image: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#
asp.net document viewer c#: ASP.NET Document Viewer using C#: Open, View, Annotate, Redact, Convert document files in ASP.NET using C#, HTML5, JQuer...



  • Written in C# managed code, compatible with .NET Framework 2.0 and above
  • Generating, writing QR Code bar codes on PNG, JPG, GIF, and BMP image files with specified location
  • C# tutorial and sample codes to draw, insert QR Codes in PDF, TIFF, MS Word, Excel and PowerPoint
  • Control QR Code barcode size by setting size related properties
  • Use C# code to adjust bar code image format, location, resolution, orientation, version, color and more
  • Compatible with ISO+IEC+18004 QR Code bar code symbology specification






QR Code barcode data encoding in C#


Encode character set and QR Code data mode

QR Code support encoding the following characters.

  • Numeric data (digits 0 - 9)
  • Alphanumeric data (0 - 9; A -Z; nine other characters: space, $ % * + - . / : )
  • Byte data
  • Kanji characters



QR Code data mode

To encode the above character sets, QR Code defines five encoding data modes.

  • Auto
  • Numeric
  • AlphaNumeric
  • Byte
  • Kanji



QR Code maximum data length

Maximum characters per QR Code barcode with Version 40-L

  • numeric data: 7,089 characters
  • alphanumeric data: 4,296 characters
  • byte data: 2,953 characters
  • Kanji data: 1,817 characters



QR Code error correction mode

Four levels of Reed-Solomon error correction (referred to as L, M, Q and H in increasing order of capacity) allowing recovery of the QR Code barcode data.

Using XImage.Barcode Generator C# library, class QRCode has provided the property ECL. You can set one of the following values from RasterEdge.XImage.BarcodeCreator.QRCodeECL

  • L: 7% (QRCodeECL.H)
  • M: 15% (QRCodeECL.M)
  • Q: 25% (QRCodeECL.Q)
  • H: 30% (QRCodeECL.H)







QR Code Special Characters Encoding using C#




How to generate GS1 QR Code using C#

GS1 QR Code barcode is a standalone, two-dimensional matrix symbology that is made up of square modules arranged in an overall square pattern, including a unique finder pattern located at three corners of the barcode symbol.

To create valid GS1 QR Code using C# QR Code library, you need apply the following properties with valid value or formats.

  • FNC1: The value should be RasterEdge.XImage.BarcodeCreator.FNC1.FNC1_1ST_POS.
  • Data: Valid GS1 data message includes pairs of AI code and AI data. Using QR Code C# library, all AI codes should be surrounded by parentheses. For example: (11)010101(15)020202



How to encode Kanji characters in QR Code using C#

Apply the following settings to encode Kanji characters in QR Code C# barcode generator library:

  • ProcessTilde: Set to enable '~' in data message.
  • DataMode:It should be RasterEdge.XImage.BarcodeCreator.QRCodeDataMode.Kanji



How to encode international characters in QR Code using C#

To encode international characters in QR Code, you need convert internation text to byte array using UTF-8 encode, and generate QR Code using byte mode.

Following properties should be applied to generate international characters in QR Code using C#:

  • ProcessTilde: Set to enable '~' in data message.
  • DataMode:It should be RasterEdge.XImage.BarcodeCreator.QRCodeDataMode.Byte
  • Data: The international characters should be converted to byte array using UTF8 encoding.



            RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();

            string message = "สวัสดี";
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            StringBuilder messageInBytes = new StringBuilder();
            foreach (byte b in bytes)
                messageInBytes.Append("~" + b.ToString().PadLeft(3, '0'));

            qrcode.Data = messageInBytes.ToString();
            qrcode.ProcessTilde = true;
            qrcode.DataMode = RasterEdge.XImage.BarcodeCreator.QRCodeDataMode.Byte;

            //  Set barcode size to 2 inch x 2 inch
            qrcode.AutoResize = true;
            qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            qrcode.BarcodeWidth = 2F;
            qrcode.BarcodeHeight = 2F;
            //  Set image resolution to 300 dpi.
            qrcode.Resolution = 300;

            //  Set all margins to 0
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;

            Bitmap qrcodeBitmap = qrcode.ToImage();
            qrcodeBitmap.Save(@"W:\Projects\Test-Output\RasterEdge.com\barcode-qrcode-international-byte.png");






How to create QR Code barcode in PDF file with web link added using C#.NET


The following content and C# sample source code to show how to create QR Code barcode in an existing PDF file, and create, insert a web link on the QR Code in the PDF document using C#.NET

  1. Create a new QRCode object
  2. Set QR Code encoding data "https://www.rasteredge.com".
  3. Set QR Code barcode size options
  4. Create a new PDFDocument from an existing PDF file
  5. Get a new PDFPage object from the first page of the PDF document
  6. Generate and print QR Code on the PDFPage object
  7. Create a new PDFLinkAction object to add a web link to PDF page
  8. Set the web link position and area which is the same position and area as QR Code
  9. Add, insert the web link object to the PDF page
  10. Save the PDF file


Note: web link covered area width and height calculation is based on PDF document default resolution (96 dpi). Two inch is 192 dpi.



            RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();

            qrcode.Data = "https://www.rasteredge.com";
            qrcode.DataMode = RasterEdge.XImage.BarcodeCreator.QRCodeDataMode.Auto;

            //  Set barcode size to 2 inch x 2 inch
            qrcode.AutoResize = true;
            qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            qrcode.BarcodeWidth = 2F;
            qrcode.BarcodeHeight = 2F;
            //  Set image resolution to 300 dpi.
            qrcode.Resolution = 300;

            //  Set all margins to 0
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\XDoc.PDF Overview.pdf";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-qrcode-pdf.pdf";

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


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

            doc.Save(outputFilePath);






How to generate QR Code barcode in TIFF file using C#.NET


The following C# source code explains how to create QR Code barcode in an existing Tiff file using C#.NET



            RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();

            qrcode.Data = "https://www.rasteredge.com";

            //  Set barcode size to 2 inch x 2 inch
            qrcode.AutoResize = true;
            qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            qrcode.BarcodeWidth = 2F;
            qrcode.BarcodeHeight = 2F;
            //  Set image resolution to 300 dpi.
            qrcode.Resolution = 300;

            //  Set all margins to 0
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\XDoc.PDF Overview.tiff";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-qrcode-tiff.tiff";

            TIFFDocument tiffDoc = new TIFFDocument(inputFilePath);

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

            tiffDoc.Save(outputFilePath);






How to generate QR Code in Office Word, Excel, PowerPoint files using C#.NET


The following C# source code explains how to generate, insert QR Code barcode in a Word (.docx) file using C#.NET



            RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();

            qrcode.Data = "https://www.rasteredge.com";

            //  Set barcode size to 1 inch x 1 inch
            qrcode.AutoResize = true;
            qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            qrcode.BarcodeWidth = 1F;
            qrcode.BarcodeHeight = 1F;
            //  Set image resolution to 300 dpi.
            qrcode.Resolution = 300;

            //  Set all margins to 0
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\word-empty.docx";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-qrcode-word.docx";

            DOCXDocument doc = new DOCXDocument(inputFilePath);

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

            REImage image = new REImage(qrcode.ToImage());
            page.AddImage(image, new PointF(100F, 200F));

            doc.Save(outputFilePath);






How to draw, print QR Code in JPG, PNG, Bitmap images using C#.NET


The C# sample code below shows how to generate, draw QR Code barcode in an image file (JPG, PNG, or BMP) using C#.NET



            RasterEdge.XImage.BarcodeCreator.QRCode qrcode = new RasterEdge.XImage.BarcodeCreator.QRCode();

            qrcode.Data = "https://www.rasteredge.com";

            //  Set barcode size to 2 inch x 2 inch
            qrcode.AutoResize = true;
            qrcode.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            qrcode.BarcodeWidth = 2F;
            qrcode.BarcodeHeight = 2F;
            //  Set image resolution to 300 dpi.
            qrcode.Resolution = 300;

            //  Set all margins to 0
            qrcode.LeftMargin = 0;
            qrcode.RightMargin = 0;
            qrcode.TopMargin = 0;
            qrcode.BottomMargin = 0;

            Bitmap qrcodeBitmap = qrcode.ToImage();
            qrcodeBitmap.Save(@"W:\Projects\Test-Output\RasterEdge.com\barcode-qrcode.png");