• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

printing to multiple of pages

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic