When I add something like following, it gets clipped off from the side margins.

            int colStart = 0, rowStart = 0;
            for( int i = 10; i < datatable.getRows().size(); i+=10 )
            {
                colStart = 0;
                for( int j = 5; j < table.getColumnCount(); j+=5 )
                {
                    datatable.writeSelectedRows( colStart, j, rowStart, i, 50, 
575, cb );
                    colStart += 5;
                    document.newPage();
                }
                if(colStart <  table.getColumnCount())
                {
                    document.newPage();
                    datatable.writeSelectedRows( colStart, -1, rowStart, i, 50, 
575, cb );
                }
                rowStart += 10;
            }
            if(rowStart <  datatable.getRows().size())
            {
                document.newPage();
                colStart = 0;
                for( int j = 5; j < table.getColumnCount(); j+=5 )
                {
                    datatable.writeSelectedRows( colStart, j, rowStart, -1, 50, 
575, cb );
                    colStart += 5;
                    document.newPage();
                }
                if(colStart <  table.getColumnCount())
                {
                    document.newPage();
                    datatable.writeSelectedRows( colStart, -1, rowStart, -1, 
50, 575, cb );
                }
            }
 
Chandrajeet Padhy.




----- Original Message ----
From: chandrajeet padhy <[EMAIL PROTECTED]>
To: itext-questions@lists.sourceforge.net
Sent: Monday, February 4, 2008 4:58:13 PM
Subject: 


Hi,

I try to export a large JTable into a PDF with Cell Colors, CheckBox 
compoenents in Cells as below:
1) I don't get the proper pagination
2) I don;t get the Cell Colors

public static void export( JTable table )
    {
        Document document = new Document( PageSize.A4.rotate() );
        try
        {
            PdfWriter writer = PdfWriter.getInstance( document, new 
FileOutputStream( FILE_NAME ) );
            document.open();
            //document.addTitle("TIA
 Strategy Grid");
            PdfContentByte cb = writer.getDirectContent();
            
            PdfPTable datatable = getPdfPTable( table );
            datatable.setTotalWidth(1200 );
            datatable.writeSelectedRows(0,datatable.getRows().size(), 0, 500, 
cb );
        }
        catch( DocumentException de )
        {
            m_logger.error( de.getMessage(), de );
        }
        catch( IOException ioe
 )
        {
            m_logger.error( ioe.getMessage(), ioe );
        }
        document.close();
        try{
            Runtime rt=Runtime.getRuntime();
            rt.exec("cmd.exe /c " + FILE_NAME);
        }catch (Exception ex) {
            JOptionPane.showMessageDialog( null, "Error " + ex );
        }
        
    }

    private static PdfPTable getPdfPTable(JTable table ) throws 
DocumentException
   
 {
        PdfPTable datatable = new PdfPTable( table.getColumnCount() - 1 );
        int headerwidths[] = new int[table.getColumnCount() - 1];
        for( int i = 1; i < table.getColumnCount(); i++ )
        {
            TableColumn col = table.getColumnModel().getColumn( i );
            headerwidths[i - 1] = col.getPreferredWidth();
        }
        datatable.setWidths( headerwidths );
        datatable.setWidthPercentage( 80 );
        datatable.getDefaultCell().setBorderWidth( 2 );
       
 datatable.getDefaultCell().setPadding(5);
        datatable.getDefaultCell().setHorizontalAlignment( Element.ALIGN_CENTER 
);
        PdfPCell cell;
        for( int i = 1; i < table.getColumnCount(); i++ )
        {
            cell = new PdfPCell(new Phrase(table.getColumnName( i )));
            cell.setGrayFill(0.5f);
            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
            datatable.addCell( cell );
        }
       
 datatable.setHeaderRows(1);
        datatable.getDefaultCell().setBorderWidth(1);
        for( int i = 0; i < table.getRowCount(); i++ )
        {
            for( int j = 1; j < table.getColumnCount(); j++ )
            {
                datatable.addCell( table.getValueAt( i, j ) != null ? 
table.getValueAt( i, j ).toString() : "null" );
            }
        }
        datatable.setSplitLate( false );
        
        return
 datatable;
    }
 
Chandrajeet Padhy.







      Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.





      
____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to