java.net member

Rechercher dans ce site

Showing posts with label java - barcode. Show all posts
Showing posts with label java - barcode. Show all posts

Hello World, Barcode in Java, using ZXing

>> 29 September 2010

I have posted an article about using "Barbecue" for generating bar codes in Java, a few days ago.

 Yesterday I read this excellent post : about using "ZXing" Java Library (Open Source), to generate bar code in Java programs.

This library looks very interesting and powerful. Here is a Hello World.

ZXing ("Zebra Crossing")

The description is from the library's site
"ZXing (pronounced "zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. Our focus is on using the built-in camera on mobile phones to photograph and decode barcodes on the device, without communicating with a server."

Project's Site :
http://code.google.com/p/zxing/

Installing
  • Download the current version (Zxing-1.6.zip)
  • Unzip in a folder of your choice, this will give "zxing-1.6" folder
  • For normal Java programs, two .jar files must be built
  • One of the possibilities is to use "ant"
  • cd zxing-1.6/core
  • Type "ant" you'll get in the same folder "core.jar"
  • cd zxing-1.6/javase
  • Type "ant" you'll get here "javase.jar"
  • In your Java project, create a folder (give it any name), for instance "lib"
  • Copy "core.jar" and "javase.jar" to YourProject/lib
  • Add these two .jar files to YourProject/properties/Java Build Path



Hello World

package com.java_javafx.ka;

import java.io.File;
import java.io.FileOutputStream;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;

/**
 *
 * @author Kaesar ALNIJRES
 *
 */
public class HelloWorld {

  
    public static void main(String[] args) {
      
           int width = 440;
           int height = 48;
           
             
           BitMatrix bitMatrix;
        try {
            bitMatrix = new Code128Writer().encode("Hello World !!!",BarcodeFormat.CODE_128,width,height,null);
            MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream(new File("/home/kas/zxing_barcode.png")));
        } catch (WriterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}


Read more...

Barcode generating in Java, Barbecue, Hello World

>> 21 September 2010


If you are looking for an open source library for generating barcodes from your Java application, then this article is for you.


What is Barbecue :
"Barbecue Project" site's says
"Barbecue is a Java library that enables the creation of barcodes in a variety of standard formats that can be displayed as Swing/AWT components, included in printed output, generated as EPS and SVG and displayed in a web application."

Note:
Before going any further, please note that Barbecue will not play on GAEJ, some dependencies are not on the "The JRE Class White List" of Google, for instance JComponent.


Project's Site :
http://sourceforge.net/projects/barbecue/


Installing
  • Download the current version (In this moment it's 1.5Beta 1)
  • Unzip
  • In a Web App
    • copy barbecue-1.5-beta1.jar to war/WEB-INF/lib
    • copy jdom.jar (in the created folder/lib when unzipping ) to war/WEB-INF/lib
    • Add these two .jar files to YourProject/properties/Java Build Path
  • In a normal Java project
    • Create a folder (give it any name), for instance "lib"
    • copy barbecue-1.5-beta1.jar to YourProject/lib
    • copy jdom.jar (in the created folder/lib when unzipping ) to     YourProject/lib
    • Add these two .jar files to YourProject/properties/Java Build Path

Hello World
import java.io.File;

import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeException;
import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;
import net.sourceforge.barbecue.output.OutputException;

/**
 *
 * @author Kaesar ALNIJRES
 *
 */

public class BarCode {

    /**
     * @param args
     */
    public static void main(String[] args) {
      
        //1 get a File reference to save the bar code image
        File file=new File("/home/kas/barcode");
      
      
                          
        try {
            //2 create the bar code using a String (your data)
            Barcode barCode=BarcodeFactory.createCode128("Hello World !!!");
          
        //3 save the generated bar code to the above file as jpeg image
            BarcodeImageHandler.saveJPEG(barCode,file);
        } catch (OutputException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (BarcodeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

}





Read more...

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP