Hi,
I am trying to do some printing in my
Java program....
this is what I am doing.... I pass an ArrayList to the class performing the print ... and then create a graphics object using the data in the ArrayList..... And print it.....
public int print(Graphics g, PageFormat pageFormat, int page) throws
PrinterException
{
int i;
Graphics2D g2d = (Graphics2D) g;
if (page == 0)
{
g2d.translate (pageFormat.getImageableX(), pageFormat.getImageableY());
g2d.setFont(new java.awt.Font("Microsoft Sans Serif", 0,11));
int x =0;
int y= 45;
// Printing the data from the Array list.
// The way I am formatting to print.. I can print only 16 records on one page.
So it needs to go to the next page after 16 records.
for(i=0;i<printArray.size();i++)
{
// trying to position the data into tow columns .. with all odd rows on one side and even on another.
if(checknum_odd_even(i))
{
x =0;
// trying to position the data.
Object[] prnObject = (Object[]) printArray.get(i);
g2d.drawString(prnObject[0].toString(), x, y);
y = y + 15;
g2d.drawString(prnObject[1].toString(), x, y);
y = y + 15;
g2d.drawString(prnObject[2].toString(), x, y);
y = y + 45;
}
else
{
// trying to position the data.
x=300;
y=y-75;
Object[] prnObject = (Object[]) printArray.get(i);
g2d.drawString(prnObject[0].toString(), x, y);
y = y + 15;
g2d.drawString(prnObject[1].toString(), x, y);
y = y + 15;
g2d.drawString(prnObject[2].toString(), x, y);
y = y + 45;
}
}
return (PAGE_EXISTS);
}
else return (NO_SUCH_PAGE);
}
}
This works fine.. as long as it is limited to only one page .... but i don't know how to print multiple pages ,,,
for example .. if there are 30 items in the array list that I am sending to the class ... it should print the first 16 on page one and the next 14 on page two .... .. I went through the javax.print .. but did not understand much .. will really appreciate if someone could help me .. give me an idea as per what needs to be done ..
Thanks,
Sandeep