Re: Barcode with iText
Louis Demers <[email protected]> Wed, 22 Feb 2012 11:36:20 -0500
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Thank you very much. Incorporated, adapted, and it works perfectly.
Cheers
Louis
On 2012-02-22, at 04:14 , Gary Teter wrote:
> Image: WOImage {
> align = "right";
> data = barcodeData;
> mimeType = "image/png";
> }
>
> public NSData barcodeData() {
> return barcode128AsPNG("some barcode data");
> }
>
> public static NSData barcode128AsPNG(String barcode) {
> Barcode128 code128 = new Barcode128();
> code128.setCode(barcode);
> java.awt.Image image = code128.createAwtImage(Color.BLACK, Color.WHITE);
> BufferedImage bufferedImage = bufferedImageFromImage(image);
> SunPNGEncoderAdapter encoder = new SunPNGEncoderAdapter();
> try {
> bytes = new NSData(encoder.encode(bufferedImage));
> } catch (java.io.IOException e) {
> // the goggles, they do nothing
> }
> return bytes;
> }
>
> public static BufferedImage bufferedImageFromImage(java.awt.Image img) {
> //This line is important, this makes sure that the image is
> //loaded fully
> img = new ImageIcon(img).getImage();
>
> //Create the BufferedImage object with the width and height of the Image
> BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
>
> //Create the graphics object from the BufferedImage
> Graphics g = bufferedImage.createGraphics();
>
> //Draw the image on the graphics of the BufferedImage
> g.drawImage(img, 0, 0, null);
>
> //Dispose the Graphics
> g.dispose();
>
> //return the BufferedImage
> return bufferedImage;
> }
>
>
> On Feb 21, 2012, at 4:26 PM, Louis Demers wrote:
>
>> Hi,
>>
>> I'm trying to create barcodes with iText without inserting them into a PDF, but instead for inclusion into a wocomponent. The barcode is returned as a com.itextpdf.text.Image but I can't figure out how to get a usable image for woimage. Alternatively, I could get a java.awt.Image, But I'm equally dum and clueless with those.
>>
>> Any past experience and pointers would be welcomed.
>>
>> Cordially.
>>
>>
>> Louis Demers eng.
>> www.obzerv.com
>>
>>
>> _______________________________________________
>> WebObjects-dev mailing list
>> [email protected]
>> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
>
Louis Demers eng.
www.obzerv.com