Guide for C#
Core Document Formats
Additional Features
UPC-A

C# Imaging - UPC-A Barcode Generator

How to Add and Insert UPC-A Barcode to Image & Document in C#

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

C# Imaging - UPC-A Barcode Add-on Overview
Our C#.NET UPC-A barcode creator add-on is designed to help C# developers create standard linear UPC-A barcode and add generated UPC-A barcode to documents and image files in .NET applications.
Following is a feature list of RasterEdge C# UPC-A barcode creator add-on.
  • Mature UPC-A barcode generator SDK for C#.NET document and image processing applications
  • Insert linear UPC-A barcode into images and documents using simple C# programming language
  • Created UPC-A barcode can be processed separately on target document or image file using C#.NET
  • Offer complete parameters for C# developers to create UPC-A barcode with desired property values
This online tutorial page for C#.NET UPC-A barcode creation on images and documents are divided into following five sections.
  • How to add UPC-A barcode to raster image files using sample C# code
  • How to draw UPC-A barcode on PDF, Word, TIFF, Excel and PowerPoint documents in C#
  • Complete C# UPC-A barcoding parameters
  • Demo C# code for customizing UPC-A barcode creation on document image files
  • C# UPC-A barcode creator control FAQs
If needed, please try this C#.NET UPC-A barcode reader add-on to integrate UPC-A barcode detecting functions into your C#.NET project. If you want to integrate UPC-A barcode generating features into VB.NET class application, please read this tutorial page for VB.NET UPC-A barcode generator SDK.
How to Add UPC-A Barcode to Image in C#
In this section, you can find sample C# code, which is used to illustrate how to create and draw UPC-A barcode on source image, picture or photo in .NET class application. Now, our Barcode Generator DLL for C#.NET supports creating UPC-A barcode on BMP, GIF, JPEG, TIFF and PNG image files. Remarkably, developers can draw linear UPC-A barcode at any desired place on source image file as this C# UPC-A Barcode Generator DLL uses the application of X & Y location.
REImage reImage = REFile.OpenImageFile("c:/Sample.png", new PNGDecoder());

Linear barcode = new Linear();//create a barcode

barcode.Type = RasterEdge.Imaging.Barcode.Creator.BarcodeType.UPCA;//select barcode type

barcode.Data = "01234567890";//set barcode data
barcode.X = 1.0F;//set x
barcode.Y = 60.0F;//set y
barcode.Resolution = 96;//set resolution
barcode.Rotate = Rotate.Rotate0;//set rotate

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

REFile.SaveImageFile(reImage, "c:/upc-a.png", new PNGEncoder());
How to Create UPC-A on Document Page in C#
This C# UPC-A barcode generator SDK is often used by developers for the purpose of adding linear UPC-A barcode to document files, like PDF, TIFF, MS Word, Excel and PowerPoint. What should be noted here is that, using RasterEdge UPC-A barcode creator SDK, you can create and insert UPC-A barcode at any specified location of any one page from target document files accurately by C# programming code.

How to Insert UPC-A Barcode into PDF Using C#

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

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

Linear barcode = new Linear();//create a barcode

barcode.Type = BarcodeType.UPCA;//select barcode type

barcode.Data = "01234567890";//set barcode data
barcode.X = 1.0F;//set x
barcode.Y = 60.0F;//set y
barcode.Resolution = 96;//set resolution
barcode.Rotate = Rotate.Rotate0;//set rotate

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:/upc-a.pdf", new PDFEncoder());

How to Draw UPC-A on TIFF Using C#.NET

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

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

Linear barcode = new Linear();//create a barcode

barcode.Type = BarcodeType.UPCA;//select barcode type

barcode.Data = "01234567890";//set barcode data
barcode.X = 1.0F;//set x
barcode.Y = 60.0F;//set y
barcode.Resolution = 96;//set resolution
barcode.Rotate = Rotate.Rotate0;//set rotate

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:/upc-a.tif", new TIFEncoder());

How to Add UPC-A to Word Document in C#

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

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

Linear barcode = new Linear();//create a barcode

barcode.Type = BarcodeType.UPCA;//select barcode type

barcode.Data = "01234567890";//set barcode data
barcode.X = 1.0F;//set x
barcode.Y = 60.0F;//set y
barcode.Resolution = 96;//set resolution
barcode.Rotate = Rotate.Rotate0;//set rotate

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:/upc-a.docx", new DOCXEncoder());

How to Draw UPC-A on Excel Document in C#

/// <summary>
/// Create a UPC-A linear barcode to Excel document page
/// </summary>
/// <param name="filePath"></param>
/// <param name="barcodeData"></param>
public void CreateUPCAOnExcelDocument(String filePath, String barcodeData, float positionX, float positionY)
{

ExcelDocument doc = new ExcelDocument(filePath);

RasterEdge.Imaging.Barcode.Creator.Linear = new Linear();//create a UPC-A barcode
BarcodeType = BarcodeType.UPCA;

barcode.Data = "01234567899";//set barcode data
barcode.X = 6.0F;

barcode.Resolution = 90;
barcode.Rotate = Rotate.Rotate90;

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:\upca-barcode.xlsx");

}

How to Create UPC-A Barcode to PPTX Slide

/// <summary>
/// Create UPC-A linear barcode on PPTX document
/// </summary>
/// <param name="filePath"></param>
/// <param name="barcodeData"></param>
public void CreateUPCAOnPPTXDocument(String filePath, String barcodeData, float positionX, float positionY)
{

PPTXDocument doc = new PPTXDocument(filePath);

RasterEdge.Imaging.Barcode.Creator.Linear = new Linear();//create UPC-A barcode
BarcodeType = BarcodeType.UPCA;

barcode.Data = "01234567899";//set UPC-A barcode data
barcode.X = 2.0F;

barcode.Resolution = 82;

REImage reBarcode = barcode.ToImage();

//Update the barcode resolution
reBarcode.UpdateResolution(96F, 96F);

for (int i = 0; i < doc.GetPageCount(); i++)
{

((PPTXPage)(doc.GetPage(i))).AddImage(reBarcode, 100, 100);// add barcode at position (100,100) unit is pixel as default.

}

doc.Save(@"C:\upca-barcode.pptx");

}
UPC-A Barcoding Parameters and C# Code Demo
Sometimes, C# developers are required to create document file with linear UPC-A barcode that has certain fixed margins, text font style or specific generation orientation. Therefore, a professional UPC-A barcode creator add-on, which allows C# developers to create highly-readable UPC-A barcode on document file and also help them adjust generated UPC-A barcode properties to their desired values, is quite necessary.
Here we present all barcoding parameters, supported by Visual C# UPC-A barcode creator add-on, in the following chart.
UPC-A SETTING+
UPC-A SETTING-
Type UPCA, UPCA_2, UPCA_5
Data Format
UOM(Unit of Measure)
Rotate
BarAlignment Resolution(DPI)
AutoResize AddCheckSum
X(Bar Width) ShowText
Y(Bar Height) TextFontSize
BarcodeWidth TextMargin
BarcodeHeight TextFont
LeftMargin TextColor
RightMargin TextFontStyle
TopMargin BackColor
BottomMargin ForeColor
SupData SupHeight
SupSpace

Entire C# Code for Customizing UPC-A Barcode

As is said above, RasterEdge UPC-A barcode creator add-on for C# owns comprehensive barcode generating functions, which allows C# developers to create a fully-customized UPC-A barcode and insert generated UPC-A barcode into source document image file. In this section, we particularly prepare a C# code demo for developers, which can be used to create UPC-A barcode and customize each property of generated barcode image on sample PNG image file.
REImage reImage = REFile.OpenImageFile("c:/Sample.png", new PNGDecoder());

Linear barcode = new Linear();//create a barcode

barcode.Type = BarcodeType.UPCA;//select barcode type

barcode.Data = "01234567890";//set barcode data

//UPC-A barcode size related
barcode.X = 1.0F;//set x
barcode.Y = 60.0F;//set y
barcode.BarcodeHeight = 60;
barcode.BarcodeWidth = 0;
barcode.BottomMargin = 0;
barcode.LeftMargin = 0;
barcode.RightMargin = 0;
barcode.BarAlignment = AlignmentHori.Center;
barcode.Resolution = 72;//set resolution
barcode.Rotate = Rotate.Rotate0;//set rotate
barcode.AddCheckSum = false;
barcode.UOM = RasterEdge.Imaging.Barcode.Creator.UnitOfMeasure.PIXEL;

//UPC-A colors
barcode.BackColor = System.Drawing.Color.White;
barcode.ForeColor = System.Drawing.Color.Black;

//UPC-A font style
barcode.TextFont = new Font("Arial", 9f, FontStyle.Regular);
barcode.TextColor = System.Drawing.Color.Black;
barcode.TextMargin = 6;
barcode.ShowText = true;

//UPC-A Special
//barcode.SupData = "";
//barcode.SupHeight = 0.8f;
//barcode.SupSpace = 15f;

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

REFile.SaveImageFile(reImage, "c:/upc-a.png", new PNGEncoder());
C# UPC-A Barcode Generator Library FAQs
Can I create and insert multiple UPC-A barcodes on source document image file at a time using the APIs that RasterEdge C#.NET UPC-A Barcode Creator Add-on offers?
Sorry, using RasterEdge C#.NET UPC-A barcode generation API, developers can only create & insert one UPC-A barcode into target document image file at a time.


Recommend this to Google+