If anyone has a better approach, please update on this thread.
Hey guys.. I found a workaround to this problem. We have to create a Java step in an activity and in the Java code we can use the existing lowagie or itext libraries that are a part of the product and use the library functions to generate the Barcode ( refer http://itextpdf.com/ for he documentation ) once this barcode is generated, convert it into an image and then you can either
1. assign the java image to a parameter or a property on the step page
2. convert the image into a byte array and then into Base64 code in Java code itself and then assign that Base64 encoded string to a parameter or a property of the step page. Then apply the Base64 decoding available as a library function in Pega expression builder to convert it back to an image.