hi..,i am new in printing in dot matrix printer. i just want to print a money receipt of width=9 inch and height=6 inch.
but the problem is after printing the printer automatically drags some paper blank.means it prints 9*12 inch (9*6 printed & 9*6 blank). so that the second page printing loose its track.
here is my code
HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper paper = pf.getPaper();
pf.setOrientation(PageFormat.PORTRAIT);
paper.setSize(9*72,6*72);
paper.setImageableArea(0.5*72,0.5*72,9*72,6*72);
pf.setPaper(paper);


job.setPrintable((Printable) amr,pf);
try {
if(job.printDialog(attributes))

job.print();
} catch (PrinterException ex) {
JOptionPane.showMessageDialog(this, "Cannot Print Due TO Printer Problem");
}

i also use print function as below:
public int print(Graphics g,PageFormat pageFormat,int pageIndex) throws PrinterException
{
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.black);
//Image img =Toolkit.getDefaultToolkit().getImage("Images:\\Ja ganath.jpg");
//g2.drawImage(img, 20, 20, this);
int fontHeight=g2.getFontMetrics().getHeight();
System.out.println("fontHeight="+fontHeight);

//System.out.println("fontDescent="+fontDescent);
pageFormat.setOrientation(PageFormat.PORTRAIT);
double pageHeight=pageFormat.getImageableHeight()-fontHeight;
System.out.println("pageHeight="+pageHeight);
double pageWidth=pageFormat.getImageableWidth();
System.out.println("pageWidth="+pageWidth);
Dimension d0;
d0=getSize();
double panelWidth=(double)d0.width;
System.out.println("panelWidth="+panelWidth);
double panelHeight=(double)d0.height;
System.out.println("panelHeight="+panelHeight);
double scale=1;
System.out.println("scale="+scale);

if (panelWidth>=pageWidth)
{
scale=pageWidth/panelWidth;
System.out.println("scale="+scale);
}
double panelWidthOnPage=panelWidth*scale;
System.out.println("panelWidthOnPage="+panelWidthO nPage);
double oneRowHeight=fontHeight;
System.out.println("oneRowHeight="+oneRowHeight);
int numRowsOnAPage=(int)(pageHeight/oneRowHeight);
//System.out.println("jlabel 133 x=="+jLabel3.getX());
double pageHeightForPanel=oneRowHeight*numRowsOnAPage;
System.out.println("pageHeightForPanel="+pageHeigh tForPanel);
int totalNumPages=(int)Math.ceil((double)panelHeight/pageHeight);
System.out.println("totalNumPages="+totalNumPages) ;
totalNumPages=1;
if (pageIndex>=totalNumPages)
{
return (NO_SUCH_PAGE);
}

g2.translate(pageFormat.getImageableX()+0.5,pageFo rmat.getImageableY()+0.5);
//g2.translate(pageFormat.getImageableX(),pageFormat .getImageableY());
g2.translate(0f,-pageIndex*pageHeightForPanel);
//Image img1 = Toolkit.getDefaultToolkit().getImage("Images/untitled.PNG");
Image img1 = Toolkit.getDefaultToolkit().getImage("sedilogo_03_ 03.jpg");

g2.drawString(heading.getText(),100,10 );

//g2.setFont(new Font("Verdana", Font.PLAIN,10));
g2.setFont(new Font("Sans Serif", Font.PLAIN,11));
g2.drawString(head1.getText(),100,23 );
g2.drawString(head3.getText(),100,36 );
g2.drawString("Branch Name: "+home.branchname,100,49);
g2.drawString("Branch ID: "+home.branchID,100,62);
//g2.drawString(head3.getText(),100,40 );

g2.drawString("Receipt No :",17,80);
g2.drawString(recpt.getText(),95,80);
g2.drawString("Name And Address Of The Agent", 17, 110);
g2.drawLine(17, 115, 182, 115);
g2.drawString(name.getText(), 17,130);
g2.drawString(addr1.getText(), 17,145);
g2.drawString(addr2.getText(), 17,160);
.
.
.
}
i can't get any idea how to stop printing in 9*6inch.
please help me.

thanks..