Javaweb barcode generation, printing, scanning

Source: Internet
Author: User

The plug-in that produces the barcode is many, but can use the needle printer to print on the suitable form, moreover can use the common laser scanner to scan out the demo to not many.

In this paper, the related code and tools are pro-test available.

Using tools:

Epson LQ-630K-Pin Printer

Honeywell ms9540 Laser Barcode Scanning gun

Laser printer


Difficulty:

Laser printer, no matter what encoding format, with the following code output pictures, scanning guns can be scanned out;

Needle printer printing effect is not so good, print out can not scan out, just start not know what problem, change code, change style, such as the mode, pin-type printer configuration, a variety of combination test.


Solution:

Use the following code and adjust the width of the barcode appropriately.

Also do not increase too big (too big appear uncoordinated), 15 bits (5 letters are numbers) generally normal output width is about 51mm bar, adjust to 56 can be recognized, of course, if not ideal, can be adjusted.


Demo

In addition, the Jbarcode-0.2.8.jar package is added to the project.

The project uses the Struts framework, which is configured in struts as follows:

<action name= "Barcode" class= "XX. Yy. Zzaction "> <span style=" white-space:pre "></span><result type=" stream "> <span style=" White-space:pre "></span><param name=" ContentType ">image/jpeg</param> <span style=" White-space:pre "></span><param name=" InputName ">inputStream</param> <span style=" White-space:pre "></span></result> </action>
The foreground can be called as follows

Aciton class

Import Java.awt.image.bufferedimage;import Java.io.bytearrayinputstream;import Java.io.ByteArrayOutputStream; Import Javax.imageio.imageio;import Javax.imageio.stream.imageoutputstream;import Org.jbarcode.jbarcode;import Org.jbarcode.encode.code93encoder;import Org.jbarcode.paint.baselinetextpainter;import Org.jbarcode.paint.ean13textpainter;import Org.jbarcode.paint.widthcodedpainter;public class BarcodeAction { Private Bytearrayinputstream inputstream;private String Barcode;public string Execute () throws Exception {Jbarcode Jbarcode = new Jbarcode (Code93encoder.getinstance (), Widthcodedpainter.getinstance (), Baselinetextpainter.getinstance ()); Jbarcode. Setshowcheckdigit (false); Jbarcode. Setcheckdigit (True); JBarcode. Setshowtext (false); Jbarcode. Setbarheight (10); BufferedImage bufferedimage = Jbarcode. Createbarcode (barcode); Bytearrayoutputstream output = new Bytearrayoutputstream (); Imageoutputstream imageout = Imageio.createimageoutputstream (output); Imageio.write (BufferedImage, "JPEG", imageout); Imageout.close (); inputstream = new Bytearrayinputstream (Output.tobytearray ()); Return "Success";} public void Setinputstream (Bytearrayinputstream inputstream) {this.inputstream = InputStream;} Public Bytearrayinputstream getInputStream () {return inputstream;} Public String Getbarcode () {return barcode;} public void Setbarcode (String barcode) {this.barcode = barcode;}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.