Background Color:
 
Background Pattern:
Reset
Search
Home Recent Changes Show All Pages

Table, Row, Cell

Not Rated Yet

The table is a concrete layout container that arranges it's inner content in a grid like structure. Each table is composed of rows, cells, and then content within the cells.

Article Contents

A simple table

The most basic table is a collection of cells , with some textual content.

      <pdf:Table id="MyTable" >
          <pdf:Row id="FirstRow" >
            <pdf:Cell>Cell A1 content</pdf:Cell>
            <pdf:Cell>Cell B1 content</pdf:Cell>
            <pdf:Cell>Cell C1 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell>Cell A2 content</pdf:Cell>
            <pdf:Cell>Cell B2 content</pdf:Cell>
            <pdf:Cell>Cell C2 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell>Cell A3 content</pdf:Cell>
            <pdf:Cell>Cell B3 content</pdf:Cell>
            <pdf:Cell>Cell C3 content</pdf:Cell>
          </pdf:Row>
        </pdf:Table>
            PDFDocument doc = new PDFDocument();
            PDFPage page = new PDFPage();
            doc.Pages.Add(page);

            PDFTableGrid tbl = new PDFTableGrid();
            page.Contents.Add(tbl);

            PDFTableRow row = new PDFTableRow();
            tbl.Rows.Add(row);

            PDFTableCell cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A1 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B1 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C1 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A2 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B2 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C2 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A3 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B3 content"));

            cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C3 content"));

Preview Image

Table cell styles

Because tables and their cells are block level components they fully support block styles including borders, backgrounds, padding, margins and padding.
It also becomes evident how much quicker it is to write the content of a document in XML rather than the long winded code (although this could obviously be optimised).

<Styles>

    <style:Style applied-type="pdf:Table" applied-class="bordered" >
      <style:Border color="maroon" corner-radius="4pt" sides="Bottom Right"/>
    </style:Style>
    <style:Style applied-type="pdf:Cell" applied-class="bordered" >
      <style:Border color="aqua" width="1pt" corner-radius="4pt" sides="Top Left"/>
      <style:Padding all="4pt"/>
      <style:Margins all="4pt"/>
      <style:Font size="12pt" bold="true" />
    </style:Style>
    
  </Styles>

  <!-- document content -->

      <pdf:Table id="MyTable" style:class="bordered" >
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A1 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B1 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C1 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A2 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B2 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C2 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C3 content</pdf:Cell>
          </pdf:Row>
        </pdf:Table>
            PDFDocument doc = new PDFDocument();

            //Define the styles in the document
            PDFStyleDefn tblstyle = new PDFStyleDefn();
            tblstyle.AppliedClass = "bordered";
            tblstyle.AppliedType = typeof(PDFTableGrid);
            tblstyle.Border.Color = PDFColors.Maroon;
            tblstyle.Border.CornerRadius = 4;
            tblstyle.Border.Sides = Sides.Bottom | Sides.Right;
            doc.Styles.Add(tblstyle);

            PDFStyleDefn cellstyle = new PDFStyleDefn();
            cellstyle.AppliedType = typeof(PDFTableCell);
            cellstyle.AppliedClass = "bordered";

            cellstyle.Border.Color = PDFColors.Aqua;
            cellstyle.Border.CornerRadius = 4;
            cellstyle.Border.Width = 1;
            cellstyle.Border.Sides = Sides.Top | Sides.Left;
            cellstyle.Padding.All = 4;
            cellstyle.Margins.All = 4;
            cellstyle.Font.FontSize = 12;
            cellstyle.Font.FontBold = true;
            doc.Styles.Add(cellstyle);

            
            PDFPage page = new PDFPage();
            doc.Pages.Add(page);

            //Add the table to the page
            PDFTableGrid tbl = new PDFTableGrid();
            tbl.StyleClass = "bordered";
            page.Contents.Add(tbl);

            PDFTableRow row = new PDFTableRow();
            tbl.Rows.Add(row);

            PDFTableCell cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.StyleClass = "bordered";
            cell.Contents.Add(new PDFTextLiteral("Cell A1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C1 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C2 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C3 content"));

Preview Image

For more information on styles and how they work see Understanding Styles

Table widths

Each cell can be explicitly sized, and the rest of the content will adjust to accommodate the sizes
By default the width of the table is set to the required content size, but it also honours the full width attribute (stretching to fill the available width)

NOTE: We are applying the styles here using multiple class names, which are fully supported in scryber, and will be applied in the order they are specified

<Styles>

    <style:Style applied-type="pdf:Table" applied-class="bordered" >
      <style:Border color="maroon" corner-radius="4pt" sides="Bottom Right"/>
    </style:Style>
    <style:Style applied-type="pdf:Cell" applied-class="bordered" >
      <style:Border color="aqua" width="1pt" corner-radius="4pt" sides="Top Left"/>
      <style:Padding all="4pt"/>
      <style:Margins all="4pt"/>
      <style:Font size="12pt" bold="true" />
    </style:Style>
    
    <style:Style applied-class="full-width" >
      <style:Position full-width="true"/>
    </style:Style>

    <style:Style applied-class="fixed80" >
      <style:Position width="80pt" height="80pt"/>
    </style:Style>
  </Styles>

  <!-- document content -->

      <pdf:Table id="MyTable" style:class="bordered full-sized" >
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A1 content</pdf:Cell>
            <pdf:Cell style:class="bordered fixed80">Cell B1 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C1 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A2 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B2 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C2 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C3 content</pdf:Cell>
          </pdf:Row>
        </pdf:Table>
            PDFDocument doc = new PDFDocument();

            //Define the styles in the document
            PDFStyleDefn tblstyle = new PDFStyleDefn();
            tblstyle.AppliedClass = "bordered";
            tblstyle.AppliedType = typeof(PDFTableGrid);
            tblstyle.Border.Color = PDFColors.Maroon;
            tblstyle.Border.CornerRadius = 4;
            tblstyle.Border.Sides = Sides.Bottom | Sides.Right;
            doc.Styles.Add(tblstyle);

            PDFStyleDefn cellstyle = new PDFStyleDefn();
            cellstyle.AppliedType = typeof(PDFTableCell);
            cellstyle.AppliedClass = "bordered";

            cellstyle.Border.Color = PDFColors.Aqua;
            cellstyle.Border.CornerRadius = 4;
            cellstyle.Border.Width = 1;
            cellstyle.Border.Sides = Sides.Top | Sides.Left;
            cellstyle.Padding.All = 4;
            cellstyle.Margins.All = 4;
            cellstyle.Font.FontSize = 12;
            cellstyle.Font.FontBold = true;
            doc.Styles.Add(cellstyle);

            PDFStyleDefn fullW = new PDFStyleDefn();
            fullW.AppliedClass = "full-sized";
            fullW.Position.FullWidth = true;
            doc.Styles.Add(fullW);

            PDFStyleDefn fixed80 = new PDFStyleDefn();
            fixed80.AppliedClass = "fixed80";
            fixed80.Position.Width = 80;
            fixed80.Position.Height = 80;
            doc.Styles.Add(fixed80);
            
            PDFPage page = new PDFPage();
            doc.Pages.Add(page);

            //Add the table to the page
            PDFTableGrid tbl = new PDFTableGrid();
            tbl.StyleClass = "bordered";
            tbl.StyleClass += " full-sized";
            page.Contents.Add(tbl);

            PDFTableRow row = new PDFTableRow();
            tbl.Rows.Add(row);

            PDFTableCell cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.StyleClass = "bordered";
            cell.Contents.Add(new PDFTextLiteral("Cell A1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered fixed80";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C1 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C2 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C3 content"));

Preview Image

It is evident that the content of the second column is being squeezed into the specified width (80pt) and the other 2 columns are stretching to take this into account and fill the rest of the available width

It can also be seen that the cell height is being honoured across the entire first row.

Table cell spans

Each cell also supports a column-span attribute, this can either be explicitly specified on the cell, or driven from the >style:Table< element with the @cell-column-span attribute.

NOTE: Row span is not currently supported, but may be in the future

<Styles>

    <style:Style applied-type="pdf:Table" applied-class="bordered" >
      <style:Border color="maroon" corner-radius="4pt" sides="Bottom Right"/>
    </style:Style>
    <style:Style applied-type="pdf:Cell" applied-class="bordered" >
      <style:Border color="aqua" width="1pt" corner-radius="4pt" sides="Top Left"/>
      <style:Padding all="4pt"/>
      <style:Margins all="4pt"/>
      <style:Font size="12pt" bold="true" />
    </style:Style>
    
    <style:Style applied-class="full-width" >
      <style:Position full-width="true"/>
    </style:Style>

    <style:Style applied-class="fixed80" >
      <style:Position width="80pt" height="80pt"/>
    </style:Style>
  </Styles>

  <!-- document content -->

      <pdf:Table id="MyTable" style:class="bordered full-sized" >
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A1 content</pdf:Cell>
            <pdf:Cell style:class="bordered fixed80">Cell B1 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C1 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered" style:column-span="2" >Cell A2 content</pdf:Cell>
            <!-- <pdf:Cell style:class="bordered">Cell B2 content</pdf:Cell>-->
            <pdf:Cell style:class="bordered">Cell C2 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered" >Cell A3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C3 content</pdf:Cell>
          </pdf:Row>
        </pdf:Table>
            PDFDocument doc = new PDFDocument();

            //Define the styles in the document
            PDFStyleDefn tblstyle = new PDFStyleDefn();
            tblstyle.AppliedClass = "bordered";
            tblstyle.AppliedType = typeof(PDFTableGrid);
            tblstyle.Border.Color = PDFColors.Maroon;
            tblstyle.Border.CornerRadius = 4;
            tblstyle.Border.Sides = Sides.Bottom | Sides.Right;
            doc.Styles.Add(tblstyle);

            PDFStyleDefn cellstyle = new PDFStyleDefn();
            cellstyle.AppliedType = typeof(PDFTableCell);
            cellstyle.AppliedClass = "bordered";

            cellstyle.Border.Color = PDFColors.Aqua;
            cellstyle.Border.CornerRadius = 4;
            cellstyle.Border.Width = 1;
            cellstyle.Border.Sides = Sides.Top | Sides.Left;
            cellstyle.Padding.All = 4;
            cellstyle.Margins.All = 4;
            cellstyle.Font.FontSize = 12;
            cellstyle.Font.FontBold = true;
            doc.Styles.Add(cellstyle);

            PDFStyleDefn fullW = new PDFStyleDefn();
            fullW.AppliedClass = "full-sized";
            fullW.Position.FullWidth = true;
            doc.Styles.Add(fullW);

            PDFStyleDefn fixed80 = new PDFStyleDefn();
            fixed80.AppliedClass = "fixed80";
            fixed80.Position.Width = 80;
            fixed80.Position.Height = 80;
            doc.Styles.Add(fixed80);
            
            PDFPage page = new PDFPage();
            doc.Pages.Add(page);

            //Add the table to the page
            PDFTableGrid tbl = new PDFTableGrid();
            tbl.StyleClass = "bordered";
            tbl.StyleClass += " full-sized";
            page.Contents.Add(tbl);

            PDFTableRow row = new PDFTableRow();
            tbl.Rows.Add(row);

            PDFTableCell cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.StyleClass = "bordered";
            cell.Contents.Add(new PDFTextLiteral("Cell A1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered fixed80";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C1 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            cell.ColumnSpan = 2;
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A2 content"));

            //cell = new PDFTableCell();
            //cell.StyleClass = "bordered";
            //row.Cells.Add(cell);
            //cell.Contents.Add(new PDFTextLiteral("Cell B2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C2 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C3 content"));

Preview Image

Now the first cell of the second row stretches to accommodate the first and second column.

Header and Footer cells

A table also supports the concept of table headers and footers. There is no requirement that header cells sit within header rows, it is entirely up to the required presentation
But a header cell will get all the style associated with a standard cell, along with any style explicitly defined for the header.

  <Styles>

    <style:Style applied-type="pdf:Table" applied-class="bordered" >
      <style:Border color="maroon" corner-radius="4pt" sides="Bottom Right"/>
    </style:Style>
    
    <style:Style applied-type="pdf:Cell" applied-class="bordered" >
      <style:Border color="aqua" width="1pt" corner-radius="4pt" sides="Top Left"/>
      <style:Padding all="4pt"/>
      <style:Margins all="4pt"/>
      <style:Font size="12pt" bold="true" />
    </style:Style>

    <style:Style applied-class="full-width" >
      <style:Position full-width="true"/>
    </style:Style>

    <style:Style applied-class="fixed80" >
      <style:Position width="80pt" height="80pt"/>
    </style:Style>

   <style:Style applied-type="pdf:Header-Cell" applied-class="bordered" >
      <style:Border color="maroon" sides="Left Bottom"/>
    </style:Style>

    <style:Style applied-type="pdf:Footer-Cell" applied-class="bordered" >
      <style:Border color="#AAAA00" sides="Left Top Right"/>
    </style:Style>
  </Styles>

  <!-- document content -->

      <pdf:Table id="MyTable" style:class="bordered full-width" >
          <pdf:Header-Row>
            <pdf:Header-Cell style:class="bordered" >Header A</pdf:Header-Cell>
            <pdf:Header-Cell style:class="bordered" >Header B</pdf:Header-Cell>
            <pdf:Header-Cell style:class="bordered" >Header C</pdf:Header-Cell>
          </pdf:Header-Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A1 content</pdf:Cell>
            <pdf:Cell style:class="bordered fixed80">Cell B1 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C1 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered" style:column-span="2">Cell A2 content</pdf:Cell>
            <!--<pdf:Cell style:class="bordered">Cell B2 content</pdf:Cell>-->
            <pdf:Cell style:class="bordered">Cell C2 content</pdf:Cell>
          </pdf:Row>
          <pdf:Row id="FirstRow" >
            <pdf:Cell style:class="bordered">Cell A3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell B3 content</pdf:Cell>
            <pdf:Cell style:class="bordered">Cell C3 content</pdf:Cell>
          </pdf:Row>
          <pdf:Footer-Row>
            <pdf:Cell ></pdf:Cell>
            <pdf:Footer-Cell style:class="bordered" >Footer B</pdf:Footer-Cell>
            <pdf:Footer-Cell style:class="bordered" >Footer C</pdf:Footer-Cell>
          </pdf:Footer-Row>
        </pdf:Table>
            PDFDocument doc = new PDFDocument();

            //Define the styles in the document
            PDFStyleDefn tblstyle = new PDFStyleDefn();
            tblstyle.AppliedClass = "bordered";
            tblstyle.AppliedType = typeof(PDFTableGrid);
            tblstyle.Border.Color = PDFColors.Maroon;
            tblstyle.Border.CornerRadius = 4;
            tblstyle.Border.Sides = Sides.Bottom | Sides.Right;
            doc.Styles.Add(tblstyle);

            PDFStyleDefn cellstyle = new PDFStyleDefn();
            cellstyle.AppliedType = typeof(PDFTableCell);
            cellstyle.AppliedClass = "bordered";

            cellstyle.Border.Color = PDFColors.Aqua;
            cellstyle.Border.CornerRadius = 4;
            cellstyle.Border.Width = 1;
            cellstyle.Border.Sides = Sides.Top | Sides.Left;
            cellstyle.Padding.All = 4;
            cellstyle.Margins.All = 4;
            cellstyle.Font.FontSize = 12;
            cellstyle.Font.FontBold = true;
            doc.Styles.Add(cellstyle);

            PDFStyleDefn fullW = new PDFStyleDefn();
            fullW.AppliedClass = "full-sized";
            fullW.Position.FullWidth = true;
            doc.Styles.Add(fullW);

            PDFStyleDefn fixed80 = new PDFStyleDefn();
            fixed80.AppliedClass = "fixed80";
            fixed80.Position.Width = 80;
            fixed80.Position.Height = 80;
            doc.Styles.Add(fixed80);

            PDFStyleDefn header = new PDFStyleDefn();
            header.AppliedClass = "bordered";
            header.AppliedType = typeof(PDFTableHeaderCell);
            header.Border.Sides = Sides.Bottom | Sides.Left;
            header.Border.Color = PDFColors.Maroon;
            doc.Styles.Add(header);

            PDFStyleDefn footer = new PDFStyleDefn();
            footer.AppliedClass = "bordered";
            footer.AppliedType = typeof(PDFTableFooterCell);
            footer.Border.Sides = Sides.Top | Sides.Left | Sides.Right;
            footer.Border.Color = new PDFColor(170, 170, 0);
            doc.Styles.Add(footer);
            
            PDFPage page = new PDFPage();
            doc.Pages.Add(page);

            //Add the table to the page
            PDFTableGrid tbl = new PDFTableGrid();
            tbl.StyleClass = "bordered";
            tbl.StyleClass += " full-sized";
            page.Contents.Add(tbl);

            //Header Row
            PDFTableHeaderRow hrow = new PDFTableHeaderRow();
            tbl.Rows.Add(hrow);

            PDFTableHeaderCell hcell = new PDFTableHeaderCell();
            hcell.StyleClass = "bordered";
            hcell.Contents.Add(new PDFTextLiteral("Header A"));
            hrow.Cells.Add(hcell);

            hcell = new PDFTableHeaderCell();
            hcell.StyleClass = "bordered";
            hcell.Contents.Add(new PDFTextLiteral("Header B"));
            hrow.Cells.Add(hcell);

            hcell = new PDFTableHeaderCell();
            hcell.StyleClass = "bordered";
            hcell.Contents.Add(new PDFTextLiteral("Header C"));
            hrow.Cells.Add(hcell);

            //Content
            PDFTableRow row = new PDFTableRow();
            tbl.Rows.Add(row);

            PDFTableCell cell = new PDFTableCell();
            row.Cells.Add(cell);
            cell.StyleClass = "bordered";
            cell.Contents.Add(new PDFTextLiteral("Cell A1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered fixed80";
            cell.ColumnSpan = 2;
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B1 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C1 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B2 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C2 content"));

            row = new PDFTableRow();
            tbl.Rows.Add(row);

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell A3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell B3 content"));

            cell = new PDFTableCell();
            cell.StyleClass = "bordered";
            row.Cells.Add(cell);
            cell.Contents.Add(new PDFTextLiteral("Cell C3 content"));

            //Footer Row
            PDFTableFooterRow frow = new PDFTableFooterRow();
            tbl.Rows.Add(frow);

            PDFTableFooterCell fcell = new PDFTableFooterCell();
            fcell.StyleClass = "bordered";
            hrow.Cells.Add(fcell);

            fcell = new PDFTableFooterCell();
            fcell.StyleClass = "bordered";
            fcell.Contents.Add(new PDFTextLiteral("Footer B"));
            hrow.Cells.Add(fcell);

            fcell = new PDFTableFooterCell();
            fcell.StyleClass = "bordered";
            fcell.Contents.Add(new PDFTextLiteral("Footer C"));
            hrow.Cells.Add(fcell);

Preview Image

 

Because the footer cell in column A is empty, nothing is rendered, only if a cell actually has some content would it be laid out and rendered.

 

Overflow and repeating rows

Table rows appear as a block that cannot be split across pages, so if the content within the row is larger than the available space on the page or column the entire row will overflow onto the next available column or page.

If the table has header rows (<Header-Row>), then they (by default) will be repeated at the top of the new block. There is actually nothing special about the header row, it is simply a sub-class of the PDFTableRow with a base style extended with the table style row repeat set. Style.TableStyle.RowRepeat = TableRowRepeat.RepeatAtTop

When the tables rows are laid out this style marker is checked, and any that are set will be repeated at the top of any new block, so you can switch it off for header rows as required, and switch it on for other rows, and as it is style based it can be applied based on the various application options

 

<Styles>

    <styles:Styles-Ref source="../Units/UnitStyles.psfx"/>
    
    <styles:Style applied-type="pdf:Page" >
      <styles:Font size="12" family="Helvetica" />
      <styles:Columns count="2"/>
      <styles:Margins all="10pt"/>
    </styles:Style>


    <styles:Style applied-type="pdf:Cell">
      <styles:Border color="black" width="1pt"/>
      <styles:Padding all="4pt"/>
    </styles:Style>
    
    <styles:Style applied-id="NonRepeating">
      <styles:Table row-repeat="None"/>
    </styles:Style>
   
    
  </Styles>

  
  <Pages>

    <pdf:Section id="RepeatingRows" >
      <Header>A table that will overflow onto a new column with repeating row headers.</Header>
      <Content>

        <pdf:Div id="Spacer" styles:height="200mm" styles:bg-color="#CCC" >
          This is a spacer to push the table down.
        </pdf:Div>

        <pdf:Table styles:full-width="true" styles:margins="10 0 0 0">
          <!-- This header row will only appear on the first block based
          on the applied id style -->
          <pdf:Header-Row id="NonRepeating" styles:bg-color="#33FFFF" >
            <pdf:Header-Cell>Only Once</pdf:Header-Cell>
            <pdf:Header-Cell>Will This Row appear</pdf:Header-Cell>
          </pdf:Header-Row>
          
          <!-- This header row will repeat as normal based on
          the default Header-Row style -->
          <pdf:Header-Row id="NormalHeaderRow" styles:bg-color="#66FFFF">
            <pdf:Header-Cell>Every Block</pdf:Header-Cell>
            <pdf:Header-Cell>Will contain this row</pdf:Header-Cell>
          </pdf:Header-Row>

          <!-- The next 2 are standard rows -->
          <pdf:Row id="NormalRow1" >
            <pdf:Cell >Will only</pdf:Cell>
            <pdf:Cell>Appear once in the entire table</pdf:Cell>
          </pdf:Row>

          <pdf:Row id="NormalRow2" >
            <pdf:Cell >Will only</pdf:Cell>
            <pdf:Cell>Appear once in the entire table</pdf:Cell>
          </pdf:Row>

          <!-- This is a repeating row because the style is being
           applied explicitly. -->
          <pdf:Row id="RepeatingStdRow" styles:repeat="RepeatAtTop" styles:bg-color="#99FFFF" >
            <pdf:Cell >Will repeat</pdf:Cell>
            <pdf:Cell>On every block the table flows on to.</pdf:Cell>
          </pdf:Row>

          <!-- These rows will overflow the content onto a new column -->
          <pdf:Row id="NormalRow3" >
            <pdf:Cell >Will only</pdf:Cell>
            <pdf:Cell>Appear once in the entire table</pdf:Cell>
          </pdf:Row>

          <pdf:Row id="NormalRow4" >
            <pdf:Cell >Will only</pdf:Cell>
            <pdf:Cell>Appear once in the entire table</pdf:Cell>
          </pdf:Row>

          <pdf:Row id="NormalRow5" >
            <pdf:Cell >Will only</pdf:Cell>
            <pdf:Cell>Appear once in the entire table</pdf:Cell>
          </pdf:Row>
          
        </pdf:Table>
        
      </Content>
    </pdf:Section>

  </Pages>

Preview Image

 

Note: Repeating rows will repeat the exact same content, dynamic content such as page numbers will not change even if the repeat is on a different page. There is also a known defect that if the repeating row is also the first row in the new repeating block then the spacing will be mixed up. This will be fixed in a later release

 

See Also



  Rating
Rate This Page: Poor Great   |  Rate Content |
Average rating:  No Ratings Yet   
Number of Ratings : 0
  Comments
Add Comment
No Comments Yet