Hi, I've looked on the different tutorial and I can't find any thing that I understand so I would be happy for any answer I get.
This is my code, the problem is that it not printout on multiple pages so all lines does not being printed.
public void pprint()
{
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat formating = new PageFormat();
formating = printerJob.pageDialog(formating);
book = new Book();
book.append(this, formating);
printerJob.setPageable(book);
boolean doPrint = printerJob.printDialog();
if (doPrint)
{
try
{
printerJob.print();
}
catch (PrinterException exception)
{
System.err.println("Printing error: " + exception);
}
}
}
public int print(Graphics g, PageFormat format, int pageIndex)
{
Graphics2D g2d = (Graphics2D) g;
g2d.translate(format.getImageableX(), format.getImageableY());
g2d.setPaint(Color.black);
int y = 15;
for(int j = 0; j < sumOfRows; j++)
{
if(!text[j].getText().equals(""))
{
int lineLength = text[j].getText().length();
if (lineLength > 55)
{
String temp1 = text[j].getText().substring(0, 55);
String temp2 = text[j].getText().substring(56, lineLength);
g2d.drawString(temp1, 15, y);
y += 15;
g2d.drawString(temp2, 15, y);
}
else
g2d.drawString(text[j].getText(), 15, y);
}
y += 15;
}
return Printable.PAGE_EXISTS;
}
Would be happy for answer
Mattias Fransson