Settting Table Dimensions TallPDF3.0 in .Net

Code Demonstrates Settting Table Dimensions TallPDF3.0 in .Net


Settting Table Dimensions TallPDF3.0 in .Net

 
using
System;

using

System.IO;

using

TallComponents.PDF.Layout;

using

TallComponents.PDF.Layout.Paragraphs;

namespace

TallComponents.Samples.TallPDF

{

public class TableDimensions

{

static void Main()

{

using( FileStream file = new FileStream( @"..\..\TableDimensions.pdf", FileMode.Create ) )

{

Document document =

new Document();

Section section = document.Sections.Add();

// automatically layout cell dimensions

section.Paragraphs.Add( CreateTableWith2Rows() );

section.Paragraphs.Add( CreateTableWith1RowAnd2Cells() );

Table table;

// use a fixed table witdh

table = CreateTableWith2Rows();

table.PreferredWidth = 300;

table.ForceWidth =

true;

section.Paragraphs.Add( table );

table = CreateTableWith1RowAnd2Cells();

table.PreferredWidth = 300;

table.ForceWidth =

true;

section.Paragraphs.Add( table );

// use fit to content

table = CreateTableWith2Rows();

table.Rows[0].Cells[0].FitToContent =

true;

table.Rows[1].Cells[0].FitToContent =

true;

section.Paragraphs.Add( table );

table = CreateTableWith1RowAnd2Cells();

table.Rows[0].Cells[0].FitToContent =

true;

table.Rows[0].Cells[1].FitToContent =

true;

section.Paragraphs.Add( table );

// use preffered width for a cell

table = CreateTableWith2Rows();

table.Rows[0].Cells[0].PreferredWidth = 100;

table.Rows[1].Cells[0].PreferredWidth = 200;

section.Paragraphs.Add( table );

table = CreateTableWith1RowAnd2Cells();

table.Rows[0].Cells[0].PreferredWidth = 100;

table.Rows[0].Cells[1].PreferredWidth = 200;

section.Paragraphs.Add( table );

// use preffered width for a cell in combination with a fixed table width

table = CreateTableWith2Rows();

table.PreferredWidth = 200;

table.ForceWidth =

true;

table.Rows[0].Cells[0].PreferredWidth = 100;

table.Rows[1].Cells[0].PreferredWidth = 200;

section.Paragraphs.Add( table );

table = CreateTableWith1RowAnd2Cells();

table.PreferredWidth = 200;

table.ForceWidth =

true;

table.Rows[0].Cells[0].PreferredWidth = 100;

table.Rows[0].Cells[1].PreferredWidth = 200;

section.Paragraphs.Add( table );

// use preffered width for a cell in combination with a fixed table width and a fixed cell width

table = CreateTableWith1RowAnd2Cells();

table.PreferredWidth = 200;

table.ForceWidth =

true;

table.Rows[0].Cells[0].PreferredWidth = 100;

table.Rows[0].Cells[0].Fixed =

true;

table.Rows[0].Cells[1].PreferredWidth = 200;

section.Paragraphs.Add( table );

document.Write( file );

}

}

private static Table CreateTableWith2Rows()

{

// create a new table paragraph

Table table =

new Table();

// create the first row with one cell and some text

Cell rowCell = table.Rows.Add().Cells.Add();

rowCell.Paragraphs.Add( CreateTextParagraph( "Small text" ) );

rowCell.Border =

new Border( System.Drawing.Color.Black, 1 );

// create the second row with one cell and some text

rowCell = table.Rows.Add().Cells.Add();

rowCell.Paragraphs.Add( CreateTextParagraph( "This text occupies some additional space" ) );

rowCell.Border =

new Border( System.Drawing.Color.Black, 1 );

// add space after this table

table.SpacingAfter = 10;

return table;

}

private static Table CreateTableWith1RowAnd2Cells()

{

// create a new table paragraph

Table table =

new Table();

// Get a reference to a newly created row

Row tblRow = table.Rows.Add();

// create the first row with one cell and some text

Cell rowCell = tblRow.Cells.Add();

rowCell.Paragraphs.Add( CreateTextParagraph( "Small text" ) );

rowCell.Border =

new Border( System.Drawing.Color.Black, 1 );

// create the second row with one cell and some text

rowCell = tblRow.Cells.Add();

rowCell.Paragraphs.Add( CreateTextParagraph( "This text occupies some additional space" ) );

rowCell.Border =

new Border( System.Drawing.Color.Black, 1 );

// add space after this table

table.SpacingAfter = 10;

return table;

}

private static TextParagraph CreateTextParagraph( string text )

{

TextParagraph paragraph =

new TextParagraph();

paragraph.Fragments.Add(

new Fragment( text ) );

return paragraph;

}

}

}

Comments

Article rating:
Your rating:

Activity for this knol

This week:

35pageviews

Totals:

1011pageviews