TableColumn col = tab1.getColumnModel().getColumn(0);
col.setPreferredWidth(50);
col = tab1.getColumnModel().getColumn(1);
col.setPreferredWidth(100);
col = tab1.getColumnModel().getColumn(2);
col.setPreferredWidth(300);
Wednesday, December 23, 2009
Tuesday, December 22, 2009
Set Tooltip in JTable Cell
JTable tab = new javax.swing.JTable(tabm3){
public Component prepareRenderer(TableCellRenderer renderer,
int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (c instanceof JComponent) {
JComponent jc = (JComponent)c;
jc.setToolTipText((String)getValueAt(rowIndex, vColIndex));
}
return c;
}
};
public Component prepareRenderer(TableCellRenderer renderer,
int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (c instanceof JComponent) {
JComponent jc = (JComponent)c;
jc.setToolTipText((String)getValueAt(rowIndex, vColIndex));
}
return c;
}
};
Sunday, December 6, 2009
Max date of a month
calendar = new GregorianCalendar(yr,mon-1,dd);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
Tuesday, November 10, 2009
Bar code generation with print option
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package barcode;
/**
*
* @author amber imam
*/
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.Color;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
public class BarcodePrint {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Document document = new Document(PageSize.NOTE, 50, 50, 50, 50);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
Barcode128 code128 = new Barcode128();
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
int no = 5;
String data = "23456 "+no+" " + sdf.format(new Date());
code128.setCodeType(Barcode.CODE128_RAW);
code128.setCode(data.trim());
//code128.setBarHeight(10);
//code128.setSize(20);
Image image128 = code128.createImageWithBarcode(cb, Color.black, Color.blue);
Chunk park = new Chunk("Zoological Park of India , Kolkata",new Font(Font.COURIER, 8,Font.BOLD) );
//park.setBackground(Color.yellow);
//park.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL,0f,Color.red);
document.add(new Phrase(park));
document.add(new Phrase("\n"));
document.add(Chunk.NEWLINE);
document.add(new Phrase(new Chunk(image128, 0, 0)));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk(sdf1.format(new Date()) , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("Rs-250.50/- C4" , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("solution by : KMA infonet solution (p) Ltd." , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(Chunk.NEWLINE);
document.add(Chunk.NEWLINE);
code128.setCodeType(Barcode.CODE128);
code128.setCode(data.trim());
image128 = code128.createImageWithBarcode(cb, Color.black, Color.blue);
park = new Chunk("Zoological Park of India",new Font(Font.TIMES_ROMAN, 8,Font.BOLD) );
//park.setBackground(Color.yellow);
//park.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL,0f,Color.red);
document.add(new Phrase(park));
document.add(new Phrase("\n"));
document.add(Chunk.NEWLINE);
document.add(new Phrase(new Chunk(image128, 0, 0)));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk(sdf1.format(new Date()) , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("Rs-250.50/- C4" , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("solution by : KMA infonet solution (p) Ltd." , new Font(Font.COURIER, 6, Font.BOLD))));
// document.add(Chunk.NEWLINE);
// UPC E
// BarcodeEAN codeEAN = new BarcodeEAN();
// document.add(new Paragraph("Barcode UPC-E"));
// codeEAN.setCodeType(Barcode.UPCE);
// codeEAN.setCode(data.trim());
// document.add(codeEAN.createImageWithBarcode(cb, null, null));
// codeEAN.setBarHeight(codeEAN.getSize() * 3f);
document.close();
String filename = "test.pdf";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//pras.add(MediaSize.findMedia((float) 12, (float) 8, MediaSize.MM));
//Media printable area
// pras.add(new MediaPrintableArea(0, 0, (float) 12, (float) 8,MediaPrintableArea.MM));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
//Thread.sleep(10000);
}
System.exit(0);
}
catch (Exception de)
{
System.out.println(de);
}
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package barcode;
/**
*
* @author amber imam
*/
import java.io.FileOutputStream;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.Color;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
public class BarcodePrint {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Document document = new Document(PageSize.NOTE, 50, 50, 50, 50);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
Barcode128 code128 = new Barcode128();
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
int no = 5;
String data = "23456 "+no+" " + sdf.format(new Date());
code128.setCodeType(Barcode.CODE128_RAW);
code128.setCode(data.trim());
//code128.setBarHeight(10);
//code128.setSize(20);
Image image128 = code128.createImageWithBarcode(cb, Color.black, Color.blue);
Chunk park = new Chunk("Zoological Park of India , Kolkata",new Font(Font.COURIER, 8,Font.BOLD) );
//park.setBackground(Color.yellow);
//park.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL,0f,Color.red);
document.add(new Phrase(park));
document.add(new Phrase("\n"));
document.add(Chunk.NEWLINE);
document.add(new Phrase(new Chunk(image128, 0, 0)));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk(sdf1.format(new Date()) , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("Rs-250.50/- C4" , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("solution by : KMA infonet solution (p) Ltd." , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(Chunk.NEWLINE);
document.add(Chunk.NEWLINE);
code128.setCodeType(Barcode.CODE128);
code128.setCode(data.trim());
image128 = code128.createImageWithBarcode(cb, Color.black, Color.blue);
park = new Chunk("Zoological Park of India",new Font(Font.TIMES_ROMAN, 8,Font.BOLD) );
//park.setBackground(Color.yellow);
//park.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL,0f,Color.red);
document.add(new Phrase(park));
document.add(new Phrase("\n"));
document.add(Chunk.NEWLINE);
document.add(new Phrase(new Chunk(image128, 0, 0)));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk(sdf1.format(new Date()) , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("Rs-250.50/- C4" , new Font(Font.COURIER, 6, Font.BOLD))));
document.add(new Phrase("\n", new Font(Font.COURIER, 6)));
document.add(new Phrase(new Chunk("solution by : KMA infonet solution (p) Ltd." , new Font(Font.COURIER, 6, Font.BOLD))));
// document.add(Chunk.NEWLINE);
// UPC E
// BarcodeEAN codeEAN = new BarcodeEAN();
// document.add(new Paragraph("Barcode UPC-E"));
// codeEAN.setCodeType(Barcode.UPCE);
// codeEAN.setCode(data.trim());
// document.add(codeEAN.createImageWithBarcode(cb, null, null));
// codeEAN.setBarHeight(codeEAN.getSize() * 3f);
document.close();
String filename = "test.pdf";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//pras.add(MediaSize.findMedia((float) 12, (float) 8, MediaSize.MM));
//Media printable area
// pras.add(new MediaPrintableArea(0, 0, (float) 12, (float) 8,MediaPrintableArea.MM));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
//Thread.sleep(10000);
}
System.exit(0);
}
catch (Exception de)
{
System.out.println(de);
}
}
}
Bar Code generation with iText.jar
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package barcode;
/**
*
* @author amber imam
*/
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BarcodeCodabar;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.BarcodeEANSUPP;
import com.lowagie.text.pdf.BarcodeInter25;
import com.lowagie.text.pdf.BarcodePDF417;
import com.lowagie.text.pdf.BarcodePostnet;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
/**
* This example was written by Bruno Lowagie. It is part of the book 'iText in
* Action' by Manning Publications.
* ISBN: 1932394796
* http://www.1t3xt.com/docs/book.php
* http://www.manning.com/lowagie/
*/
public class Barcodes {
/**
* Generates a PDF file with different types of barcodes.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("Chapter 5: example Barcodes");
System.out.println("-> Creates a PDF file with barcodes.");
System.out.println("-> jars needed: iText.jar");
System.out.println("-> resulting PDF: barcodes.pdf");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a writer
PdfWriter writer = PdfWriter.getInstance(
// that listens to the document
document,
// and directs a PDF-stream to a file
new FileOutputStream("barcodes.pdf"));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
PdfContentByte cb = writer.getDirectContent();
// EAN 13
document.add(new Paragraph("Barcode EAN.UCC-13"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCode("4512345678906");
Paragraph p = new Paragraph("default: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
codeEAN.setGuardBars(false);
p.add(" without guard bars: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
codeEAN.setBaseline(-1f);
codeEAN.setGuardBars(true);
p.add(" text above: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
p.setLeading(codeEAN.getBarHeight());
document.add(p);
codeEAN.setBaseline(codeEAN.getSize());
// UPC A
document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
codeEAN.setCodeType(Barcode.UPCA);
codeEAN.setCode("785342304749");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// EAN 8
document.add(new Paragraph("Barcode EAN.UCC-8"));
codeEAN.setCodeType(Barcode.EAN8);
codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
codeEAN.setCode("34569870");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// UPC E
document.add(new Paragraph("Barcode UPC-E"));
codeEAN.setCodeType(Barcode.UPCE);
codeEAN.setCode("03456781");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBarHeight(codeEAN.getSize() * 3f);
// EANSUPP
document.add(new Paragraph("Bookland"));
document.add(new Paragraph("ISBN 0-321-30474-8"));
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9780321304742");
BarcodeEAN codeSUPP = new BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("55499");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
document.add(eanSupp.createImageWithBarcode(cb, null, Color.blue));
// CODE 128
document.add(new Paragraph("Barcode 128"));
Barcode128 code128 = new Barcode128();
code128.setCode("0123456789 hello");
document.add(code128.createImageWithBarcode(cb, null, null));
code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
code128.setCodeType(Barcode.CODE128_RAW);
document.add(code128.createImageWithBarcode(cb, null, null));
// Data for the barcode :
String code402 = "24132399420058289";
String code90 = "3700000050";
String code421 = "422356";
StringBuffer data = new StringBuffer(code402);
data.append(Barcode128.FNC1);
data.append(code90);
data.append(Barcode128.FNC1);
data.append(code421);
Barcode128 shipBarCode = new Barcode128();
shipBarCode.setX(0.75f);
shipBarCode.setN(1.5f);
shipBarCode.setSize(10f);
shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
shipBarCode.setBaseline(10f);
shipBarCode.setBarHeight(50f);
shipBarCode.setCode(data.toString());
document.add(shipBarCode.createImageWithBarcode(cb, Color.black,
Color.blue));
// it is composed of 3 blocks whith AI 01, 3101 and 10
Barcode128 uccEan128 = new Barcode128();
uccEan128.setCodeType(Barcode.CODE128_UCC);
uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.black));
uccEan128.setCode("0191234567890121310100035510ABC123");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.red));
uccEan128.setCode("(01)28880123456788");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.black));
// INTER25
document.add(new Paragraph("Barcode Interleaved 2 of 5"));
BarcodeInter25 code25 = new BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("411200076041001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("0611012345678");
code25.setChecksumText(true);
document.add(code25.createImageWithBarcode(cb, null, null));
document.newPage();
// POSTNET
document.add(new Paragraph("Barcode Postnet"));
BarcodePostnet codePost = new BarcodePostnet();
document.add(new Paragraph("ZIP"));
codePost.setCode("01234");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4"));
codePost.setCode("012345678");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4 and dp"));
codePost.setCode("01234567890");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode Planet"));
BarcodePostnet codePlanet = new BarcodePostnet();
codePlanet.setCode("01234567890");
codePlanet.setCodeType(Barcode.PLANET);
document.add(codePlanet.createImageWithBarcode(cb, null, null));
// CODE 39
document.add(new Paragraph("Barcode 3 of 9"));
Barcode39 code39 = new Barcode39();
code39.setCode("ITEXT IN ACTION");
document.add(code39.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode 3 of 9 extended"));
Barcode39 code39ext = new Barcode39();
code39ext.setCode("iText in Action");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
document.add(code39ext.createImageWithBarcode(cb, null, null));
// CODABAR
document.add(new Paragraph("Codabar"));
BarcodeCodabar codabar = new BarcodeCodabar();
codabar.setCode("A123A");
codabar.setStartStopText(true);
document.add(codabar.createImageWithBarcode(cb, null, null));
// PDF417
document.add(new Paragraph("Barcode PDF417"));
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "It was the best of times, it was the worst of times, "
+ "it was the age of wisdom, it was the age of foolishness, "
+ "it was the epoch of belief, it was the epoch of incredulity, "
+ "it was the season of Light, it was the season of Darkness, "
+ "it was the spring of hope, it was the winter of despair, "
+ "we had everything before us, we had nothing before us, "
+ "we were all going direct to Heaven, we were all going direct "
+ "the other way - in short, the period was so far like the present "
+ "period, that some of its noisiest authorities insisted on its "
+ "being received, for good or for evil, in the superlative degree "
+ "of comparison only.";
pdf417.setText(text);
Image img = pdf417.getImage();
img.scalePercent(50, 50 * pdf417.getYHeight());
document.add(img);
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package barcode;
/**
*
* @author amber imam
*/
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.Barcode;
import com.lowagie.text.pdf.Barcode128;
import com.lowagie.text.pdf.Barcode39;
import com.lowagie.text.pdf.BarcodeCodabar;
import com.lowagie.text.pdf.BarcodeEAN;
import com.lowagie.text.pdf.BarcodeEANSUPP;
import com.lowagie.text.pdf.BarcodeInter25;
import com.lowagie.text.pdf.BarcodePDF417;
import com.lowagie.text.pdf.BarcodePostnet;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
/**
* This example was written by Bruno Lowagie. It is part of the book 'iText in
* Action' by Manning Publications.
* ISBN: 1932394796
* http://www.1t3xt.com/docs/book.php
* http://www.manning.com/lowagie/
*/
public class Barcodes {
/**
* Generates a PDF file with different types of barcodes.
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("Chapter 5: example Barcodes");
System.out.println("-> Creates a PDF file with barcodes.");
System.out.println("-> jars needed: iText.jar");
System.out.println("-> resulting PDF: barcodes.pdf");
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a writer
PdfWriter writer = PdfWriter.getInstance(
// that listens to the document
document,
// and directs a PDF-stream to a file
new FileOutputStream("barcodes.pdf"));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
PdfContentByte cb = writer.getDirectContent();
// EAN 13
document.add(new Paragraph("Barcode EAN.UCC-13"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCode("4512345678906");
Paragraph p = new Paragraph("default: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
codeEAN.setGuardBars(false);
p.add(" without guard bars: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
codeEAN.setBaseline(-1f);
codeEAN.setGuardBars(true);
p.add(" text above: ");
p.add(new Chunk(codeEAN.createImageWithBarcode(cb, null, null), 0,
-5));
p.setLeading(codeEAN.getBarHeight());
document.add(p);
codeEAN.setBaseline(codeEAN.getSize());
// UPC A
document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
codeEAN.setCodeType(Barcode.UPCA);
codeEAN.setCode("785342304749");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// EAN 8
document.add(new Paragraph("Barcode EAN.UCC-8"));
codeEAN.setCodeType(Barcode.EAN8);
codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
codeEAN.setCode("34569870");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// UPC E
document.add(new Paragraph("Barcode UPC-E"));
codeEAN.setCodeType(Barcode.UPCE);
codeEAN.setCode("03456781");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBarHeight(codeEAN.getSize() * 3f);
// EANSUPP
document.add(new Paragraph("Bookland"));
document.add(new Paragraph("ISBN 0-321-30474-8"));
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9780321304742");
BarcodeEAN codeSUPP = new BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("55499");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
document.add(eanSupp.createImageWithBarcode(cb, null, Color.blue));
// CODE 128
document.add(new Paragraph("Barcode 128"));
Barcode128 code128 = new Barcode128();
code128.setCode("0123456789 hello");
document.add(code128.createImageWithBarcode(cb, null, null));
code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
code128.setCodeType(Barcode.CODE128_RAW);
document.add(code128.createImageWithBarcode(cb, null, null));
// Data for the barcode :
String code402 = "24132399420058289";
String code90 = "3700000050";
String code421 = "422356";
StringBuffer data = new StringBuffer(code402);
data.append(Barcode128.FNC1);
data.append(code90);
data.append(Barcode128.FNC1);
data.append(code421);
Barcode128 shipBarCode = new Barcode128();
shipBarCode.setX(0.75f);
shipBarCode.setN(1.5f);
shipBarCode.setSize(10f);
shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
shipBarCode.setBaseline(10f);
shipBarCode.setBarHeight(50f);
shipBarCode.setCode(data.toString());
document.add(shipBarCode.createImageWithBarcode(cb, Color.black,
Color.blue));
// it is composed of 3 blocks whith AI 01, 3101 and 10
Barcode128 uccEan128 = new Barcode128();
uccEan128.setCodeType(Barcode.CODE128_UCC);
uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.black));
uccEan128.setCode("0191234567890121310100035510ABC123");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.red));
uccEan128.setCode("(01)28880123456788");
document.add(uccEan128.createImageWithBarcode(cb, Color.blue,
Color.black));
// INTER25
document.add(new Paragraph("Barcode Interleaved 2 of 5"));
BarcodeInter25 code25 = new BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("411200076041001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("0611012345678");
code25.setChecksumText(true);
document.add(code25.createImageWithBarcode(cb, null, null));
document.newPage();
// POSTNET
document.add(new Paragraph("Barcode Postnet"));
BarcodePostnet codePost = new BarcodePostnet();
document.add(new Paragraph("ZIP"));
codePost.setCode("01234");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4"));
codePost.setCode("012345678");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4 and dp"));
codePost.setCode("01234567890");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode Planet"));
BarcodePostnet codePlanet = new BarcodePostnet();
codePlanet.setCode("01234567890");
codePlanet.setCodeType(Barcode.PLANET);
document.add(codePlanet.createImageWithBarcode(cb, null, null));
// CODE 39
document.add(new Paragraph("Barcode 3 of 9"));
Barcode39 code39 = new Barcode39();
code39.setCode("ITEXT IN ACTION");
document.add(code39.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode 3 of 9 extended"));
Barcode39 code39ext = new Barcode39();
code39ext.setCode("iText in Action");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
document.add(code39ext.createImageWithBarcode(cb, null, null));
// CODABAR
document.add(new Paragraph("Codabar"));
BarcodeCodabar codabar = new BarcodeCodabar();
codabar.setCode("A123A");
codabar.setStartStopText(true);
document.add(codabar.createImageWithBarcode(cb, null, null));
// PDF417
document.add(new Paragraph("Barcode PDF417"));
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "It was the best of times, it was the worst of times, "
+ "it was the age of wisdom, it was the age of foolishness, "
+ "it was the epoch of belief, it was the epoch of incredulity, "
+ "it was the season of Light, it was the season of Darkness, "
+ "it was the spring of hope, it was the winter of despair, "
+ "we had everything before us, we had nothing before us, "
+ "we were all going direct to Heaven, we were all going direct "
+ "the other way - in short, the period was so far like the present "
+ "period, that some of its noisiest authorities insisted on its "
+ "being received, for good or for evil, in the superlative degree "
+ "of comparison only.";
pdf417.setText(text);
Image img = pdf417.getImage();
img.scalePercent(50, 50 * pdf417.getYHeight());
document.add(img);
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
}
How to call and get output from stored procedure in java
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[genTicketGen] ( @head varchar(10),@price varchar(20),@cno varchar(10),@issby varchar(50),@tno varchar(50) output)
AS
BEGIN
DECLARE
@dd varchar(50),
@dd1 varchar(50),
@dd2 varchar(50),
@dt varchar(50),
@seq int,
@no int;
set @seq = 0;
set @dd = (SELECT CONVERT(VARCHAR(50), GETDATE(), 10) AS [MM-DD-YYYY]);
set @dt = (SELECT CONVERT(VARCHAR(50), GETDATE(), 103) AS [DD/MM/YYYY]);
set @dd1 = @dd + ' 00:00:00 AM';
set @dd2 = @dd + ' 11:59:59 PM';
select @no = count (*) from tblGen_Ticket_Issue where issue_datetime > @dd1 and issue_datetime < @dd2
select @seq = max(sequence) from tblGen_Ticket_Issue where issue_datetime > @dd1 and issue_datetime < @dd2
if( @no = 0)
begin
set @seq =1;
end
else
begin
set @seq = @seq+1;
end
set @tno = convert(varchar(20),@seq)+' '+@head+' '+@dt;
begin
insert into tblGen_Ticket_Issue values (@tno,@seq,@head,@price,getdate(),@cno,@issby);
end
return 1
END
..........................................................................
How to call and get output from stored procedure in java
..........................................................................
Connection con = new DbConnection().getConnection();
CallableStatement cst = con.prepareCall("{call genTicketGen(?,?,?,?,?)}");
cst.setString(1,no);
cst.setString(2, price.getText());
cst.setString(3,cno);
cst.setString(4,MainFrame.Uname);
cst.registerOutParameter(5, java.sql.Types.VARCHAR);
cst.execute();
String valtno = cst.getString(5);
System.out.println(valtno);
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author:
-- Create date:
-- Description:
-- =============================================
ALTER PROCEDURE [dbo].[genTicketGen] ( @head varchar(10),@price varchar(20),@cno varchar(10),@issby varchar(50),@tno varchar(50) output)
AS
BEGIN
DECLARE
@dd varchar(50),
@dd1 varchar(50),
@dd2 varchar(50),
@dt varchar(50),
@seq int,
@no int;
set @seq = 0;
set @dd = (SELECT CONVERT(VARCHAR(50), GETDATE(), 10) AS [MM-DD-YYYY]);
set @dt = (SELECT CONVERT(VARCHAR(50), GETDATE(), 103) AS [DD/MM/YYYY]);
set @dd1 = @dd + ' 00:00:00 AM';
set @dd2 = @dd + ' 11:59:59 PM';
select @no = count (*) from tblGen_Ticket_Issue where issue_datetime > @dd1 and issue_datetime < @dd2
select @seq = max(sequence) from tblGen_Ticket_Issue where issue_datetime > @dd1 and issue_datetime < @dd2
if( @no = 0)
begin
set @seq =1;
end
else
begin
set @seq = @seq+1;
end
set @tno = convert(varchar(20),@seq)+' '+@head+' '+@dt;
begin
insert into tblGen_Ticket_Issue values (@tno,@seq,@head,@price,getdate(),@cno,@issby);
end
return 1
END
..........................................................................
How to call and get output from stored procedure in java
..........................................................................
Connection con = new DbConnection().getConnection();
CallableStatement cst = con.prepareCall("{call genTicketGen(?,?,?,?,?)}");
cst.setString(1,no);
cst.setString(2, price.getText());
cst.setString(3,cno);
cst.setString(4,MainFrame.Uname);
cst.registerOutParameter(5, java.sql.Types.VARCHAR);
cst.execute();
String valtno = cst.getString(5);
System.out.println(valtno);
Monday, June 15, 2009
Decimal Number convert into words
////..................start Amount to word.........................////
private static final String[] tensNames = {
"",
" ten",
" twenty",
" thirty",
" forty",
" fifty",
" sixty",
" seventy",
" eighty",
" ninety"
};
private static final String[] numNames = {
"",
" one",
" two",
" three",
" four",
" five",
" six",
" seven",
" eight",
" nine",
" ten",
" eleven",
" twelve",
" thirteen",
" fourteen",
" fifteen",
" sixteen",
" seventeen",
" eighteen",
" nineteen"
};
private static String convertLessThanOneThousand(int number) {
String soFar = "";
if (number % 100 < 20) {
soFar = numNames[number % 100];
number /= 100;
} else {
soFar = numNames[number % 10];
number /= 10;
soFar = tensNames[number % 10] + soFar;
number /= 10;
}
if (number == 0) {
return soFar;
}
return numNames[number] + " hundred" + soFar;
}
public static String convert(Double number) {
// 0 to 999 999 999 999
if (number == 0) {
return "zero";
}
String snumber = Double.toString(number);
// pad with "0"
String mask = "#########.00";
DecimalFormat df = new DecimalFormat(mask);
snumber = df.format(number);
// nnnXXXnnnnnn
int crore = Integer.parseInt(snumber.substring(0, 2));
// nnnnnnXXXnnn
int lacks = Integer.parseInt(snumber.substring(2, 4));
// nnnnnnnnnXXX
int thousands = Integer.parseInt(snumber.substring(4, 6));
int hundreds = Integer.parseInt(snumber.substring(6, 9));
int paise = Integer.parseInt(snumber.substring(10, 12));
String tradcrores;
switch (crore) {
case 0:
tradcrores = "";
break;
case 1:
tradcrores = convertLessThanOneThousand(crore) + " crore ";
break;
default:
tradcrores = convertLessThanOneThousand(crore) + " crore ";
}
String result = tradcrores;
String tradlacks;
switch (lacks) {
case 0:
tradlacks = "";
break;
case 1:
tradlacks = convertLessThanOneThousand(lacks) + " lacks ";
break;
default:
tradlacks = convertLessThanOneThousand(lacks) + " lacks ";
}
result = result + tradlacks;
String tradThousands;
switch (thousands) {
case 0:
tradThousands = "";
break;
case 1:
tradThousands = "one thousand ";
break;
default:
tradThousands = convertLessThanOneThousand(thousands) + " thousand ";
}
result = result + tradThousands;
String tradHundrads;
tradHundrads = convertLessThanOneThousand(hundreds);
result = result + tradHundrads + " Rupees ";
if (paise > 0) {
String txt_paise = "and " + convertLessThanOneThousand(paise) + " paise Only";
result = result + txt_paise;
} else {
String txt_paise = "and Zero paise Only";
result = result + txt_paise;
}
// remove extra spaces!
return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");
}
private static final String[] tensNames = {
"",
" ten",
" twenty",
" thirty",
" forty",
" fifty",
" sixty",
" seventy",
" eighty",
" ninety"
};
private static final String[] numNames = {
"",
" one",
" two",
" three",
" four",
" five",
" six",
" seven",
" eight",
" nine",
" ten",
" eleven",
" twelve",
" thirteen",
" fourteen",
" fifteen",
" sixteen",
" seventeen",
" eighteen",
" nineteen"
};
private static String convertLessThanOneThousand(int number) {
String soFar = "";
if (number % 100 < 20) {
soFar = numNames[number % 100];
number /= 100;
} else {
soFar = numNames[number % 10];
number /= 10;
soFar = tensNames[number % 10] + soFar;
number /= 10;
}
if (number == 0) {
return soFar;
}
return numNames[number] + " hundred" + soFar;
}
public static String convert(Double number) {
// 0 to 999 999 999 999
if (number == 0) {
return "zero";
}
String snumber = Double.toString(number);
// pad with "0"
String mask = "#########.00";
DecimalFormat df = new DecimalFormat(mask);
snumber = df.format(number);
// nnnXXXnnnnnn
int crore = Integer.parseInt(snumber.substring(0, 2));
// nnnnnnXXXnnn
int lacks = Integer.parseInt(snumber.substring(2, 4));
// nnnnnnnnnXXX
int thousands = Integer.parseInt(snumber.substring(4, 6));
int hundreds = Integer.parseInt(snumber.substring(6, 9));
int paise = Integer.parseInt(snumber.substring(10, 12));
String tradcrores;
switch (crore) {
case 0:
tradcrores = "";
break;
case 1:
tradcrores = convertLessThanOneThousand(crore) + " crore ";
break;
default:
tradcrores = convertLessThanOneThousand(crore) + " crore ";
}
String result = tradcrores;
String tradlacks;
switch (lacks) {
case 0:
tradlacks = "";
break;
case 1:
tradlacks = convertLessThanOneThousand(lacks) + " lacks ";
break;
default:
tradlacks = convertLessThanOneThousand(lacks) + " lacks ";
}
result = result + tradlacks;
String tradThousands;
switch (thousands) {
case 0:
tradThousands = "";
break;
case 1:
tradThousands = "one thousand ";
break;
default:
tradThousands = convertLessThanOneThousand(thousands) + " thousand ";
}
result = result + tradThousands;
String tradHundrads;
tradHundrads = convertLessThanOneThousand(hundreds);
result = result + tradHundrads + " Rupees ";
if (paise > 0) {
String txt_paise = "and " + convertLessThanOneThousand(paise) + " paise Only";
result = result + txt_paise;
} else {
String txt_paise = "and Zero paise Only";
result = result + txt_paise;
}
// remove extra spaces!
return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ");
}
Friday, May 29, 2009
Some fresh javascript example
www.sandbox.leigerber.com
www.1stwebdesigner.com/resources/57-free-image-gallery-slideshow-and-lightbox-solutions/
www.1stwebdesigner.com/resources/57-free-image-gallery-slideshow-and-lightbox-solutions/
Wednesday, April 22, 2009
How to set System tray icon in swing
SystemTray tray = SystemTray.getSystemTray();
Image ico = Toolkit.getDefaultToolkit().getImage("services_gen.gif");
TrayIcon tric=new TrayIcon(ico, "NEWS",popup);
try
{
tray.add(tric);
}
catch (AWTException ex)
{
System.out.println(ex);
}
Image ico = Toolkit.getDefaultToolkit().getImage("services_gen.gif");
TrayIcon tric=new TrayIcon(ico, "NEWS",popup);
try
{
tray.add(tric);
}
catch (AWTException ex)
{
System.out.println(ex);
}
sql server and access type 4 connection code
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://121.241.213.156:1433;databasename=test;user=test;password=test;");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\\\\c71\\\\My Sql\\\\1\\\\att.mdb");
con = DriverManager.getConnection("jdbc:sqlserver://121.241.213.156:1433;databasename=test;user=test;password=test;");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\\\\c71\\\\My Sql\\\\1\\\\att.mdb");
Ajax Simple Example to call Servlet
<html>
<head>
<title>Ajax Example</title>
<script language="Javascript">
function postRequest(strURL) {
var xmlHttp;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
}catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
xmlHttp.open('POST', strURL, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
updatepage(xmlHttp.responseText);
}
}
xmlHttp.send(strURL);
}
function updatepage(str){
//for more than one data use
// var arr = str.split(“separator symbol”);
// for(var i = 0;i<arr.length();i++)
//{
// get the data arr[i] and place it in page using //object.innerHTML = arr[i];
//}
document.getElementById("result").innerHTML =
"<font color='red' size='5'>" + str + "</font>";;
}
function showCurrentTime(){
var rnd = Math.random();
var url="servlet_url?id="+rnd;
postRequest(url);
}
</script>
</head>
<body>
<h1 align="center"><font color="#000080">Ajax Example</font></h1>
<p><font color="#000080"> This very simple Ajax Example retrieves the
current date and time from server and shows on the form. To view the current
date and time click on the following button.</font></p>
<form name="f1">
<p align="center"><font color="#000080"> <input value=" Show Time "
type="button" onclick='JavaScript:showCurrentTime()' name="showdate"></font></p>
<div id="result" align="center"></div>
</form>
<div id=result></div>
</body>
</html>
.................................
Servlet coding.
just print the response data using out.println("data"+"separator symbol");
<head>
<title>Ajax Example</title>
<script language="Javascript">
function postRequest(strURL) {
var xmlHttp;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
}catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
xmlHttp.open('POST', strURL, true);
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
updatepage(xmlHttp.responseText);
}
}
xmlHttp.send(strURL);
}
function updatepage(str){
//for more than one data use
// var arr = str.split(“separator symbol”);
// for(var i = 0;i<arr.length();i++)
//{
// get the data arr[i] and place it in page using //object.innerHTML = arr[i];
//}
document.getElementById("result").innerHTML =
"<font color='red' size='5'>" + str + "</font>";;
}
function showCurrentTime(){
var rnd = Math.random();
var url="servlet_url?id="+rnd;
postRequest(url);
}
</script>
</head>
<body>
<h1 align="center"><font color="#000080">Ajax Example</font></h1>
<p><font color="#000080"> This very simple Ajax Example retrieves the
current date and time from server and shows on the form. To view the current
date and time click on the following button.</font></p>
<form name="f1">
<p align="center"><font color="#000080"> <input value=" Show Time "
type="button" onclick='JavaScript:showCurrentTime()' name="showdate"></font></p>
<div id="result" align="center"></div>
</form>
<div id=result></div>
</body>
</html>
.................................
Servlet coding.
just print the response data using out.println("data"+"separator symbol");
Monday, April 20, 2009
show picture from database in jsp
rs1 = st1.executeQuery(strQuery);
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.setHeader("Content-disposition","attachment; filename=" +filename);
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
out.write("image");
}
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.setHeader("Content-disposition","attachment; filename=" +filename);
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
out.write("image");
}
Subscribe to:
Posts (Atom)
