Click or drag to resize

PdfTable Class

An object to output object data in a table format to a PdfGeneratedDocument.
Inheritance Hierarchy
SystemObject
  Atalasoft.PdfDoc.Generating.ShapesPdfTable

Namespace:  Atalasoft.PdfDoc.Generating.Shapes
Assembly:  Atalasoft.PdfDoc (in Atalasoft.PdfDoc.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
[SerializableAttribute]
public class PdfTable : IPdfRenderable, ICloneable

The PdfTable type exposes the following members.

Constructors
  NameDescription
Public methodPdfTable
Initializes a new instance of the PdfTable class.
Top
Properties
  NameDescription
Public propertyActualHeight
returns the height of the filled table.
Public propertyCode exampleBorderColor
Gets/sets the color to draw the border grid lines. The default border color is black.
Public propertyCode exampleBorderStyle
The border style for the table. See PdfTableBorderStyle The default border style is None. Border options are: Grid,Vertical,Horizontal,Outline, None.
Public propertyBorderWidth
Gets/sets the width the border should be drawn. This applies to all the lines that are drawn for the table The default border width is 1.
Public propertyBounds
Gets/sets the bounds for the table
Public propertyColumns
Returns the columns already set for the PdfTable. See PdfTableColumn
Public propertyFilledRowsCount
Gets a count of rows placed to the table after the Fill() method using. This value takes into account header row if it exists.
Public propertyFontName
Gets/sets the name of the font to be used
Public propertyFontSize
Gets/sets the size of the font.
Public propertyHasMoreRows
Returns true if there are more rows to draw for the table. Check this after the Fill() method to see if all the rows were written to the table.
Public propertyHeaderFontName
Gets or sets the name of the header font. If set to null, when Fill(PdfFontManager) is called, PdfTable will attempt to find a font named FontName + " Bold" in the system (creating a font resource if needed), otherwise it will use a font named by HeaderFontName.
Public propertyLineHeight
Gets/sets the height of each row in the table. If text has multiple lines the row height will be multiplied by the number of lines. The default row height is calculated based on the font type and font size specified.
Public propertyName
Gets/sets the name of the IPdfRenderable object.
Public propertyShowColumnHeadingRow
Get/sets whether to draw the a heading row for the table. Default is true.
Public propertyTextPaddingLeft
The padding from the left margin to the start of the text. This will apply to the entire table. If there is a column TextPaddingLeft defined it will override this value.
Public propertyTextPaddingRight
The padding from the end of the text to the right margin. This will apply to the entire table If there is a column TextPaddingRight defined it will override this value.
Top
Methods
  NameDescription
Public methodCode exampleAddRows
Add row data to the table. Pass an enumerator for a collection of items. Can also be an enumerator of a List<Dictionary<string,string>> object.
Public methodClone
Copy the PdfTable object to a new instance. Reuses the Font Resource manager. Reuses the Ta Does not copy table rows.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodFill
Fills the specified table with rows using the PdfTableInput enumerator This method must be called before the table attempts to render. This fills the table with the rows provided, it will stop at the point the table bounds height has been reached.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRender
Generates the PDFTable. Draws each row in the table
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
// constructor takes the PdfBounds for the table, the default font type, and font size
PdfTable productTable = new PdfTable(new PdfBounds(10, 100, 500, 600), "Arial", 6);

// create the table columns
// the columns are shown in the order they are added to the table
// add a column, pass the key, display Text, and column Width
productTable.Columns.Add(new PdfTableColumn("SKU", "Product Code", 50));

// if the width is not specified, the width will be calculated by using the average of what width is left 
productTable.Columns.Add(new PdfTableColumn("Name", "Product Name"));

productTable.Columns.Add(new PdfTableColumn("Quantity", "Quantity", 25));
productTable.Columns.Add(new PdfTableColumn("UnitPrice", "Price", 50));

// specify the BorderStyle,BorderWidth, and BorderColor
// BorderStyle options: Grid, Vertical, Horizontal, Outline, None
productTable.BorderStyle = PdfTableBorderStyle.Vertical;
productTable.BorderWidth = .5;
productTable.BorderColor = PdfColorFactory.FromColor(System.Drawing.Color.Black);

List<Product> productList = CreateProductList();
productTable.AddRows(productList.GetEnumerator());

// create the Pdf doc and page to draw to
PdfGeneratedDocument pdfDoc = new PdfGeneratedDocument();
PdfGeneratedPage page = PdfDefaultPages.Letter;

// populate the table with the data collection
productTable.Fill(pdfDoc.Resources.Fonts);

// add the table to the page
page.DrawingList.Add(productTable);
pdfDoc.Pages.Add(page);
Examples
The following example demonstrates how to create a document with a multi-page table.
Multi-page table
PdfGeneratedDocument pdfDoc = new PdfGeneratedDocument();
PdfGeneratedPage page = PdfDefaultPages.Letter;
List<Product> productList = CreateProductList(30);

PdfTable productTable = new PdfTable(new PdfBounds(10, 100, 500, 200), "Arial", 6);

productTable.Columns.Add(new PdfTableColumn("SKU", "Product Code", 30));
productTable.Columns.Add(new PdfTableColumn("Name", "Product Name"));
productTable.Columns.Add(new PdfTableColumn("Quantity", "Quantity", 50));
productTable.Columns.Add(new PdfTableColumn("UnitPrice", "Price", 50));

productTable.BorderStyle = PdfTableBorderStyle.Grid;
productTable.BorderWidth = .5;
productTable.BorderColor = PdfColorFactory.FromColor(System.Drawing.Color.Black);

productTable.AddRows(productList.GetEnumerator());

// populate the table with the collection data
productTable.Fill(pdfDoc.Resources.Fonts);

// add the table to the page
page.DrawingList.Add(productTable);
pdfDoc.Pages.Add(page);

while (productTable.HasMoreRows)
{
    page = PdfDefaultPages.Letter;
    productTable = (PdfTable)productTable.Clone();

    // populate the table with the collection data
    productTable.Fill(pdfDoc.Resources.Fonts);

    // add the table to the page
    page.DrawingList.Add(productTable);                
    pdfDoc.Pages.Add(page);
}

using (FileStream fs = new FileStream("MultipleIterationExampleTest.pdf", FileMode.Create,
    FileAccess.ReadWrite, FileShare.Read))
    pdfDoc.Save(fs);
See Also