Printing of JTable on multiple pages

i have jtable that contain too many column when i give printing through table.print()
then table is print but it is too small to see it.
i want some column of table on one page and some column on another page
Plz give me source code
so plz help me

Hello there sagar
Cant quite give you source code, but a fellow named stanislav has created some very interesting examples to do what you want but with JTextComponents. From what I have seen with the examples a little bit of tinkering should be able to get the same thing happening for JTable as well.
Best of luck here is the site:
http://java-sl.com/articles.html
Jason Barraclough.

Similar Messages

  • How can i print a AdvancedDataGrid in multiple pages with ColumnHeaders?

    Hi all,
    I need to print a AdavancedDataGrid in multiple pages with columnheaders in all pages.
    Rite now, i can able to print column headers in first page only.
    is there any chance to split the ADG into multiple pages with columnheaders??
    Thanks in Advance
    Shravan.

    Shardul,
    Thanks for your help.
    Your logic is working fine when i have a single datagrid.
    What i'm doing here is, i took a VBox(playout) and printing 2 ADG's in that,so the column headers of 2nd ADG are not printing when it continues to next page.
    Here is the sample code:
    custComp1
    custComp2 are ADG's
    <mx:VBox id="playout" width="100%" visible="false" includeInLayout="false"></mx:VBox>
    private function preparePrint():void{
    var x:custComp1 = new custComp1();
    var y:custComp2 = new custComp2();
    x.dataProvider = arrayColl1;
    playout.addChild(x);
    if(arrayColl2 >=1){
    playout.addChild(y);
    y.dataprovider = arryColl2;
    while(y.adg.validNextPage){
    playout.addChild(y);
    y.adg.nextPage();
    private function doPrint(event:Event):void{
    var printJob:FlexPrintJob = new FlexPrintJob();
    if(printJob.start()) {
    playout.includeInLayout = true;
    playout.visible = true;
    printJob.addObject(playout);
    printJob.send();
    playout.visible = false;
    playout.includeInLayout = false;
    is there any way to get column headers when we use printing multiple ADG's in a VBox?

  • Print JTable with Multiple pages and rows

    I took the printing example at http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html#pe and modified it a bit to include the following:
    1) To Print Multiple pages
    2) To wrap lines that is too long for the column
    3) To print with a more proffesional style, so that it doesn't look like a screen capture is printed
    4) To align the numbers to the right and center column headings
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.Dimension;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import java.text.*;
    public class Report implements Printable
         private final int LEFT_ALIGN = -1;
         private final int CENTER_ALIGN = 0;
         private final int RIGHT_ALIGN = 1;
         private JFrame frame;
         private JTable tableView;
         private String lastPrintDate;
         private Font defaultFont;
         private Font headerFont;
         private Font footerFont;
         private int headerHeight;
         private int footerHeight;
         private int cellBuffer = 5;
         private boolean first_pass;
         private ArrayList pages;
         public Report()
              frame = new JFrame("Sales Report");
              frame.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                        System.exit(0);
              final String[] headers =
                   "ID",
                   "Description",
                   "open price",
                   "latest price",
                   "End Date",
                   "Quantity"
              int count = 0;
              final Object[][] data =
                   {new Integer(count++), "Box of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of Biros ppppppppppppppp", "1.00", "4.99", new Date(), new Integer(200000)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++),  "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++),  "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++),  "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++),  "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)}
              TableModel dataModel = new AbstractTableModel()
                   public int getColumnCount() { return headers.length; }
                   public int getRowCount() { return data.length;}
                   public Object getValueAt(int row, int col)
                        return data[row][col];
                   public String getColumnName(int column)
                        return headers[column];
                   public Class getColumnClass(int col)
                        return getValueAt(0,col).getClass();
                   public boolean isCellEditable(int row, int col)
                        return (col==1);
                   public void setValueAt(Object aValue, int row, int column)
                        data[row][column] = aValue;
              tableView = new JTable(dataModel);
              JScrollPane scrollpane = new JScrollPane(tableView);
              scrollpane.setPreferredSize(new Dimension(500, 80));
              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(BorderLayout.CENTER,scrollpane);
              frame.pack();
              JButton printButton= new JButton();
              printButton.setText("print me!");
              frame.getContentPane().add(BorderLayout.SOUTH,printButton);
              // for faster printing turn double buffering off
              RepaintManager.currentManager(frame).setDoubleBufferingEnabled(false);
              printButton.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent evt)
                        doPrint();
              frame.setVisible(true);
          * Reset variables before printing
         private void prepareForPrint()
              pages = new ArrayList();
              first_pass = true;
          * Display a print dialog with some hardcoded defaults
          * The print fonts are also hardcoded
         public void doPrint()
              try
                   String jobName = "Java Report";
                   defaultFont = new Font("Arial", Font.PLAIN, 8);
                   footerFont = new Font("Arial", Font.PLAIN, 6);
                   headerFont = new Font("Arial", Font.BOLD, 10);
                   PrinterJob prnJob = PrinterJob.getPrinterJob();
                   prnJob.setPrintable(this);
                   PrintRequestAttributeSet prnSet = new HashPrintRequestAttributeSet();
                   prnSet.add(new Copies(1));
                   prnSet.add(new JobName(jobName, null));
                   prnSet.add(MediaSizeName.ISO_A4);
                   PageFormat pf = prnJob.defaultPage();
                   pf.setOrientation(java.awt.print.PageFormat.PORTRAIT);
                   prnJob.setJobName(jobName);
                   PrintService[] services = PrinterJob.lookupPrintServices();
                   if (services.length > 0)
                        if (prnJob.printDialog(prnSet))
                              * Get print date
                             String dateFormat = "dd/MM/yyyy HH:mm:ss";
                             DateFormat m_DateFormat = new SimpleDateFormat(dateFormat);
                             lastPrintDate = m_DateFormat.format(new Date()).toString();
                             prepareForPrint();
                             prnJob.print(prnSet);
                   else
                        JOptionPane.showMessageDialog(frame, "No Printer was found!!", "Printer Error", JOptionPane.ERROR_MESSAGE);
                        return;
              catch (PrinterException e)
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
               * Check if this is the first time the print method is called for this print action.
               * It is not guaranteed that the print will be called with synchronous pageIndex'es,
               * so we need to calculate the number of pages and which rows appear on which pages.
               * Then the correct page will be printed regardless of which pageIndex is sent through.
              if (first_pass)
                   calcPages(g, pageFormat);
              first_pass = false;
              // Stop printing if the pageIndex is out of range
              if (pageIndex >= pages.size())
                   return NO_SUCH_PAGE;
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() + pageFormat.getImageableY();
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = pageWidth / (tableWidth+ (cellBuffer * tableView.getColumnCount()));
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)tableView.getColumnModel().getColumn(i).getWidth() * scale;
              // Reset the view to the start of the page
              g2.translate(0, 0);
              // Draw a rectangle to see the printable area
              g2.draw3DRect((int)pageFormat.getImageableX(),
                        (int)pageFormat.getImageableY(),
                        (int)pageFormat.getImageableWidth(),
                        (int)pageFormat.getImageableHeight(),
                        false);
              // Calculate the header height
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              // Print the headers and retreive the starting position for the data
              int next_row = printLine(g2, pageFormat, fontMetrics, -1, (int)pageFormat.getImageableY() + fontHeight, columnWidths);
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              // Start printing the detail
              ArrayList page = (ArrayList)pages.get(pageIndex);
              int start = ((Integer)page.get(0)).intValue();
              int end = ((Integer)page.get(1)).intValue();
              for (int i = start; i <= end; i++)
                   next_row = printLine(g2, pageFormat, fontMetrics, i, next_row, columnWidths);
              // Print the footer
              g2.setFont(footerFont);
              String pageFooter = "Page " + (pageIndex + 1) + " - " + lastPrintDate;
              g2.drawString(pageFooter,
                             (int)pageFormat.getWidth() / 2 - (fontMetrics.stringWidth(pageFooter) / 2),
                             (int)(pageHeight - fontDescent));
              return PAGE_EXISTS;
          * We can't guarantee that the same amount of rows will be displayed on each page,
          * the row heights are dynamic and may wrap onto 2 or more lines.
          * Thus we need to calculate the height of each row and then test how may rows
          * fit on a specific page. eg. Page 1 contains rows 1 to 10, Page 2 contains rows 11 to 15 etc.
         public void calcPages(Graphics g, PageFormat pageFormat) throws PrinterException
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() - fontHeight;
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = pageWidth / (tableWidth+ (cellBuffer * tableView.getColumnCount()));
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)tableView.getColumnModel().getColumn(i).getWidth() * scale;
              // Calculate the header height
              int maxHeight = 0;
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = tableView.getColumnName(j).toString();
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
              headerHeight = g2.getFontMetrics().getHeight() * maxHeight;
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              int pageNum = 0;
              int bottom_of_page = (int)(pageFormat.getImageableHeight() + pageFormat.getImageableY()) - footerHeight;
              int prev_row = 0;
              int next_row = (int)pageFormat.getImageableY() + fontHeight + headerHeight;
              int i = 0;
              ArrayList page = new ArrayList();
              page.add(new Integer(0));
              for (i = 0; i < tableView.getRowCount(); i++)
                   maxHeight = 0;
                   for (int j = 0; j < tableView.getColumnCount(); j++)
                        String value = tableView.getValueAt(i, j).toString();
                        int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                        if (numLines > maxHeight)
                             maxHeight = numLines;
                   prev_row = next_row;
                   next_row += (fontHeight * maxHeight);
                   // If we've reached the bottom of the page then set the current page's end row
                   if (next_row > bottom_of_page)
                        page.add(new Integer(i - 1));
                        pages.add(page);
                        page = new ArrayList();
                        page.add(new Integer(i));
                        pageNum++;
                        next_row = (int)pageFormat.getImageableY()
                                       + fontHeight
                                       + ((int)pageFormat.getHeight() * pageNum)
                                       + headerHeight;
                        bottom_of_page = (int)(pageFormat.getImageableHeight()
                                            + pageFormat.getImageableY())
                                            + ((int)pageFormat.getHeight() * pageNum)
                                            - footerHeight;
                        //Include the current row on the next page, because there is no space on this page
                        i--;
              page.add(new Integer(i - 1));
              pages.add(page);
          * Print the headers or a row from the table to the graphics context
          * Return the position of the row following this one
         public int printLine(Graphics2D g2,
                                       PageFormat pageFormat,
                                       FontMetrics fontMetrics,
                                       int rowNum,
                                       int next_row,
                                       double[] columnWidths)
                   throws PrinterException
              int lead = 0;
              int maxHeight = 0;
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = null;
                   int align = LEFT_ALIGN;
                   if (rowNum > -1)
                        Object obj = tableView.getValueAt(rowNum, j);
                        if (obj instanceof Number)
                             align = RIGHT_ALIGN;
                        value = obj.toString();
                   else
                        align = CENTER_ALIGN;
                        value = tableView.getColumnName(j);
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
                   if (fontMetrics.stringWidth(value) < columnWidths[j])
                        // Single line
                        int offset = 0;
                        // Work out the offset from the start of the column to display alignment correctly
                        switch (align)
                             case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                             case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                             default: offset = 0; break;
                        g2.drawString(value,
                                       lead + (int)(pageFormat.getImageableX() + offset),
                                       next_row);
                   else
                        for(int a = 0; a < numLines; a++)
                             //Multi-Line
                             int x = 0;
                             int width = 0;
                             for(x = 0; x < value.length(); x++)
                                  width += fontMetrics.charWidth(value.charAt(x));
                                  if (width > columnWidths[j])
                                       break;
                             int offset = 0;
                             // Work out the offset from the start of the column to display alignment correctly
                             switch (align)
                                  case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                                  case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                                  default: offset = 0; break;
                             g2.drawString(value.substring(0, x),
                                            lead + (int)(pageFormat.getImageableX() + offset),
                                            next_row + (fontMetrics.getHeight() * a));                    
                             value = value.substring(x);
                   lead += columnWidths[j] + cellBuffer;
              // Draw a solid line below the row
              g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                             next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent(),
                             pageFormat.getImageableY() + pageFormat.getImageableWidth(),
                             next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent()));
              // Return the position of the row following this one
              return next_row + (fontMetrics.getHeight() * maxHeight);
         public static void main(String[] args)
              new Report();
    }

    Fixed some bugs and added a title. Just pass in a JTable and the class will do the rest.
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import java.text.*;
    import java.math.*;
    public class PrintJTable implements Printable
         private final int LEFT_ALIGN = -1;
         private final int CENTER_ALIGN = 0;
         private final int RIGHT_ALIGN = 1;
         private JFrame m_parent;
         private String m_title;
         private JTable tableView;
         private String lastPrintDate;
         private Font defaultFont;
         private Font headerFont;
         private Font footerFont;
         private int headerHeight;
         private int footerHeight;
         private int cellBuffer = 5;
         private boolean first_pass;
         private ArrayList pages;
         public PrintJTable(JFrame parent, JTable table)
              m_parent = parent;
              tableView = table;
              doPrint();
         public PrintJTable(JFrame parent, String title, JTable table)
              m_parent = parent;
              m_title = title;
              tableView = table;
              doPrint();
          * Reset variables before printing
         private void prepareForPrint()
              pages = new ArrayList();
              first_pass = true;
          * Display a print dialog with some hardcoded defaults
          * The print fonts are also hardcoded
         public void doPrint()
              try
                   String jobName = "Java Report";
                   defaultFont = new Font("Arial", Font.PLAIN, 8);
                   footerFont = new Font("Arial", Font.PLAIN, 6);
                   headerFont = new Font("Arial", Font.BOLD, 8);
                   PrinterJob prnJob = PrinterJob.getPrinterJob();
                   prnJob.setPrintable(this);
                   PrintRequestAttributeSet prnSet = new HashPrintRequestAttributeSet();
                   prnSet.add(new Copies(1));
                   prnSet.add(new JobName(jobName, null));
                   prnSet.add(MediaSizeName.ISO_A4);
                   PageFormat pf = prnJob.defaultPage();
                   pf.setOrientation(java.awt.print.PageFormat.PORTRAIT);
                   prnJob.setJobName(jobName);
                   PrintService[] services = PrinterJob.lookupPrintServices();
                   if (services.length > 0)
                        if (prnJob.printDialog(prnSet))
                              * Get print date
                             String dateFormat = "dd/MM/yyyy HH:mm:ss";
                             DateFormat m_DateFormat = new SimpleDateFormat(dateFormat);
                             lastPrintDate = m_DateFormat.format(new Date()).toString();
                             prepareForPrint();
                             prnJob.print(prnSet);
                   else
                        JOptionPane.showMessageDialog(m_parent, "No Printer was found!!", "Printer Error", JOptionPane.ERROR_MESSAGE);
                        return;
              catch (PrinterException e)
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
               * Check if this is the first time the print method is called for this print action.
               * It is not guaranteed that the print will be called with synchronous pageIndex'es,
               * so we need to calculate the number of pages and which rows appear on which pages.
               * Then the correct page will be printed regardless of which pageIndex is sent through.
              if (first_pass)
                   calcPages(g, pageFormat);
              first_pass = false;
              // Stop printing if the pageIndex is out of range
              if (pageIndex >= pages.size())
                   return NO_SUCH_PAGE;
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() + pageFormat.getImageableY();
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = (pageWidth - (cellBuffer * tableView.getColumnCount())) / tableWidth;
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              double test = 0;
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)Math.floor(tableView.getColumnModel().getColumn(i).getWidth() * scale);
                   test += columnWidths;
              // Reset the view to the start of the page
              g2.translate(0, 0);
              // Draw a rectangle to see the printable area
              g2.draw3DRect((int)pageFormat.getImageableX(),
                        (int)pageFormat.getImageableY(),
                        (int)pageFormat.getImageableWidth(),
                        (int)pageFormat.getImageableHeight(),
                        false);
              // Calculate the header height
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              // Print the headers and retreive the starting position for the data
              int next_row = (int)pageFormat.getImageableY() + fontMetrics.getHeight();
              if ((m_title != null) && (!m_title.equalsIgnoreCase("")))
                   g2.drawString(m_title,
                                       (int)(pageFormat.getImageableX()),
                                       next_row);
                   Color current_color = g2.getColor();
                   g2.setColor(Color.lightGray);
                   int y = next_row + fontMetrics.getDescent();
                   g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                                  y,
                                  (pageFormat.getImageableY() + pageFormat.getImageableWidth()),
                                  y));
                   g2.setColor(current_color);
                   next_row += fontMetrics.getHeight();
              next_row = printLine(g2, pageFormat, fontMetrics, -1, next_row, columnWidths);
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              // Start printing the detail
              ArrayList page = (ArrayList)pages.get(pageIndex);
              int start = ((Integer)page.get(0)).intValue();
              int end = ((Integer)page.get(1)).intValue();
              for (int i = start; i <= end; i++)
                   next_row = printLine(g2, pageFormat, fontMetrics, i, next_row, columnWidths);
              // Print the footer
              g2.setFont(footerFont);
              String pageFooter = "Page " + (pageIndex + 1) + " - " + lastPrintDate;
              g2.drawString(pageFooter,
                             (int)pageFormat.getWidth() / 2 - (fontMetrics.stringWidth(pageFooter) / 2),
                             (int)(pageHeight - fontDescent));
              return PAGE_EXISTS;
         * We can't guarantee that the same amount of rows will be displayed on each page,
         * the row heights are dynamic and may wrap onto 2 or more lines.
         * Thus we need to calculate the height of each row and then test how may rows
         * fit on a specific page. eg. Page 1 contains rows 1 to 10, Page 2 contains rows 11 to 15 etc.
         public void calcPages(Graphics g, PageFormat pageFormat) throws PrinterException
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() - fontHeight;
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = (pageWidth - (cellBuffer * tableView.getColumnCount())) / tableWidth;
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)Math.floor(tableView.getColumnModel().getColumn(i).getWidth() * scale);
              // Calculate the header height
              int maxHeight = 0;
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              headerHeight = 0;
              if ((m_title != null) && (!m_title.equalsIgnoreCase("")))
                   headerHeight = fontMetrics.getHeight();
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = tableView.getColumnName(j).toString();
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
              headerHeight += g2.getFontMetrics().getHeight() * maxHeight;
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              int pageNum = 0;
              int bottom_of_page = (int)(pageFormat.getImageableHeight() + pageFormat.getImageableY()) - footerHeight;
              int prev_row = 0;
              int next_row = (int)pageFormat.getImageableY() + fontHeight + headerHeight;
              int i = 0;
              ArrayList page = new ArrayList();
              page.add(new Integer(0));
              for (i = 0; i < tableView.getRowCount(); i++)
                   maxHeight = 0;
                   for (int j = 0; j < tableView.getColumnCount(); j++)
                        String value = formatObject(tableView.getValueAt(i, j));
                        int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                        if (numLines > maxHeight)
                             maxHeight = numLines;
                   prev_row = next_row;
                   next_row += (fontHeight * maxHeight);
                   // If we've reached the bottom of the page then set the current page's end row
                   if (next_row > bottom_of_page)
                        page.add(new Integer(i - 1));
                        pages.add(page);
                        page = new ArrayList();
                        page.add(new Integer(i));
                        pageNum++;
                        next_row = (int)pageFormat.getImageableY()
                                       + fontHeight
                                       + ((int)pageFormat.getHeight() * pageNum)
                                       + headerHeight;
                        bottom_of_page = (int)(pageFormat.getImageableHeight()
                                            + pageFormat.getImageableY())
                                            + ((int)pageFormat.getHeight() * pageNum)
                                            - footerHeight;
                        //Include the current row on the next page, because there is no space on this page
                        i--;
              page.add(new Integer(i - 1));
              pages.add(page);
         * Print the headers or a row from the table to the graphics context
         * Return the position of the row following this one
         public int printLine(Graphics2D g2,
                                       PageFormat pageFormat,
                                       FontMetrics fontMetrics,
                                       int rowNum,
                                       int next_row,
                                       double[] columnWidths)
                   throws PrinterException
              int lead = 0;
              int maxHeight = 0;
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = null;
                   int align = LEFT_ALIGN;
                   if (rowNum > -1)
                        Object obj = tableView.getValueAt(rowNum, j);
                        if (obj instanceof Number)
                             align = RIGHT_ALIGN;
                        value = formatObject(obj);
                   else
                        //align = CENTER_ALIGN;
                        value = tableView.getColumnName(j);
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
                   if (fontMetrics.stringWidth(value) < columnWidths[j])
                        // Single line
                        int offset = 0;
                        // Work out the offset from the start of the column to display alignment correctly
                        switch (align)
                             case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                             case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                             default: offset = 0; break;
                        g2.drawString(value,
                                       lead + (int)(pageFormat.getImageableX() + offset),
                                       next_row);
                   else
                        for(int a = 0; a < numLines; a++)
                             //Multi-Line
                             int x = 0;
                             int width = 0;
                             for(x = 0; x < value.length(); x++)
                                  width += fontMetrics.charWidth(value.charAt(x));
                                  if (width > columnWidths[j])
                                       break;
                             int offset = 0;
                             // Work out the offset from the start of the column to display alignment correctly
                             switch (align)
                                  case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value.substring(0, x))); break;
                                  case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value.substring(0, x))) / 2; break;
                                  default: offset = 0; break;
                             g2.drawString(value.substring(0, x),
                                            lead + (int)(pageFormat.getImageableX() + offset),
                                            next_row + (fontMetrics.getHeight() * a));                    
                             value = value.substring(x);
                   lead += columnWidths[j] + cellBuffer;
              // Draw a solid line below the row
              Color current_color = g2.getColor();
              g2.setColor(Color.lightGray);
              int y = next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent();
              g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                             y,
                             (pageFormat.getImageableY() + pageFormat.getImageableWidth()),
                             y));
              g2.setColor(current_color);
              // Return the position of the row following this one
              return next_row + (fontMetrics.getHeight() * maxHeight);
         public String formatObject(Object obj)
              String value = (obj == null) ? "" : obj.toString();
              return value;

  • HP L7780 Printing - Two-sided and Multiple pages

    The HP L7780 printer is capable of printing two-sided pages and multiple pages per page (e.g. two-up on a single sheet). This works just fine with my WIndows XP systems, but not with my BRAND NEW Pro! I've installed the latest drivers from HP ... any help here?

    Is any of this helpful?
    http://tinyurl.com/b2kjco
    The URL above goes to ...
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c00874428&jumpid=otrecdoc/c01463616/en_us/c00874428/loc:2&custom_solutionid=rdc01463616&lc=en&dlc=en&cc=us

  • Printing large Panel across multiple pages!

    We are trying to print a receipt which has master panel consisting of more than 10 components(transaction panels) which are going to spread multiple pages. Is there a way to print this multiple page spanning receipt. I appreciate your response.

    I don’t think you want to set the image’s width/height to the page dimensions.  I think that will shrink the image to fit the page.  If you leave the image as a larger size, FlexPrintJob should chop into enough pages.

  • PRINT ENLAGED IMAGE ACROSS MULTIPLE PAGES

    I have a scanned image that I want to print at 4 times its original size across multiple pages. Is there any known way to do this?  

    Thanks for the info, guys.
    I don't have InDesign installed. I'll consider installing it, but it's sad that we have to install an entire app to get functionality for Adobe graphics programs that even browsers offer routinely. Jeez, Firefox spans pages automatically.
    If you have a graphic larger than the page and you don't opt to resize it, Photoshop should offer to clip the overflow or print multiple pages. And ideally, to print multiple pages with an optional overlap.
    I would have thought this was in version 1. But then again, Photoshop didn't have a thumbnail browser until what, version 7?

  • Issues when printing a website of multiple pages, only prints every other page

    I have recently started using Firefox as since using windows 8 have found a few problems with explorer.
    I sell a great deal on ebay and in order to print my invoices, ebay create a webpage with all of them on.
    I have attempted to print this through firfox and it only seemed to print every other page fully(1,3,5,7 etc.)
    Pages 2,4,6 etc. would have just the first couple of text lines on but nothing else, it even shows it like this on the print preview. can you help?

    Try the '''''reset''''' described here: <br />
    http://kb.mozillazine.org/Problems_printing_web_pages#Reset_printer

  • Reverse printing order when copying multiple pages?

    My boss often wants to copy multi-page documents using the ADF and copy mode. Since the feeder takes the pages from the top, the copies end up in reverse order. Is there any setting that would make the copies come out in the same order as the original?  ( I know you could scan them all and then print, but he doesn't want to do that.) 

    Hi, HPGLinda!
    So that the Community can help you better, we will need to know exactly which model of printer you're using, which operating system is on the computer that's talking to it, and which applications you're trying to print from. That, and any other details you'd like to give will help the Community better understand your issue!
    If this is a time-sensitive matter, our US-based technical support team is standing by, ready to help 24/7 via Email at http://bit.ly/EmailCanon or by phone at 1-800-OK-CANON (1-800-652-2666) weekdays between 10 AM and 10 PM ET (7 AM to 7 PM PT).
    Thanks and have a great day!

  • How do I print a spread with multiple page sizes?

    Hello fellow designers!!!!
    I'm trying to make a production dummy by printing double sided. My document has an extra fold on the outer edge (see attached image).
    I want to print 'D11-D12' as one spread with the reverse side as 'D13-12', so that I can simply fold in the outer edge and spiral bind the spine.
    When I input the range 'D11-D12, D13-12' the printer prints 'D11' on one side and 'D12' on the reverse same with 'D13' and '12'.
    How do I get this spread happening the way I want? I'd appreciate any help I can get as time is mot my friend on this one!
    Thanks,
    Gordon

    Sandee, I think you're onto something here. I've managed to separate the spreads from the spine as you suggested, however, I'm still getting the same result. The preview in the print dialogue is exactly what I want, yet the printout itself still print 'D11' on the back of 'D12'. I'm under a mountain of failed printouts! In the end I gave up and just taped the extra fold to the dummy manually.
    I'd love to figure this out though for future use, so any more input would be divine!
    Thank you so much for helping out!

  • Footer should be print on last page in multiple page format

    Hi expert,
    I designed form for invoice print ,in that for multiple pages footer should be print on last page only and hight of the main window should be increase (means if footer will display on last page then space of footer should be used for main window in multiple
    page format) 
    for eg .if i have 12 item so 5 items displyed on each page but i want to print 10 item on first page and remaing on second and after that i want to print footer.
    Regards,
    Jyotsna

    Hi,
    Has you tried to create a "new page" copy of FIRST, and make it the LAST_PAGE... On it you are going to create the desired footer.
    The Page Secuence will be something like this:
    If you are trying to print 12 items, then PAGE 1 (10 items) -> LAST_PAGE (2 remaining items).
    Hope it helps you...
    Alexis Sanchez N.
    SAP ABAP Development Consultant
    Molen Services and Consulting, C.A.

  • Print multiple pages with dynamic data from same movieclip

    Hi @ all,
    like much of us i have a problem with printjob.
    I have a printjob routine, that starts a new job, then
    handles the following in a loop for printing multiple pages:
    1. update content for every page in a sprite. every loop it's
    the same sprite. the sprite is visible on stage
    2. addPage to Printjob
    after that sends the printjob to the printer
    Now the Problem:
    On Windows it runs perfectly. On Mac only the last page was
    printed. the other pages before are empty (white).
    Has anyone a idea?
    Thanks for answeres.
    Her's my code. As you can see i try to print a table on
    multiple pages. In every loop i only show the rows for the actually
    printing page:

    the printview function only updates the content in the sprite
    that will be printet on every page.
    it generates the rows of a table that will be printed on the
    actual page and return if all rows are printed (true or false)
    this is a very slim function. there is no time overflow or
    sth. like this.

  • NEED HELP PUTTING MULTIPLE PAGES TOGETHER IN 1 PDF

    HOW DO I PUT 10 PAGES TOGETHER TO OPEN IN 1 PDF?

    Thanks Janelle - I do not have that ability with the Epson RX580. Epson just answered my tech support question with this answer:
    I am sorry you are experiencing difficulties with your EPSON Stylus Photo RX580. Unfortunately this feature is not available with Mac OS X. You will need a third-party software that will help you with this, such as Poster Print for Mac or Tiler. Please note though that Epson does not support these applications.
    So I guess my question becomes what software can I use to print my images on multiple pages. As I do large photo transfers I need to be able to do this with my mac in an efficient way and not try to cut portions of image into seperate print jobs that would be too time consuming. HAve you had any experience with other software. If not I guess the next question  what printer would you recommend that would do this with my MAC. I have included a pic of one of my larger transfers on a cupboard. To do this I needed the image to be tiled on 8 different sheet of 8.5x11 so this is a feature I need through either software or a printer that is easy to use and easily accessible. Thanks Krista
    I am inl

  • Multiple page Report

    Hi,
    How to Print the Report in Multiple Pages? i.e. Once the first page Report is finished , the next one has to start printing, and so on.Each Page can contain more than one pages.
    TIA,
    Vikki
    null

    You aren't really linking the frames to the pages. Simply set the "page break before" on the second frame. When the first frame finishes printing (regardless of how many pages that is) it will skip to the next page before the second frame starts printing. If required, you can make the page numbering re-set if you want to based on repeating frame values.
    If you really want to distinguish between the layouts, you can create up to 3 layouts by using each of the three sections (header, main, trailer). As each section finishes, there is also a page break before the next section starts.
    You can get at the page number using srw.get_page_num() but I don't think this will help you.

  • Combining multiple pages to a single page

    I have a pdf file of 12 pages, each page a single photo. I would like to place 4 photos on a single page so that I end up with 3 pages with a photo on each quarter page. I tried doing it by printing to Adobe PDF multiple pages per sheet. I tried this in windows photo viewer and in Acrobat. Both times the 'printing' got stuck about 3/4 into page 1.
    Is there a more straightforward way to do what I'm trying to achieve?
    Many thanks

    Sounds like you are looking for information on how to scan with the HP software. Here is a link on how to do that, if you check under "How to Scan ..." it should contain information on what you are looking to do. 
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&​lc=en&docname=c03476857#N3157
    Let me know if that helps you! 
    -Spencer 
    PS Hope you are having a wonderful day and that your weather is as beautiful there as it is here!  

  • Report on Multiple pages.

    Hi to All,
    I want to print a report on Multiple pages.
    I want to print only one report but on different pages divided by CASE, LCO and AA.
    Example: for
    LCO: 2129 AA: 000759 only one record on page 1
    LCO: 2129 AA: 000729 only one record on page 2
    LCO: 3041 AA: 005163 page should have all 4 records displayed on one page 3
    and so on...
    currently I am doing this in a loop.
    The report is called from a form, in the form I have created a loop and for every record it calls the report by LCO and AA. But if the CASE has 50 different LCO and AA the user cannot exit until all 50 reports are displayed.
    all I want to pass is the CASE and request_type and the report then generates the details on multiple pages grouped by LCO and AA.
    Thanks to all.
    Habeeb
    Below is the query.
    Cenqr@PRD> SELECT opcode
      2              , case
      3              , docid
      4              , lco
      5              , aa
      6              , book_num
      7              , num_of_book
      8              , census_batchid  batchid
      9              , SUBSTR(boxid,1,8) || ' ' || SUBSTR(boxid,9,5) BOXID
    10              , request_date
    11     FROM cenqr.tbl_uni_cenqr
    12  WHERE case = 90002
    13        AND request_type = 'AR'
    14  ORDER BY boxid;
    OP CASE       DOCID                                LCO  AA     BOOK NUM_ BATCHID                              BOXID         
    31 90002      2129310007591301                     2129 000759 01   01   321290007590101                      ARMP0137 00038
    31 90002      2129310007292001                     2129 000729 01   01   321290007290101                      ARMP0356 00011
    60 90002      3041600051637201                     3041 005163 01   01   630410051630101                      ARMP0600 00006
    60 90002      3041600051637201                     3041 005163 98   98   630410051639898                      ARMP0638 00020
    60 90002      3041600051637201                     3041 005163 97   97   630410051639797                      ARMP0639 00002
    60 90002      3041600051637201                     3041 005163 99   99   630410051639999                      ARMP0640 00029
    74 90002      2718740021944801                     2718 002194 01   01   427180021940101                      FVAR0312 00032
    57 90002      20154949186118                       2441 000011           5701000020                           GQER0002 00013
    57 90002      20154944875146                       2441 000011           5701000007                           GQER0002 00013
    57 90002      20154944874116                       2441 000011           5701000007                           GQER0002 00013
    57 90002      20154944833172                       2441 000011           5701000020                           GQER0002 00013
    35 90002      2331350027180201                     2331 002718 01   01   3523310027180101                     GQVA0010 00001
    35 90002      2424350036429301                     2424 003642 01   01   3524240036420101                     GQVA0012 00005
    32 90002      30163213478401                       3016 001347      0001 30160013470001                       NRFU0304 00024
    32 90002      30163213478401                       3016 001347      0002 30160013470002                       NRFU0666 00015
    32 90002      30163213478401                       3016 001347      0003 30160013470003                       NRFU0666 00025
    32 90002      30163213478401                       3016 001347      0004 30160013470004                       NRFU0910 00008
    32 90002      32273216280801                       3227 001628      0004 32270016280004                       NRFU1208 00019
    32 90002      32273216280801                       3227 001628      0002 32270016280002                       NRFU1208 00019
    32 90002      32273216280801                       3227 001628      0003 32270016280003                       NRFU1208 00019
    32 90002      32273216280801                       3227 001628      0001 32270016280001                       NRFU1208 00019
    32 90002      27123212883701                       2712 001288      0001 27120012880001                       NRFU2690 00012
    32 90002      27123212893801                       2712 001289      0001 27120012890001                       NRFU2734 00004

    Thanks a lot,
    that really helped what I wanted, the users have requested one further change (display only) if not they are happy with what they have.
    example
    My report displays
                                 CASE: 00010
    LCO  AA        CODE    DOCID                       ETC ... ETC ....
    125  001225      32    123456789                   01
                     32    123456788                   01
                     32    123456777                   02
    They want
                                 CASE: 00010  LCO 125   AA 001225
    CODE    DOCID                       ETC ... ETC ....
      32    123456789                   01
      32    123456788                   01
      32    123456777                   02
    OR something like this
                                              CASE: 00010 
                                         LCO 125   AA 001225
    CODE    DOCID                       ETC ... ETC ....
      32    123456789                   01
      32    123456788                   01
      32    123456777                   02But case is not part of the repeating frame where as LCO and AA are, can I do this, I don't have to move LCO and AA out of the repeating frame can I do this inside the frame itself I mean arrange the LCO and AA on top and then the rest of the information.
    Thanks again
    Habeeb

Maybe you are looking for