Guide for C#
Core Document Formats
Additional Features
QR Code

C# Imaging - QR Code Image Generation Tutorial

Create QR Code Barcode on C# Images, 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 QR Code barcode generator add-on component, developers can create & draw single or multiple scannable QR Codes on different image files (png, jpeg, gif, bmp and tiff) and insert them into common documents like PDF, MS Word, Excel and PowerPoint using Visual C# .NET programming code. Following below are some barcoding features offered by this 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 file, MS Word documents, Excel and PowerPoint
  • Control QR Code barcode size by setting sizing dimensions
  • 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 specifications
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 and C# sample codes
  • 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 the target image file. The supported image formats include png, gif, jpeg, bmp and tiff. Copy the Visual C# sample codes to your imaging application to create and insert a QR Code bar code on the testing sample images.
REImage reImage = REFile.OpenImageFile("c:/Sample.png", new PNGDecoder());

QRCode barcode = new QRCode();//create a qrcode barcode

barcode.Data = "123456789asdq";//Input encodable data
barcode.X = 20.0F;//set module size
barcode.Resolution = 96;//set QR Code barcode printing resolution
barcode.Rotate = Rotate.Rotate0;//set rotate

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

REFile.SaveImageFile(reImage, "c:/qrcode.png", new PNGEncoder());
C# Imaging - Create QR Code on Document Page
Apart from generating QR Code in 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 at target document file.

Generate QR Code on C# PDF Page

REDocument doc = REFile.OpenDocumentFile("c:/Sample.pdf", new PDFDecoder());

REPage rePage = (REPage)doc.GetPage(0);

QRCode barcode = new QRCode();//create a qrcode barcode

barcode.Data = "123456789";//set barcode data
barcode.X = 4.0F;

//barcode.Resolution = 96;
barcode.Rotate = Rotate.Rotate0;

REImage reBarcode = barcode.ToImage();

EmbeddedImageAnnotation obj = new EmbeddedImageAnnotation();

obj.X = 10.0F;
obj.Y = 25.0F;
obj.Width = reBarcode.GetWidth();
obj.Height = reBarcode.GetHeight();

obj.FillImage = reBarcode.ToBitmap(reBarcode.GetWidth(), reBarcode.GetHeight());

RasterEdge.Imaging.Drawing.REItemEx item = obj.CreateAnnotationItem(rePage);
rePage.AddFloatingItem(item);

rePage.MergeItemsToPage();

REFile.SaveDocumentFile(doc, "c:/qrcode.pdf", new PDFEncoder());

Create QR Code on C# TIFF File

REDocument doc = REFile.OpenDocumentFile("c:/Sample.tif", new TIFDecoder());

REPage rePage = (REPage)doc.GetPage(0);

QRCode barcode = new QRCode();//create a qrcode barcode

barcode.Data = "123456789";//set barcode data
barcode.X = 4.0F;

//barcode.Resolution = 96;
barcode.Rotate = Rotate.Rotate0;

REImage reBarcode = barcode.ToImage();

EmbeddedImageAnnotation obj = new EmbeddedImageAnnotation();

obj.X = 10.0F;
obj.Y = 25.0F;
obj.Width = reBarcode.GetWidth();
obj.Height = reBarcode.GetHeight();

obj.FillImage = reBarcode.ToBitmap(reBarcode.GetWidth(), reBarcode.GetHeight());

RasterEdge.Imaging.Drawing.REItemEx item = obj.CreateAnnotationItem(rePage);
rePage.AddFloatingItem(item);

rePage.MergeItemsToPage();

REFile.SaveDocumentFile(doc, "c:/qrcode.tif", new TIFEncoder());

Draw QR Code on C# Word Document

REDocument doc = REFile.OpenDocumentFile("c:/Sample.docx", new DOCXDecoder());

REPage rePage = (REPage)doc.GetPage(0);

QRCode barcode = new QRCode();//create a qrcode barcode

barcode.Data = "123456789";//set barcode data
barcode.X = 4.0F;

//barcode.Resolution = 96;
barcode.Rotate = Rotate.Rotate0;

REImage reBarcode = barcode.ToImage();

EmbeddedImageAnnotation obj = new EmbeddedImageAnnotation();

obj.X = 10.0F;
obj.Y = 25.0F;
obj.Width = reBarcode.GetWidth();
obj.Height = reBarcode.GetHeight();

obj.FillImage = reBarcode.ToBitmap(reBarcode.GetWidth(), reBarcode.GetHeight());

RasterEdge.Imaging.Drawing.REItemEx item = obj.CreateAnnotationItem(rePage);
rePage.AddFloatingItem(item);

rePage.MergeItemsToPage();


REFile.SaveDocumentFile(doc, "c:/qrcode.docx", new DOCXEncoder());

Generate QR Code on C# Excel Sheet

/// <summary>
/// Create a QR Code barcode on every Excel sheet
/// </summary>
/// <param name="filePath"></param>
/// <param name="barcodeData"></param>
public void CreateQRCodeOnExcelDocument(String filePath, String barcodeData, float positionX, float positionY)
{
ExcelDocument doc = new ExcelDocument(filePath);

RasterEdge.Imaging.Barcode.Creator.QRCode barcode = new QRCode();//create a QR Code barcode

barcode.Data = "123456789";//set barcode data
barcode.X = 5.0F;

barcode.Resolution = 72;
barcode.Rotate = Rotate.Rotate0;

REImage reBarcode = barcode.ToImage();

float h = reBarcode.GetResolutionHori();
float v = reBarcode.GetResolutionVert();
reBarcode.UpdateResolution(96F, 96F);

for (int i = 0; i < doc.GetPageCount(); i++)
{
((ExcelPage)(doc.GetPage(i))).AddBarcode(barcode, positionX, positionY);
}

doc.Save(@"C:\QRCode.xlsx");
}

Print QR Code Barcode on C# PowerPoint Slide

/// <summary>
/// Create a QR Code barcode on every PowerPoint slide
/// </summary>
/// <param name="filePath"></param>
/// <param name="barcodeData"></param>
public void CreateQRCodeOnPPTXDocument(String filePath, String barcodeData, float positionX, float positionY)
{
PPTXDocument doc = new PPTXDocument(filePath);

RasterEdge.Imaging.Barcode.Creator.QRCode barcode = new QRCode();//create a QR Code barcode

barcode.Data = "123456789";//set barcode data
barcode.X = 5.0F;

barcode.Resolution = 72;
barcode.Rotate = Rotate.Rotate0;

REImage reBarcode = barcode.ToImage();

float h = reBarcode.GetResolutionHori();
float v = reBarcode.GetResolutionVert();
reBarcode.UpdateResolution(96F, 96F);

for (int i = 0; i < doc.GetPageCount(); i++)
{
((PPTXPage)(doc.GetPage(i))).AddBarcode(barcode, positionX, positionY);
}

doc.Save(@"C:\QRCode.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# 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 the 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. For details, please contact our support team.
  • 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 for C#.NET class application.
REImage reImage = REFile.OpenImageFile("c:/Sample.png", new PNGDecoder());
QRCode barcode = new QRCode();//create a qrcode barcode
barcode.Data = "123456789";

//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;
barcode.TopMargin = 20;
barcode.BottomMargin = 20;
barcode.LeftMargin = 20;
barcode.RightMargin = 20;
barcode.AutoResize = false;

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

//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;

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

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

REFile.SaveImageFile(reImage, "c:/qrcode.png", new PNGEncoder());


Recommend this to Google+