import net.sourceforge.barbecue.BarcodeFactory; import net.sourceforge.barbecue.Barcode; import net.sourceforge.barbecue.BarcodeException; import net.sourceforge.barbecue.BarcodeImageHandler; import net.sourceforge.barbecue.output.OutputException; import java.io.*; public class ProBarcode { private String bartype ; private String dirpath ; public ProBarcode(String bartype, String dirpath) { this.bartype = bartype; this.dirpath = dirpath; } public String BarcodeAsPNG(String plik,String dane) { Barcode barcode; String msg="Barcode OK"; try { if (bartype.equals("Code128B")) { barcode = BarcodeFactory.createCode128B(dane); } else if (bartype.equals("Code128A")) { barcode = BarcodeFactory.createCode128A(dane); } else if (bartype.equals("Code128C")) { barcode = BarcodeFactory.createCode128C(dane); } else if (bartype.equals("Code128")) { barcode = BarcodeFactory.createCode128(dane); } else if (bartype.equals("2of7")) { barcode = BarcodeFactory.create2of7(dane); } else if (bartype.equals("3of9")) { barcode = BarcodeFactory.create3of9(dane,true); } else if (bartype.equals("Bookland")) { barcode = BarcodeFactory.createBookland(dane); } else if (bartype.equals("Codabar")) { barcode = BarcodeFactory.createCodabar(dane); } else if (bartype.equals("EAN13")) { barcode = BarcodeFactory.createEAN13(dane); } else if (bartype.equals("EAN128")) { barcode = BarcodeFactory.createEAN128(dane); } else if (bartype.equals("GlobalTradeItemNumber")) { barcode = BarcodeFactory.createGlobalTradeItemNumber(dane); } else if (bartype.equals("Int2of5")) { barcode = BarcodeFactory.createInt2of5(dane); } else if (bartype.equals("Monarch")) { barcode = BarcodeFactory.createMonarch(dane); } else if (bartype.equals("NW7")) { barcode = BarcodeFactory.createNW7(dane); } else if (bartype.equals("PDF417")) { barcode = BarcodeFactory.createPDF417(dane); } else if (bartype.equals("PostNet")) { barcode = BarcodeFactory.createPostNet(dane); } else if (bartype.equals("RandomWeightUPCA")) { barcode = BarcodeFactory.createRandomWeightUPCA(dane); } else if (bartype.equals("SCC14ShippingCode")) { barcode = BarcodeFactory.createSCC14ShippingCode(dane); } else if (bartype.equals("ShipmentIdentificationNumber")) { barcode = BarcodeFactory.createShipmentIdentificationNumber(dane); } else if (bartype.equals("SSCC18")) { barcode = BarcodeFactory.createSSCC18(dane); } else if (bartype.equals("Std2of5")) { barcode = BarcodeFactory.createStd2of5(dane); } else if (bartype.equals("UPCA")) { barcode = BarcodeFactory.createUPCA(dane); } else if (bartype.equals("USD3")) { barcode = BarcodeFactory.createUSD3(dane,true); } else if (bartype.equals("USD4")) { barcode = BarcodeFactory.createUSD4(dane); } else if (bartype.equals("USPS")) { barcode = BarcodeFactory.createUSPS(dane); } else { barcode = BarcodeFactory.createCode39(dane,true); } } catch (BarcodeException be) { msg="ERROR:" +be.getMessage(); return msg; } try { File f = new File(this.dirpath+plik); BarcodeImageHandler.savePNG(barcode, f); } catch (Exception e) { msg="ERROR:" +e.getMessage(); } return msg; } /** * main... */ public static void main(String[] args) { if (args.length == 4) { String barType=args[0] ; String dirPath=args[1] ; String nameFile = args[2] ; String text = args[3]; ProBarcode proBC= new ProBarcode(barType, dirPath); String msg=proBC.BarcodeAsPNG(nameFile,text) ; System.out.println(msg); }else{ System.out.println("Usage:"); System.out.println("java ProBarcode barType dirPath nameFile text"); } return; } }