Manage Caption of the Barcode

Skip to end of metadata
Go to start of metadata
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 are all possible where captions can be placed.


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. BarCodeBuilder class has two methods, setCaptionAbove() and setCaptionBelow() that take an instance of Caption class. So, developers can create an object of Caption class and then pass that object to the two methods to set the captions of the barcode.

Programming Sample
[Java]
//Instantiate barcode object
BarCodeBuilder bb = new BarCodeBuilder();

//Set the code text of the barcode
bb.setCodeText("1234567");

//Set the symbology type to code128
bb.setSymbologyType(Symbology.Code128);

Caption caption = new Caption();
caption.setText("Captions");
caption.setAlignment(Alignment.MIDDLE);

bb.setCaptionAbove(caption);
bb.setCaptionBelow(caption);
 
Output

The output generated barcode by the above code is shown below in the figure:
Figure: Resulting barcode image generated after example code execution


The output of Java code snippet:
Figure: Resulting barcode rendering to Graphics object

Programming Sample

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

[Java]
bb.getCaptionAbove().setAlignment(Alignment.LEFT);
bb.getCaptionAbove().setText("Aspose.Demo");
bb.getCaptionAbove().setVisible(true);
bb.getCaptionAbove().setFont(new java.awt.Font("Pristina", Font.PLAIN, 14));
bb.getCaptionAbove().setForeColor(java.awt.Color.RED);

bb.getCaptionBelow().setAlignment(Alignment.RIGHT);
bb.getCaptionBelow().setText("Aspose.Demo");
bb.getCaptionBelow().setVisible(true);
bb.getCaptionBelow().setFont(new java.awt.Font("Pristina", Font.PLAIN, 14));
bb.getCaptionBelow().setForeColor(java.awt.Color.RED);
 
Output

Figure: customizing caption

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.