Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2004, 05:58 PM
Registered User
 
Join Date: Jun 2004
Location: Washington, D.C., USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to print multiple text page

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. 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);
    }

Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Print a page without changing page setup nrajeshatwork Servlets 1 May 23rd, 2007 10:09 AM
Print arbitrary text Joachim Hofmann SQL Language 0 November 14th, 2005 06:23 AM
print the hidden page without the print dialog box kayzem Classic ASP Basics 0 April 21st, 2005 11:31 PM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM
don't want some object/text to print with page abbylee26 Javascript How-To 2 February 18th, 2004 12:43 PM



All times are GMT -4. The time now is 07:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.