article

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

Email
Submitted on: 7/24/2015 7:35:17 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 3099
 
     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.

 
				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. 


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.