To format text, you can use the PHPRtfLite_Font.
Example sets size to 12pt, font family to Arial, font color to red, and background color to blue:
<?php
// some bootstraping here
$section = $rtf->addSection();
$font = new PHPRtfLite_Font(12, 'Arial', '#FF0000', '#0000FF');
$section->writeText('Lorem ipsum', $font);
<?php
// some bootstraping here
$section = $rtf->addSection();
$font = new PHPRtfLite_Font();
$font->setBold(); // bold font
$font->setItalic(); // italic font
$font->setUnderline(); // underline font
$font->setStriked(); // strike text
$font->setDoubleStriked(); // double strike text
$section->writeText('Lorem ipsum', $font);
You can use HTML-Tags in your text to format text:
<?php
// some bootstraping here
$section = $rtf->addSection();
// text will be displayed as bold
$section->writeText('<strong>text</strong>');
$section->writeText('<b>text</b>');
// text will be displayed as italic
$section->writeText('<em>text</em>');
$section->writeText('<i>text</i>');
// text will be displayed as underlined
$section->writeText('<u>text</u>');
// text will start with a bullet
$section->writeText('<bullet> text');
// text will have a line break after
$section->writeText('text<br>');
// text will have a horizontal rule after
$section->writeText('text<hr>');
// tabulator will be displayed between text
$section->writeText('text<tab>text');
// will display section number before "hello world"
$section->writeText('<sectnum> hello world');
// will display page number before "hello world"
$section->writeText('<pagenum> hello world');
Class constants for text animation:
<?php
// some bootstraping here
$section = $rtf->addSection();
$font = new PHPRtfLite_Font();
// text with marching black ants around
$font->setAnimation(PHPRtfLite_Font::ANIMATE_MARCHING_BLACK_ANTS);
$section->writeText('Lorem ipsum', $font);
Class constants for text alignment:
<?php
// some bootstraping here
$section = $rtf->addSection();
// centered text
$parFormat = new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER);
$section->writeText('Lorem ipsum', null, $parFormat);
First line indention:
<?php
// some bootstraping here
$section = $rtf->addSection();
$parFormat = new PHPRtfLite_ParFormat();
// first line of paragraph will be indented by 1cm
$parFormat->setIndentFirstLine(1);
$section->writeText('Lorem ipsum', null, $parFormat);
Indent the whole paragraph left or/and right:
<?php
// some bootstraping here
$parFormat = new PHPRtfLite_ParFormat();
// paragraph will be indented by 1cm from the left and right
$parFormat->setIndentLeft(1);
$parFormat->setIndentRight(1);
<?php
// some bootstraping here
$parFormat = new PHPRtfLite_ParFormat();
// spaces in lines after the paragraph
$parFormat->setSpaceAfter(1);
// spaces in lines before the paragraph
$parFormat->setSpaceBefore(1);
<?php
// some bootstraping here
$parFormat = new PHPRtfLite_ParFormat();
// spaces between lines
$parFormat->setSpaceBetweenLines(1);
Paragraph background color:
<?php
// some bootstraping here
$parFormat = new PHPRtfLite_ParFormat();
$parFormat->setBackgroundColor('#FF0000');
<?php
// some bootstraping here
$border = new PHPRtfLite_Border(
$rtf, // PHPRtfLite instance
new PHPRtfLite_Border_Format(2, '#00FF00'), // left border: 2pt, green color
new PHPRtfLite_Border_Format(1, '#FFFF00'), // top border: 1pt, yellow color
new PHPRtfLite_Border_Format(2, '#FF0000'), // right border: 2pt, red color
new PHPRtfLite_Border_Format(1, '#0000FF') // bottom border: 1pt, blue color
);
$parFormat = new PHPRtfLite_ParFormat();
$parFormat->setBorder($border);
There are some alternative ways to create borders:
<?php
// some bootstraping here
// creating border in a different way: 1pt dotted red border with 0.5cm space
$border = PHPRtfLite_Border::create($rtf, 1, '#FF3333', PHPRtfLite_Border_Format::TYPE_DOT, 0.5);
<?php
// some bootstraping here
// creating border in a different way: 1pt dotted red border
$border = new PHPRtfLite_Border($rtf);
// 2pt border in green color
$border->setBorders(new PHPRtfLite_Border_Format(2, '#00FF00'));
Border style types represented as class constants of PHPRtfLite_Border_Format are: