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 dimensionssection.Paragraphs.Add( CreateTableWith2Rows() );
section.Paragraphs.Add( CreateTableWith1RowAnd2Cells() );
Table table;
// use a fixed table witdhtable = 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 contenttable = 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 celltable = 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 widthtable = 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 widthtable = 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 paragraphTable table =
new Table(); // create the first row with one cell and some textCell 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 textrowCell = 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 tabletable.SpacingAfter = 10;
return table;}
private static Table CreateTableWith1RowAnd2Cells(){
// create a new table paragraphTable table =
new Table(); // Get a reference to a newly created rowRow tblRow = table.Rows.Add();
// create the first row with one cell and some textCell 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 textrowCell = 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 tabletable.SpacingAfter = 10;
return table;}
private static TextParagraph CreateTextParagraph( string text ){
TextParagraph paragraph =
new TextParagraph();paragraph.Fragments.Add(
new Fragment( text ) ); return paragraph;}
}
}





Comments
Write New Comment ▼
Write New Comment
Sorry! This knol's owner(s) have blocked you from editing, making suggestions, or commenting here.