Re: Barcode with iText

Gary Teter <[email protected]> Wed, 22 Feb 2012 01:14:36 -0800
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <[email protected]>
Image: WOImage {
	align =3D "right";
	data =3D barcodeData;
	mimeType =3D "image/png";
}

public NSData barcodeData() {
	return barcode128AsPNG("some barcode data");
}

public static NSData barcode128AsPNG(String barcode) {
	Barcode128 code128 =3D new Barcode128();
	code128.setCode(barcode);
	java.awt.Image image =3D code128.createAwtImage(Color.BLACK, =
Color.WHITE);
	BufferedImage bufferedImage =3D bufferedImageFromImage(image);
	SunPNGEncoderAdapter encoder =3D new SunPNGEncoderAdapter();
	try {
		bytes =3D new NSData(encoder.encode(bufferedImage));
	} catch (java.io.IOException e) {
		// the goggles, they do nothing
	}
	return bytes;       =20
}

public static BufferedImage bufferedImageFromImage(java.awt.Image img) {=20=

	//This line is important, this makes sure that the image is=20
	//loaded fully=20
	img =3D new ImageIcon(img).getImage();=20
=09
	//Create the BufferedImage object with the width and height of =
the Image=20
	BufferedImage bufferedImage =3D new =
BufferedImage(img.getWidth(null), img.getHeight(null), =
BufferedImage.TYPE_INT_RGB);=20
=09
	//Create the graphics object from the BufferedImage=20
	Graphics g =3D bufferedImage.createGraphics();=20
=09
	//Draw the image on the graphics of the BufferedImage=20
	g.drawImage(img, 0, 0, null);=20
=09
	//Dispose the Graphics=20
	g.dispose();=20
=09
	//return the BufferedImage=20
	return bufferedImage;=20
}=20


On Feb 21, 2012, at 4:26 PM, Louis Demers wrote:

> Hi,
>=20
> 	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.
>=20
> Any past experience and pointers would be welcomed.
>=20
> Cordially.
>=20
>=20
> Louis Demers eng.
> www.obzerv.com
>=20
>=20
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev