Home > Code > C# > How to Customize Text, Font, Color & Size of Barcode Caption inside .NET Apps

How to Customize Text, Font, Color & Size of Barcode Caption inside .NET Apps

by sher azam   on Jul 24, 2015   Category: C#   |  Views: 645    |  Points: 25   |  Gold 


This Technical tip explains how .NET developers can manage caption of the barcode inside their .NET applications using Aspose.BarCode for .NET. Sometimes, developers might be interested in displaying some extra information on the barcode image that is called Caption. Using Aspose.BarCode, developers can display captions on above, below or both positions of the barcode image. It is also possible to customize the text, alignment, font, color and space of the caption. Aspose.BarCode provides a Caption class to serve this purpose. All barcode generating classes have two properties, CaptionAbove and CaptionBelow that take an instance of Caption class. So, developers can create an object of Caption class and then assign that object to CaptionAbove, CaptionBelow or both properties to set the captions of the barcode.

Code sample for Managing Caption of the Barcode

//[C# Code Sample]

//Instantiate barcode object
BarCodeBuilder bb = new BarCodeBuilder();

//Set the Code text for the barcode
bb.CodeText = "1234567";

//Set the symbology type to Code128
bb.SymbologyType = Symbology.Code128;

//Create caption object. Set its text and text alignment & also make it visible
Caption caption = new Caption();
caption.Text = "Aspose.BarCode";
caption.TextAlign = System.Drawing.StringAlignment.Center;
caption.Visible = true;

//Assign caption object to be displayed above and below the barcode
bb.CaptionAbove = caption;
bb.CaptionBelow = caption;

//Save the image to your system and set its image format to Jpeg
bb.Save("barcode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);


//[VB.NET Code Sample]

'Instantiate barcode object
Dim bb As BarCodeBuilder = New BarCodeBuilder()

'Set the Code text for the barcode
bb.CodeText = "1234567"

'Set the symbology type to Code128
bb.SymbologyType = Symbology.Code128

'Create caption object. Set its text and text alignment & also make it visible
Dim caption As Caption = New Caption()
caption.Text = "Aspose.BarCode"
caption.TextAlign = System.Drawing.StringAlignment.Center
caption.Visible = True

'Assign caption object to be displayed above and below the barcode
bb.CaptionAbove = caption
bb.CaptionBelow = caption

'Save the image to your system and set its image format to Jpeg
bb.Save("barcode.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

// Continuing the sample above, the following sample shows Font and Color setting

//[C# Code Sample]

bb.CaptionAbove.TextAlign = StringAlignment.Near;
bb.CaptionAbove.Text = "Aspose.Demo";
bb.CaptionAbove.Visible = true;
bb.CaptionAbove.Font = new System.Drawing.Font("Pristina", 14f);
bb.CaptionAbove.ForeColor = Color.OrangeRed;

bb.CaptionBelow.TextAlign = StringAlignment.Far;
bb.CaptionBelow.Text = "Aspose.Demo";
bb.CaptionBelow.Visible = true;
bb.CaptionBelow.Font = new System.Drawing.Font("Pristina", 14f);
bb.CaptionBelow.ForeColor = Color.OrangeRed;

//[VB.NET Code Sample]

bb.CaptionAbove.TextAlign = StringAlignment.Near
bb.CaptionAbove.Text = "Aspose.Demo"
bb.CaptionAbove.Visible = True
bb.CaptionAbove.Font = New System.Drawing.Font("Pristina", 14.0F)
bb.CaptionAbove.ForeColor = Color.OrangeRed

bb.CaptionBelow.TextAlign = StringAlignment.Far
bb.CaptionBelow.Text = "Aspose.Demo"
bb.CaptionBelow.Visible = True
bb.CaptionBelow.Font = New System.Drawing.Font("Pristina", 14.0F)
bb.CaptionBelow.ForeColor = Color.OrangeRed



Overview: Aspose.BarCode for .NET

Aspose.BarCode is a .NET component for generation and recognition of Linear and 2D barcodes on all kinds of .NET applications. It supports WPF with 29+ Barcode symbologies like OneCode, QR, Aztec, MSI, EAN128, EAN14, SSCC18, Code128, Code39, Postnet, MarcoPDF417, Datamatrix, UPCA etc. Other features include barcode insertion in PDF, Word and Excel documents. Also take image output in BMP, GIF, JPEG, PNG and WMF formats. You can also control image styles such as background color, bar color etc.

- Homepage of Aspose.BarCode for .NET: http://www.aspose.com/.net/barcode-component.aspx

- Download of Aspose.BarCode for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.barcode-for-.net/default.aspx



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts