Example 7

Description

It is possible to define new text styles, and they can be put into the global list of text styles. They can be accessed by their names.
The new text styles can use any other text style as base and inherit some settings and change others. The example shows three self defined text styles.

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();

// Create a text style with the name "MyTextStyle1", 36 points tall and red
$ts = ReportLib\TextStyles::addTextStyle("MyTextStyle1", ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::NORMAL));
$ts->setSize(36.0);
$ts->setTextColor("#FF0000");

// Print text using "MyTextStyle1"
$body->AddText("Very big red text style. Only the size and the color have been adjusted. The other attributes come from the NORMAL text style.", ReportLib\TextStyles::getTextStyle("MyTextStyle1"));
$body->AddVDistance(2.0);

// Create a text style with the name "MyTextStyle2", size 11 points and grey background color
$ts = ReportLib\TextStyles::addTextStyle("MyTextStyle2", ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::NORMAL));
$ts->setSize(11.0);
$ts->setBackgroundColor("#DDDDDD");

// Print text using "MyTextStyle2"
$body->AddText("A text style with a grey background color. Only the background color and the size have been adjusted. The other attributes come from the NORMAL text style.", ReportLib\TextStyles::getTextStyle("MyTextStyle2"));
$body->AddVDistance(2.0);

// Create a text style with the name "MyTextStyle3" - change all attributes of the base style
$ts = ReportLib\TextStyles::addTextStyle("MyTextStyle3", ReportLib\TextStyles::getTextStyle(ReportLib\TextStyles::NORMAL));
$ts->setSize(16.0);
$ts->setBold(true);
$ts->setItalic(true);
$ts->setUnderline(true);
$ts->setFontFamily("Courier");
$ts->setTextColor("#0000FF");
$ts->setBackgroundColor("#DDDDDD");

// Print text using "MyTextStyle3"
$body->AddText("A 16 point bold, italic and underlined Courier text style with a grey background and a blue font color - so all possible attributes have been adjusted.", ReportLib\TextStyles::getTextStyle("MyTextStyle3"));

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