Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Barcode39 image display in JSP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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();
codeEAN.setBarHeight(100);
codeEAN.setSize(500);
codeEAN.setCode("123456789");
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);

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

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

Thanks
Mahesh
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic