Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Barcode39 image display in JSP

Mahesh Rud
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am able to display the barcode39 image in JSP. I need to display the text also below the image which i am not able to do. Please help me.

I am using iText to generate the barcode. iText has 2 options to create barcode39. createImageWithBarcode and createAwtImage.

createImageWithBarcode comes with text below the barcode by default. But i am unable to convert this iText Image type to any other image like java.awt.Image or BufferedImage. And also i am not able to write this image to JSP. If there is way to convert the image or display it as it is on JSP then it solves my problem. Please let me know is there any way.

I had to use createAwtImage method to get image. This atleast i am able to display image on JSP. But in this case i am not able to display text under barcode.

for the createAwtImage My servlet code is:

Barcode39 codeEAN = new Barcode39();
Image img = codeEAN.createAwtImage(Color.BLACK, Color.WHITE);

BufferedImage bi = new BufferedImage(img.getWidth(null), img
.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(img, 0, 0, null);

final OutputStream outputStream = response.getOutputStream();
ImageIO.write(bi, "png", outputStream);

If i get solution for any one i will be very happy. Please let me know if there are any pointers.

Bear Bibeault
Author and ninkuma
Posts: 65276
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic