Example 14

Description

Here the widths of the columns in the table are defined in percent of the full width of the frame. To do that the values for the width has to be passed as string (the percent sign is not necessary but it makes the code more readable).
The first row just below the header shows the original widths of the columns.
If the sum of all columns is less the 100 percent (80% in the example), it will use only that part of the frame width.
If it is more than 100 percent ‘line breaks’ will be added (see example about ‘line breaks’ in tables.

Output

<?php

include_once "../src/Report.php";

use Adi\ReportLib as ReportLib;

// Create report instance
//  default format A4, portrait with margins left = 20mm, top = 10mm, right = 10mm and bottom = 10mm
$report = new ReportLib\Report();

// Get ref to the report body
$body = $report->getBody();

// Add the table
$table = $body->AddTable();

// Add four columns to the table
$table->addColumn("frametype", "Frame type", "15.0%");
$table->addColumn("container", "Container type", "15.0%", 'C');
$table->addColumn("description", "Description", "40.0%");
$table->addColumn("number", "Number", "10.0%", 'R');

// Add a data row to the table
$row = new ReportLib\TableRow('D');
$row->setText("frametype", "15% width");
$row->setText("container", "15% width");
$row->setText("description", "40% width");
$row->setText("number", "10% width");
$table->addDataRow($row);


// Add a data row to the table
$row = new ReportLib\TableRow('D');
$row->setText("frametype", "LineFrame");
$row->setText("container", "No");
$row->setText("description", "This frame type represents a line on the report.");
$row->setText("number", "1");
$table->addDataRow($row);

// Add a second data row to the table
$row = new ReportLib\TableRow('D');
$row->setText("frametype", "SerialFrame");
$row->setText("container", "Yes");
$row->setText("description", "This is a frame container for a series of frames which will be printed one after the other.");
$row->setText("number", "2");
$table->addDataRow($row);

// Add a third data row to the table
$row = new ReportLib\TableRow('D');
$row->setText("frametype", "TextFrame");
$row->setText("container", "No");
$row->setText("description", "A simple frame type to print text.");
$row->setText("number", "3");
$table->addDataRow($row);

// Produce the output of the report
//  uses the same params as TCPDF (F = File, I = Preview etc.)
$report->output(__DIR__ . "/example_014.pdf", 'I');