Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to print multiple page text  RSS feed

 
John McDonald
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JGurus,
I am impleting a Printable class to print out a text file. I loaded the text into a vector. Each element I store in vector is a single line. I try to use a while loop to fill the page. If the increment of the vertical lineIndex exceeds the page height, I then return PAGE_EXIST. If all elements in the vector has been printed out, I still return the PAGE_EXISTS but set the flag for the next call to terminate. I don't understant why I keep print out a blank page. Could someone help? Thanks a lot. The fragment of code is follow:

public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
{
int wPage = (int)pf.getImageableWidth();
int hPage = (int)pf.getImageableHeight();



if (lines == null)
{
lines = textLoader.getPrintText(g, wPage);
MAX_PAGES = lines.size();
}

g.translate((int)pf.getImageableX(), (int)pf.getImageableY());

if (rememberedEOF) return Printable.NO_SUCH_PAGE;

int y = 0;//(int) pf.getImageableY() + 12;

System.out.println("wPage " + wPage + " hPage " + hPage);

while ((y + linee.getHeight()) < hPage)
{
System.out.println("Line " + lineIndex);
Line linee = (Line)lines.elementAt(lineIndex);
// String line = raf.readLine();
y += linee.getHeight();



System.out.print("y " + y + " Page Length " + hPage);
printLine(linee, g, y);
++lineIndex;

if (lineIndex >= lines.size()) {
System.out.println("Finished Painting " + lineIndex);
rememberedEOF = true;
break;
}

}

System.out.println("Number calls " + (++count) + " index " + pageIndex + " height " + hPage);
return Printable.PAGE_EXISTS;

// return Printable.NO_SUCH_PAGE;

}


private void printLine(Line line, Graphics g, int linePosition)
{
System.out.println("\tprint:");
while(line.hasMoreSegment())
{
Segment segment = line.nextSegment();
g.setFont(segment.getFont());
System.out.print("\t" + segment.getText());
g.drawString(segment.getText(), segment.getStart(), linePosition);

if (segment.isUnderline())
{
g.drawLine(segment.getStart(), linePosition + 2, segment.getEnd(), linePosition + 2);
}
} // end of line
System.out.println("\n\tend print " + linePosition);
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!