----------------------------------------------------------- New Message on cochindotnet
----------------------------------------------------------- From: VBGUru Message 1 in Discussion www.aravinda.in Driven By Values; Powered by Passion<o:p></o:p><o:p></o:p> http://code.aravinda.in , http://fun.aravinda.in, http://kedge.aravinda.in, http://live.aravinda.in<o:p></o:p> <o:p></o:p> The below article is from http://www.aravinda.in/Tech.aspx?Title=Bar_Code_Printing&WebPage=tech\dotnet\BarcodePrinting.htm Bar Code Printing Load the Barcode Font ( you can download from any website) Create an image object Draw a string into that image using a code39 barcode font Return that image serialized. Print the image See the sample below to print bar codes. The Barcode Generation You can write a code39 barcode generator that mimics the algorithm for the barcode representation Or use one of the freely available barcode fonts to produce the barcode (http://www.squaregear.net/fonts/free3of9.shtml). Using the Code39 Font... The way to use a font in windows is simple, all you have to do is install it (by copying it to the c:\WINDOWS\Fonts - under XP) and just use it. Unfortunately, the ASP.NET graphic context does not allow you to use any font (free3of9.ttf for example) because .NET GDI only uses/enumerates OpenType fonts. So what you have to do is create a temporary font object. This method is very straighforward, as you can see in the code sample below:// Create a private font collectionobjectPrivateFontCollection pfc=new PrivateFontCollection(); // Load in the temporary barcode fontpfc.AddFontFile("c:\\barcodefont\\free3of9.ttf"); // Select the font family to useFontFamily family=new FontFamily("Free 3 of 9",pfc); // Create the font object with size 30Font c39Font=new Font(family,30); With this easy way, you get a font object mapped to the barcode font so that you can create the barcode. Creating the Barcode Image Container The image creation is very simple. .NET classes allow you to generate images on the fly. So, in order to create a image large enough to accommodate the barcode, first you need to determine the size that will be occupied by the code string drawing, using the barcode font. You can do it using the MeasureString method:// Create a temporary bitmap...Bitmap tmpBitmap = new Bitmap(1,1,PixelFormat.Format32bppArgb);objGraphics = Graphics.FromImage(tmpBitmap);// measure the barcode size...SizeF barCodeSize=objGraphics.MeasureString(barCodeString,c39Font); The returned type barCodeSize has the width, and the height that will be occupied by the code string drawing. Draw the Barcode So now we need to draw the barcode. We will use the code39 barcode font object instantiated earlier. Assuming the the barcode variable holds the barcode string, the required code is:// Draw the barcodeobjGraphics.DrawString(barCode, Code39Font, new solidBrush(Color.Black),0,0); Please note that usualy the code39 barcodes are represented concatenating the char (*) at the beginning and end of the barcode stringÂ…meaning that code 123456 has to be written as *123456*. But I will leave that to your experience. Serialize/Deserialize the Image In order to return the image from the web service method, you now have to serialize the image, meaning that your web method has to return an array of bytes. This way, you have to create a stream from the bitmap image, and return it as an array of bytes. Once again, the .NET framework makes it easy for us do perform that task:// Create stream....MemoryStream ms = new MemoryStream(); // save the image to the streamobjBitmap.Save(ms ,ImageFormat.Png); //return an array of bytes....return ms.GetBuffer(); On the other end (the client side) when you are consuming the web service, you need to be able to deserialize the array of bytes back to the image:Byte[] imgBarcode; // Call the webservice to create the barcode... // Create a stream....MemoryStream memStream = new MemoryStream(imgBarcode); // Recreate the image from the stream Bitmap bmp=new Bitmap(memStream); A final note about the sample code attachedÂ… After creating the barcode web app that will be your webservice, you need to configure the web.config file in order to specify where your barcode font is located. Search for the following section and make your changes accordingly. <appSettings> <add key="BarCodeFontFile" value="c:\temp\font\FREE3OF9.TTF" /> <add key="BarCodeFontFamily" value="Free 3 of 9" /> </appSettings> www.aravinda.in Driven By Values; Powered by Passion<o:p></o:p><o:p></o:p> http://code.aravinda.in , http://fun.aravinda.in, http://kedge.aravinda.in, http://live.aravinda.in<o:p></o:p> <o:p></o:p> The below article is from http://www.aravinda.in/Tech.aspx?Title=Bar_Code_Printing&WebPage=tech\dotnet\BarcodePrinting.htm ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/CochinDotNet/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]