How do we print multiple components each in a different page?

hello
I would like to print multiple JPanels (lets say an array) each in a different page.
The question I ask is about the following code
         printerJob.setPrintable(printTable.getInstance(), pageFormat);
              try
                    if (printerJob.printDialog())
                         printerJob.print();
                    }

Lets say that we have the following code. How do we modify it?
* This example is from the book "Java Foundation Classes in a Nutshell".
* Written by David Flanagan. Copyright (c) 1999 by O'Reilly & Associates. 
* You may distribute this source code for non-commercial purposes only.
* You may study, modify, and use this example for any purpose, as long as
* this notice is retained.  Note that this example is provided "as is",
* WITHOUT WARRANTY of any kind either expressed or implied.
import java.awt.*;
import java.awt.print.*;
import java.io.*;
import java.util.Vector;
public class PageableText implements Pageable, Printable {
  // Constants for font name, size, style and line spacing
  public static String FONTFAMILY = "Monospaced";
  public static int FONTSIZE = 10;
  public static int FONTSTYLE = Font.PLAIN;
  public static float LINESPACEFACTOR = 1.1f;
  PageFormat format;   // The page size, margins, and orientation
  Vector lines;        // The text to be printed, broken into lines
  Font font;           // The font to print with
  int linespacing;     // How much space between lines
  int linesPerPage;    // How many lines fit on a page
  int numPages;        // How many pages required to print all lines
  int baseline = -1;   // The baseline position of the font.
  /** Create a PageableText object for a string of text */
  public PageableText(String text, PageFormat format) throws IOException {
    this(new StringReader(text), format);
  /** Create a PageableText object for a file of text */
  public PageableText(File file, PageFormat format) throws IOException {
    this(new FileReader(file), format);
  /** Create a PageableText object for a stream of text */
  public PageableText(Reader stream, PageFormat format) throws IOException {
    this.format = format;
    // First, read all the text, breaking it into lines.
    // This code ignores tabs, and does not wrap long lines.
    BufferedReader in = new BufferedReader(stream);
    lines = new Vector();
    String line;
    while((line = in.readLine()) != null)
      lines.addElement(line);
    // Create the font we will use, and compute spacing between lines
    font = new Font(FONTFAMILY, FONTSTYLE, FONTSIZE);
    linespacing = (int) (FONTSIZE * LINESPACEFACTOR);
    // Figure out how many lines per page, and how many pages
    linesPerPage = (int)Math.floor(format.getImageableHeight()/linespacing);
    numPages = (lines.size()-1)/linesPerPage + 1;
  // These are the methods of the Pageable interface.
  // Note that the getPrintable() method returns this object, which means
  // that this class must also implement the Printable interface.
  public int getNumberOfPages() { return numPages; }
  public PageFormat getPageFormat(int pagenum) { return format; }
  public Printable getPrintable(int pagenum) { return this; }
   * This is the print() method of the Printable interface.
   * It does most of the printing work.
  public int print(Graphics g, PageFormat format, int pagenum) {
    // Tell the PrinterJob if the page number is not a legal one.
    if ((pagenum < 0) | (pagenum >= numPages))
      return NO_SUCH_PAGE;
    // First time we're called, figure out the baseline for our font.
    // We couldn't do this earlier because we needed a Graphics object
    if (baseline == -1) {
      FontMetrics fm = g.getFontMetrics(font);
      baseline = fm.getAscent();
    // Clear the background to white.  This shouldn't be necessary, but is
    // required on some systems to workaround an implementation bug
    g.setColor(Color.white);
    g.fillRect((int)format.getImageableX(), (int)format.getImageableY(),
               (int)format.getImageableWidth(),
               (int)format.getImageableHeight());
    // Set the font and the color we will be drawing with.
    // Note that you cannot assume that black is the default color!
    g.setFont(font);
    g.setColor(Color.black);
    // Figure out which lines of text we will print on this page
    int startLine = pagenum * linesPerPage;
    int endLine = startLine + linesPerPage - 1;
    if (endLine >= lines.size())
      endLine = lines.size()-1;
    // Compute the position on the page of the first line.
    int x0 = (int) format.getImageableX();
    int y0 = (int) format.getImageableY() + baseline;
    // Loop through the lines, drawing them all to the page.
    for(int i=startLine; i <= endLine; i++) {
      // Get the line
      String line = (String)lines.elementAt(i);
      // Draw the line.
      // We use the integer version of drawString(), not the Java 2D
      // version that uses floating-point coordinates. A bug in early
      // Java2 implementations prevents the Java 2D version from working.
      if (line.length() > 0)
        g.drawString(line, x0, y0);
      // Move down the page for the next line.
      y0 += linespacing; 
    // Tell the PrinterJob that we successfully printed the page.
    return PAGE_EXISTS;
   * This is a test program that demonstrates the use of PageableText
  public static void main(String[] args) throws IOException, PrinterException {
    // Get the PrinterJob object that coordinates everything
    PrinterJob job = PrinterJob.getPrinterJob();
    // Get the default page format, then ask the user to customize it.
    PageFormat format = job.pageDialog(job.defaultPage());
    // Create PageableText object, and tell the PrinterJob about it
    job.setPageable(new PageableText(new File("file.txt"), format));
    // Ask the user to select a printer, etc., and if not canceled, print!
    if (job.printDialog())
         job.print();
}thank you in advance

Similar Messages

  • How do I print multiple (4) photos on one page with a border around each?

    How do I print multiple photos on one page with a border around each? I've gone the contact sheet route and adjusted the number of columns but there's only outer margins and very little white space between the photos down the middle of the page.

    Ok, now I feel stupid! I always thought I was printing 6 x 4 but now I realise I can't have done!!
    The photos that I used to print are approx. 5.2" x 4" (i.e. 4 fitted nicely on a page & I had to cut the boarder off).
    I guess I just need to play with different sizes under the 'custom' option in order to get the biggest possible picture!
    Thanks for the help

  • How can I print multiple PDF files at once using Windows 7?

    How can I print multiple PDF files at once, on an HP LJ Pro 400 xcolocr printer without opening each
    one separately using Windows 7?

    I am sorry, but to get your issue more exposure I would suggest posting it in the commercial forums since this is a commercial printer. You can do this at http://h30499.www3.hp.com/hpeb/
    I hope this helps.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • HT204364 how do I order multiple card or postcard with different images each one in same order?

    how do I order multiple card or postcard with different images each one in same order?
    I keep paying separate shipping cost for each different photo

    That is not an option - with the exeption of photo prints you can only identical items on one order
    LN

  • Print Multiple copies of report, and resetting Page number for each copy.

    Dear frnds!
    i am using developer 6i reports i have a problem.
    i want to Print Multiple copies of report, and resetting Page number for each copy" that is 4 copies of an invoice is required
    1 - for user copy
    2- gate copy
    3- accounts office
    4- office copy
    any body please tell me the solution "i am using oracle 9i and developer 6i"
    Thanx
    Ibrar

    Hi,
    I was wondering if you were able to get your multiple copies working? Below is what I have so far, just trying to get it to work before changing the actual template.
    <?for-each-group@section:R5542520/Pick_Slips_Detail_Lines_S3;PickSlipNumber_ID260?>
    <?variable@incontext:G1;R5542520/Pick_Slips_Detail_Lines_S3;PickSlipNumber_ID260?>
    <?for-each@section:xdoxslt:foreach_number($_XDOCTX,1,3,1)?>
    HEADER
    PSN: <?$G1/Pick_Slip_Number_Display_ID54?>
    PSN Detail: <?$G1/PickSlipNumber_ID260?>
    Page 1 of 3
    <?start:body?>
    BODY
    <?$G1/LineNumber_ID6?>
    <?end body?>
    FOOTER
    <?end for-each?>
    <?end for-each-group?>
    XML:
    <R5542520>
    <Pick_Slips_Detail_Lines_S24>
    <Header_Custom_Section_S24>
    <Pick_Slip_Number_Display_ID54>123456</Pick_Slip_Number_Display_ID54>
    <PickSlipNumber_ID260>123456</PickSlipNumber_ID260>

  • How can I print multiple copies of same photo onto one page on iPhoto 9.5.1?

    How can I print multiple copies of same photo onto one page on iPhoto 9.5.1? I was able to do it on the old iPhoto, but can't seem to be able to do it on the new iPhoto. Grrr...

    Photos does the same thing.... Only workaround I can come up with is to create a template in Pages and copy &amp; paste.

  • Label Printing Using Address Book - How can I Print multiple labels of the same name?

    Label Printing Using Address Book - How can I Print multiple labels of the same name?

    I used to be able to print multiple copies of the same picture on one page using iphoto. There was a customise button when you went through to print and it was there somewhere. I can't see it anymore - maybe since an upgrade.
    It's gone. But as a work-around, duplicate your photo (⌘D) to create as many versions as you want copies and select all at once. Then use the "Custom" print layout and set the photo size you want.
    After printing, trash the added versions.

  • How can I print multiple copies of the same photo onto one sheet of paper?  Do I have to Duplicate the photo in iPhoto and then select them all?

    How can I print multiple copies of the same photo onto one sheet of paper?  Do I have to Duplicate the photo in iPhoto and then select them all?

    no - you simply have to select the option to print mucliples of a photo on a page
    select the photo and go to the file menu ==> print - select the printer, paper size and print size and click customize - in the tool bar click on the settings icon (the gear looking thingy) and select "multiple of the same photo per page" and the preview will reflect this option showing a full page of the selected size photos
    LN

  • How do i print multiple columns on 1 page in numbers

    I think I am over thinking this but I have confused myself. I am using Numbers to create a spreadsheet of family names with their corresponding number. I would like to print multiple columns of names on one page to save paper but I can't figure how to do it. Will someone please help me???

    Hi BestMommy,
    Here is one way. Don't mess with your database. Create a new table for printing.
    Database with a Header Row (named Table 1 as an example) might look like this:
    Name
    1
    Name 1
    2
    Name 2
    3
    Name 3
    4
    Name 4
    5
    Name 5
    6
    Name 6
    7
    Name 7
    8
    Name 8
    9
    Name 9
    10
    Name 10
    11
    Name 11
    12
    Name 12
    13
    Name 13
    14
    Name 14
    15
    Name 15
    New table for printing:
    Name
    Name
    1
    Name 1
    8
    Name 8
    2
    Name 2
    9
    Name 9
    3
    Name 3
    10
    Name 10
    4
    Name 4
    11
    Name 11
    5
    Name 5
    12
    Name 12
    6
    Name 6
    13
    Name 13
    7
    Name 7
    14
    Name 14
    Formula in A2
    =Table 1::A2
    Formula in B2
    =Table 1::B2
    Formula in C2
    =Table 1::A9
    Formula in D2
    =Table 1::B9
    So it loops back from the bottom of a page to start a new column.
    I made this example small for the pics, but obviously you could have more rows and columns per page.
    Having created your table for printing, select it, Cut, add a new sheet and Paste. Print just that sheet.
    Have a look at 'More Like This' at the bottom of this page. Trying to format page to print table in two columns Jerry suggests using Pages instead of Numbers.
    Regards,
    Ian.
    Edit: Having created your table for printing, select it, Cut, add a new sheet and Paste. Print just that sheet. Ian.

  • How do I print multiple pages (2) to one A4 page?

    Hi folks,
    How do I print multiple pages (2) to one A4 page (as you can in a PDF) ?
    There is no option when I try to print & I have checked advanced etc. I have tried opening as a PDF. I have tried printing to PDF but it won't allow.
    Any ideas or suggestions would be greatly welcomed - I don't fancy printing the whole 188 pages, but I need them all!
    Thanks,

    Hi Chris,
    Try this, and if you have any trouble get back and we'll trouble shoot, but I think it will work for you.
    Open System Preferences.
    Select Print & Scan
    Click on your printer under Printers in the left pane
    Click "Open Print Queue", on the right
    The print queue app will appear on your Dock
    Open a Finder window containing your files to be printed and select them all
    Drag the files from Finder to Print Queue icon in Dock
    Regards,
    Jerry

  • In iPhoto 9.5.1, how do I print multiple copies of the same photo on a sheet ?

    In iPhoto 9.5.1, how do I print multiple copies of the same photo on a sheet ?
    I am somehow missing the "settings" which allowed me to do this in earlier versions.
    Grateful for any hints. Thank you. Znon

    That is not a feature of iPhoto - suggest to Apple - iPhoto Menu ==> provide iPhoto feedback.
    You can only do it by duplicating the photos "n-1" times to make "n" prints and selecting all copies then print
    LN

  • How do I print multiple copies of a page in a PDF File?

    How do I print multiple copies of a page in a PDF File?  For some reason I tell it to print, for example, 3 or 4 copies of a certain page and it will only print one copy!!!

    OS X 10.9.5Adobe Reader 11.0.10
    I increase the number of copies to 3, 4, or 5 (etc.) but it would still only print one copy of the designated page/pages.
          From: pwillener <[email protected]>
    To: Caren Harris <[email protected]>
    Sent: Friday, March 6, 2015 9:17 PM
    Subject:  How do I print multiple copies of a page in a PDF File?
    How do I print multiple copies of a page in a PDF File?
    created by pwillener in Adobe Reader - View the full discussionOperating system?  Reader version? If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7262032#7262032 and clicking ‘Correct’ below the answer Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7262032#7262032 To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"  Start a new discussion in Adobe Reader by email or at Adobe Community For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

  • How do you print multiple different images on a single page in preview

    How do you print multiple different images on a single page in preview?

    Chances are no one who saw your question knew the answer.
    Unless you're willing to share the answer you found here, then anyone else like you searching for the problem who comes across this thread will also be unable to thank you for providing the answer too.  

  • How do you print multiple photos from iphoto?

    How do you print multiple photos from iphoto?

    select the photo and print - select the printer, paper size an print size, then click customize and under setting select multiple photos per page and click print - make any printer specific selections and pnt to make the prints
    LN

  • How can I print multiple photos per page?  It was simple in earlier versions of iPhoto.

    How can I print multiple photos per page?  It was simple in earlier versions of iPhoto.

    Do you want to print several different photos per page or multiples of the same photo?
    If you want to print several different photos,select them all at once and press command-P for "Print".  Pick the Custom Layout and adjust the photo size suitably.
    If you want multiples of the same photo, duplicate the photo several times and select all copies at once, then press command-P.

Maybe you are looking for

  • HT5649 Version 11.1.4 Does Not Work on my system

    I had itunes version 11.1.3.8 and it was working just fine. I believe this version is the 32 bit version. itunes sent me version 11.1.4 which is a 64 bit version and it DOES NOT work on my system. Some how this important file was deleted. And I keep

  • My server added junk at the bottom of my code

    Here's what they added automatically: <!-- text below generated by server. PLEASE REMOVE --><!-- Counter/Statistics data collection code --><script language="JavaScript" src=" http://hostingprod.com/js_source/geov2.js"></script><script language="java

  • Cannot import jpg photos into iPhoto'09

    Before posting, I tried to read previous posts and Google'd the issue, but I have not found a solution that works. Someone sent us pictures from our recent trip to Disney World. I downloaded the pictures to a folder under the Download folder. The pic

  • Dragon Dictate for iPad2 in New Zealand ?

    I would really appreciate feedback, confirmation and assistance with the following query. I have recently just got an iPad 2 and live here in New Zealand and really want to get Dragon Dictate, however, when I go to any link on the Internet and then g

  • PS 7 locks when certain action is selected

    I have had this happen before but can't remember the fix. I'll write it down this time if someone can help me. As far as I can tell everything works except this... Open an image, any image. Select "Image": Select "Adjustments" Select "Levels"....The