Guide for C#
Core Document Formats
Additional Features
QR Code

C# Imaging - QR Code Image Generation Tutorial

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

Visual C#
Home > .NET Imaging SDK > C# > Generate QR Code Barcode
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

C# Imaging - QR Code Barcode Add-on Overview
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:
  • 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
From this C#.NET QR Code generating tutorial page, you can get a few C# samples for QR Code barcoding.
  • How to generate QR Code on common image files
  • How to create QR Code on document files
  • QR Code barcode parameters
  • How to draw customized QR Code image using C# code
C# Imaging - Draw QR Code on Image File
This C# QR Code barcode generator add-on supports drawing QR Code two-dimensional bar code at any specified location on a target image file. The supported image formats include png, gif, jpeg and bmp. Copy Visual C# sample code below to your .NET imaging application to create and insert a QR Code bar code on a sample png image.
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");
C# Imaging - Create QR Code on Document Page
Apart from generating QR Code on image files, C#.NET barcode creator plug-in of RasterEdge DocImage SDK for .NET can also create QR Code in common document files, like TIFF, PDF, Word, Excel and PowerPoint. Using this C#.NET barcode creating control, you can also customize the location of generated QR Code barcode on target document file.

Generate QR Code on C# PDF Page

PDFDocument doc = new PDFDocument("c:/Sample.pdf");
PDFPage page = (PDFPage)doc.GetPage(0);

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add this barcode image to this page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save the changes
doc.Save(@"c:/barcode.pdf");

Create QR Code on C# TIFF File

// load TIFF document. You can also load document like PDF, Word, Excel & PPT
TIFFDocument tiff = new TIFFDocument(@"c:\sample.tiff");

// get the first page
BasePage page = tiff.GetPage(0);

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to TIFF document
tiff.Save(@"c:\barcode.tiff");

Draw QR Code on C# Word Document

// construct an DOCXDocument
DOCXDocument doc = new DOCXDocument(@"c:/Sample.docx");

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

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.docx");

Generate QR Code on C# Excel Sheet

// construct an XLSXDocument
XLSXDocument doc = new XLSXDocument(@"c:/Sample.xlsx");

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

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.xlsx");

Draw QR Code Barcode on C# PowerPoint Slide

// construct an PPTXDocument
PPTXDocument doc = new PPTXDocument(@"c:/Sample.pptx");

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

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data
barcode.X = 20.0F;// set module size
barcode.RightMargin = barcode.LeftMargin = barcode.TopMargin = barcode.BottomMargin = 80; // margins on four sides of QR Code should be 4X
barcode.Resolution = 96;// set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.pptx");
C# Imaging - QR Code Barcode Creating Parameters
Barcode Creator Add-on of RasterEdge DocImage SDK for .NET offers flexible options to customize QR Code barcode properties like size, color, and rotation in C#.NET project. You can find detailed information of QR Code barcoding parameters in the following form.
QR CODE SETTING+
QR CODE SETTING-
Barcode Type QRCode
Data Resolution
UOM
Rotate
LeftMargin RightMargin
TopMargin BottomMargin
BarcodeWidth BarcodeHeight
X ProcessTilde
BackColor ForeColor
AutoResize BarAlignment
FNC1 ECL
DataMode Version
StructuredAppend Parity
SymbolIndex SymbolCount
  • Left Margin: The white space by the left side of QR Code barcode image. Default value is 0 pixel. Note that, in order to create a valid QR Code for scanning, please set the Left Margin to a minimum of 4X. The same goes for Right Margin, Top Margin and Bottom Margin.
  • FNC1: This is a Boolean value. You can enable it to create a GS1-compatible QR Code bar code image.
  • Data Mode: Select according to your data type. Kanji is used to encode Japanese character Shift JIS system based JIS X 0208. Auto Mode is recommended for automation data type selecting.
  • Structure Append: A functionality to encode files of data continuously in up to 16 QR Code symbols.
  • Version: QR Code 2005 version varies from V1 to V40, starting form 21x21 modules, increasing in steps of 4 modules per side.
C# Imaging - Generate Customized QR Code Using C# Code
This C#.NET QR Code barcode generator add-on makes it quite easy for you to generate a desired QR Code barcode image. Following C# Code can be used to generate a customized QR Code on a png image file in Visual C#.NET class application.
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

QRCode barcode = new QRCode();// create a QR Code barcode
barcode.Data = "123456789asdq";// input encodable data

// QR Code size related settings
barcode.UOM = RasterEdge.Imaging.Barcode.Creator.UnitOfMeasure.PIXEL;
barcode.X = 5.0F;
barcode.BarcodeHeight = 90;
barcode.BarcodeWidth = 90;
barcode.BottomMargin = 20;// margins on four sides of QR Code should be 4X
barcode.TopMargin = 20;
barcode.LeftMargin = 20;
barcode.RightMargin = 20;
barcode.AutoResize = false;

// QR Code unique settings
barcode.DataMode = QRCodeDataMode.Auto;
barcode.ECL = QRCodeECL.M;
barcode.FNC1 = FNC1.FNC1_NONE;
barcode.StructuredAppend = false;
barcode.Version = QRCodeVersion.V1;
barcode.BarAlignment = AlignmentHori.Center;
barcode.ProcessTilde = true;

// color related settings
barcode.BackColor = System.Drawing.Color.White;
barcode.ForeColor = System.Drawing.Color.Black;

// other related settings
barcode.Resolution = 96;
barcode.Rotate = Rotate.Rotate0;

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");


Recommend this to Google+