com.cete.dynamicpdf.pageelements
Class Table




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.*;
  
 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 
          Table table = new Table(0, 0, 600, 600);
 
          //Add columns to the table
          table.getColumns().add(150);
          table.getColumns().add(90);
          table.getColumns().add(90);
          table.getColumns().add(90);
       
          // Add rows to the table and add cells to the rows
          Row row1 = table.getRows().add(40, Font.getHelveticaBold(), 16, Grayscale.getBlack(), 
          Grayscale.getGray());
          row1.setAlign(CellAlign.CENTER);
          row1.setVAlign(CellVAlign.CENTER);
          row1.getCellList().add("Header 1");
          row1.getCellList().add("Header 2");
          row1.getCellList().add("Header 3");
          row1.getCellList().add("Header 4");
 
          Row row2 = table.getRows().add(30);
          Cell cell1 = row2.getCellList().add("Rowheader 1", Font.getHelveticaBold(), 16, 
          Grayscale.getBlack(), Grayscale.getGray(), 1);
          cell1.setAlign(CellAlign.CENTER);
          cell1.setVAlign(CellVAlign.CENTER);
          row2.getCellList().add("Item 1");
          row2.getCellList().add("Item 2");
          row2.getCellList().add("Item 3");
       
          Row row3 = table.getRows().add(30);
          Cell cell2 = row3.getCellList().add("Rowheader 2", Font.getHelveticaBold(), 16, 
          Grayscale.getBlack(), Grayscale.getGray(), 1);
          cell2.setAlign(CellAlign.CENTER);
          cell2.setVAlign(CellVAlign.CENTER);
          row3.getCellList().add("Item 4");
          row3.getCellList().add("Item 5");
          row3.getCellList().add("Item 6");
            
          // 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 
        Table table = new Table(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++ )  {
	    Row row = table.getRows().add( 20 );
	    row.getCellList().add( "Row #" + i );
	    row1.getCellList().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 
        Table table = new Table(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++ )  {
	   Row row = table.getRows().add( 20 );
	   row.getCellList().add( "Row #" + i );
	   row1.getCellList().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 
        Table table = new Table(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++ )  {
	    Row row = table.getRows().add( 20 );
	    row.getCellList().add( "Row #" + i );
	    row1.getCellList().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 
       Table table = new Table(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
       Row row1 = table.getRows().add( 20 );
       Row row2 = table.getRows().add( 20 );
      
       for ( int j = 0; j <= cols; j++ )  {
           row1.getCellList().add( "Column #" + j );
           row2.getCellsList().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 
        Table table = new Table(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
        Row row1 = table.getRows().add( 20 );
        Row row2 = table.getRows().add( 20 );
      
        for ( int j = 0; j <= cols; j++ )  {
            row1.getCellList().add( "Column #" + j );
            row2.getCellsList().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 
       Table table = new Table(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
       Row row1 = table.getRows().add( 20 );
       Row row2 = table.getRows().add( 20 );
      
       for ( int j = 0; j <= cols; j++ )  {
           row1.getCellList().add( "Column #" + j );
           row2.getCellsList().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