com.cete.dynamicpdf.pageelements
Class Table2




Examples Description
Example 1 The following example will display a simple table on the page.
Example 2 The following example shows you how to use the getOverflowRows method to allow table of variable length to flow onto new pages as needed.
Example 3 The following example shows you how to use the getOverflowRows method with x,y coordinates to allow table of variable length to flow onto new pages as needed.
Example 4 The following example shows you how to use the getOverflowRows method with x,y coordinates, width & height to allow table of variable length to flow onto new pages as needed.
Example 5 The following example shows you how to use the getOverflowColumns method to allow table of variable length to flow onto new pages as needed.
Example 6 The following example shows you how to use the getOverflowColumns method with x,y coordinates to allow table of variable length to flow onto new pages as needed.
Example 7 The following example shows you how to use the getOverflowColumns method with x,y coordinates, width & height to allow table of variable length to flow onto new pages as needed.



Example 1: The following example will display a simple table on the page.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.Cell2;
import com.cete.dynamicpdf.pageelements.Column2;
import com.cete.dynamicpdf.pageelements.Row2;
import com.cete.dynamicpdf.pageelements.Table2;
  
 public class MyClass{
       public static void main(String args[]){
       
          // Create a PDF Document
          Document document = new Document();
        
          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add( page );
        
          // Create a table
          Table2 table = new Table2(0, 0, 600, 600);
        
          //Add columns to the table
          Column2 column1 =  table.getColumns().add( 150 );
          column1.getCellDefault().setAlign(TextAlign.CENTER);
          table.getColumns().add( 90 );
          table.getColumns().add( 90 );
          table.getColumns().add( 90 );
        
          // Add rows to the table and add cells to the rows
          Row2 row1 = table.getRows().add( 40, Font.getHelveticaBold(), 16, Grayscale.getBlack(),
                   Grayscale.getGray() );
          row1.getCellDefault().setAlign(TextAlign.CENTER);
          row1.getCellDefault().setVAlign(VAlign.CENTER);
          row1.getCells().add( "Header 1" );
          row1.getCells().add( "Header 2" );
          row1.getCells().add( "Header 3" );
          row1.getCells().add( "Header 4" );
           
          Row2 row2 = table.getRows().add( 30 );
          Cell2 cell1 = row2.getCells().add( "Rowheader 1", Font.getHelveticaBold(), 16,
                   Grayscale.getBlack(), Grayscale.getGray(), 1 );
          cell1.setAlign(TextAlign.CENTER);
          cell1.setVAlign(VAlign.CENTER);
          row2.getCells().add( "Item 1" );
          row2.getCells().add( "Item 2" );
          row2.getCells().add( "Item 3" );
        
          Row2 row3 = table.getRows().add( 30 );
          Cell2 cell2 = row3.getCells().add( "Rowheader 2", Font.getHelveticaBold(), 16,
                   Grayscale.getBlack(), Grayscale.getGray(), 1 );
          cell2.setAlign(TextAlign.CENTER);
          cell2.setVAlign(VAlign.CENTER);
          row3.getCells().add( "Item 4" );
          row3.getCells().add( "Item 5" );
          row3.getCells().add( "Item 6" );
        
          table.getCellDefault().getPadding().setValue(5.0f);
          table.setCellSpacing(5.0f);
          table.getBorder().getTop().setColor(RgbColor.getBlue());
          table.getBorder().getBottom().setColor(RgbColor.getBlue());
          table.getBorder().getTop().setWidth( 2);
          table.getBorder().getBottom().setWidth(2);
          table.getBorder().getLeft().setLineStyle(LineStyle.getNone());
          table.getBorder().getRight().setLineStyle(LineStyle.getNone());
        
          // Add the table to the page
          page.getElements().add( table );
 
          // Save the PDF
          document.draw("[PhysicalPath]/MyDocument.pdf");
       }
 }

Top

Example 2: The following example shows you how to use the getOverflowRows method to allow table of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 200, 700);
        
        //Add columns to the table
        table.getColumns().add(100);
        table.getColumns().add(100);
        
        // This loop populates the table
        for ( int i = 1; i <= 400; i++ )  {
            Row2 row = table.getRows().add( 20 );
            row.getCells().add( "Row #" + i );
            row.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowRows();
        } while ( table != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 3: The following example shows you how to use the getOverflowRows method with x,y coordinates to allow table of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 200, 650);
        
        //Add columns to the table
        table.getColumns().add(100);
        table.getColumns().add(100);
        
        // This loop populates the table
        for ( int i = 1; i <= 400; i++ )  {
            Row2 row = table.getRows().add( 20 );
            row.getCells().add( "Row #" + i );
            row.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowRows(50,50);
        } while ( table != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 4: The following example shows you how to use the getOverflowRows method with x,y coordinates, width & height to allow text of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 200, 700);
        
        //Add columns to the table
        table.getColumns().add(100);
        table.getColumns().add(100);
        
        // This loop populates the table
        for ( int i = 1; i <= 400; i++ )  {
            Row2 row = table.getRows().add( 20 );
            row.getCells().add( "Row #" + i );
            row.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowRows(50, 50, 200, 350);
        } while ( table != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 5: The following example shows you how to use the getOverflowColumns method to allow table of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 500, 50);
        
        // Create some number of columns
        int cols = 50;
        for( int i = 0; i <= cols; i++ )
            table.getColumns().add( 100 );
        
        // Create your rows to fill in
        Row2 row1 = table.getRows().add( 20 );
        Row2 row2 = table.getRows().add( 20 );
        
        for ( int j = 0; j <= cols; j++ )  {
            row1.getCells().add( "Column #" + j );
            row2.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowColumns();
        } while ( table != null );
    
      // Save the PDF
      document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 6: The following example shows you how to use the getOverflowColumns method with x,y coordinates to allow table of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 500, 50);
        
        // Create some number of columns
        int cols = 50;
        for ( int i = 0; i <= cols; i++ )
            table.getColumns().add( 100 );
        
        // Create your rows to fill in
        Row2 row1 = table.getRows().add( 20 );
        Row2 row2 = table.getRows().add( 20 );
        
        for ( int j = 0; j <= cols; j++ )  {
            row1.getCells().add( "Column #" + j );
            row2.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowColumns(50,50);
        } while ( table != null );
    
        // Save the PDF
        document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top

Example 7: The following example shows you how to use the getOverflowColumns methods with x,y coordinates, width & height to allow text of variable length to flow onto new pages as needed.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;

public class MyClass
{
    public static void Main(String args[])
    {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a table
        Table2 table = new Table2(0, 0, 500, 50);
        
        // Create some number of columns
        int cols = 50;
        for( int i = 0; i <= cols; i++ )
            table.getColumns().add( 100 );
        
        // Create your rows to fill in
        Row2 row1 = table.getRows().add( 20 );
        Row2 row2 = table.getRows().add( 20 );
        
        for ( int j = 0; j <= cols; j++ )  {
            row1.getCells().add( "Column #" + j );
            row2.getCells().add( "Item" );
        }
        
        do {
            Page page = new Page();
            document.getPages().add( page );
            page.getElements().add( table );
            table = table.getOverflowColumns(50, 50, 250, 50);
        } while ( table != null );
    
       // Save the PDF
       document.draw("[Physicalpath/MyDocument.pdf");
    }
}

Top