Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2004, 05:58 PM
Registered User
 
Join Date: Jun 2004
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);
    }






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





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