The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
March 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Printing in JAVA

Posted by Sumant on March 12, 2001 at 6:23 PM

Hi there I am trying to print 100 lines ( max. 30 lines per page )
but when I run the program my 1st page comes out blank and 2nd page onwards it prints correct output, 31 to 60 then 61 - 90....
attached is the class that implements Printable ....
please le me know the patch to correct this problem.

//----------------
class PaintCover implements Printable
{

int nLineNo = 1;
int nOldPageNo = 0;
int nNoOfLinesOnPage = 30;
int nMaxRows = 100;
int nRowNo = 1;

Font fnt = new Font("Verdana", Font.PLAIN, 10);

public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
{
g.setFont(fnt);
g.setColor(Color.black);
Graphics2D g2 = (Graphics2D) g;
int x,y;

if(nRowNo > nMaxRows)
return Printable.NO_SUCH_PAGE;

x = (int)pf.getImageableX();
while(nLineNo <= nNoOfLinesOnPage)
{
y = (int)pf.getImageableY() + nLineNo*10;
g2.drawString(x+", "+y+" This is RowNo : "+ nRowNo , x ,y );
nRowNo++;
nLineNo++;
if(nRowNo > nMaxRows)
break;
}
if( nOldPageNo != pageIndex )
{
nOldPageNo = pageIndex;
nLineNo = 1;
}
return Printable.PAGE_EXISTS;
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us