• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

printing to multiple of pages

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
bacon. tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic