TCPDF Advanced Multicell User Manual


The PHP Pdf Addons will work right out of the box. All you need is a webserver with Php 5.5 (or greater). No further
configurations are required.

Just download the files, extract the content in a directory where your webserver is configured and call the url.

Every add-on has multiple example files that cover the full functionality.

Include the library into the project

Normally, from the downloaded package you need only the files from library\interpid\PdfLib folder in order to run it.

Using "require_once"

In order to include the full interpid library, just include the autoload.php provided in the root folder. This will
provide you the TCPDF and all Interpid PdfLib library classes.

Assuming you downloaded tcpdf-multicell-3.0.0 and placed in your project libs folder:

require_once 'libs/tcpdf-multicell-3.0.0/autoload.php';

With composer.json

If your project uses composer, then include the pdf library path to your composer file:

In composer.json

"autoload": {
  "classmap": [

or you can use the PSR-4 autoload capabilities

In composer.json

"autoload": {
  "psr-4": {
    "Interpid\\PdfLib\\": "libs/tcpdf-multicell-3.0.0/library/interpid/PdfLib/"

then run composer dump-autoload to regenerate the autoload classmap.


Please go to your account on to download the latest versions of the addons.


To generate an "Advanced Multicell" the followings are required:

  • have a valid TCPDF/PDF object
  • create the advanced multicell object instance
  • add the multicells to the pdf document
use Interpid\PdfLib\Multicell;
use Interpid\PdfLib\Pdf; // Pdf extends TCPDF

// create the Pdf Object
$pdf = new Pdf();

// do some pdf initialization settings
// $pdf->SetMargins(20, 20, 20);

// create the Multicell Object
$multicell = new Multicell($pdf);

// set the style definitions
// `default` is applied to all tags
$multicell->setStyle('default', 11, '', '130,0,30', 'helvetica');
$multicell->setStyle('p', 11, '', '130,0,30', 'helvetica');
$multicell->setStyle('b', null, 'B', null, null);

// create the advanced multicells
$multicell->multiCell(0, 5, 'This is a simple cell');
$multicell->multiCell(0, 5, '<p>This is a <b>BOLD</b> text</p>');

Why use the \Interpid\PdfLib\Pdf object instead of TCPDF

To implement the TCPDF Add-on, we need access to private/protected properties from the TCPDF class like widths, margins,
fonts etc... As these properties are not provided by setters and getters the TCPDF class was extended and these
properties made public.

namespace Interpid\PdfLib;

class Pdf extends \TCPDF
    public $images;
    public $w;
    public $tMargin;

Create the Pdf object

Please refer to the TCPDF class manual in order to get this done correctly. Example:

use Interpid\PdfLib\Pdf;

// Pdf extends TCPDF
$pdf = new Pdf();

// use the default TCPDF configuration
$pdf->SetMargins(20, 20, 20);
$pdf->SetAutoPageBreak(true, 20);

$pdf->SetFont('helvetica', '', 11);
$pdf->SetTextColor(200, 10, 10);
$pdf->SetFillColor(254, 255, 245);

// add a page

Create the Advanced Multicell object

// Create the Advanced Multicell Object and inject the PDF object
use Interpid\PdfLib\Multicell;
$multicell = new Multicell($pdf);

Tag styling

A tag style is used specify the text display properties. The following properties can be set:

  • size/font_size: 8, 9, 10 ...
  • style/font_style: one or a combination of the following values:
    • B (Bold), U (Underline), I (Italic)
    • examples: "B", "BI"
  • color/text_color: specify a string or array: '130,0,30' or [130,0,30]
  • family/font_family: example 'Arial', 'helvetica' or any other font family
  • inherit: the style name that will be inherited.


// define a tag style using associative array
$multicell->setStyleAssoc('p', ['size' => 11, 'style' => '', 'color' => '130,0,30', 'family' => 'helvetica']);

// define only a few properties
$multicell->setStyleAssoc('b', ['style' => 'B']);
$multicell->setStyleAssoc('fancy-bi', ['style' => 'BI', 'color' => '130,0,30']);

// Set the styles for the advanced multicell using `setStyle`
$multicell->setStyle('p', 11, '', '130,0,30', 'helvetica');
$multicell->setStyle('b', 11, 'B', '130,0,30', 'helvetica');
$multicell->setStyle('i', 11, 'I', '80,80,260', 'helvetica');

Style Inheritance

Styles can be inherited if specified so.

// you can specify which style should be inherited
// example: define a base "h" style and h1, h2, h3, h4 will inherit h
$multicell->setStyle('h', null, 'B', '203,0,48');
$multicell->setStyle('h1', 16, null, null, null, 'h');
$multicell->setStyle('h2', 14, null, null, null, 'h');
$multicell->setStyle('h3', 12, null, null, null, 'h');
$multicell->setStyle('h4', 11, 'B', null, null, 'h');

// a more simple approach: use the `style` function
$multicell->setStyleAssoc('h1', ['size' => 16], 'h');
$multicell->setStyleAssoc('h2', ['size' => 14], 'h');
$multicell->setStyleAssoc('h3', ['size' => 12], 'h');
$multicell->setStyleAssoc('h4', ['size' => 11, 'style' => 'B'], 'h');

Text Formatting

No formatting

The default PDF formatting is used in this case(font, font-size and color)

// no formatting - the default

//t pdf font, font-size, colors are used
$s = "This is a simple text";
$multicell->multiCell(0, 5, $s);

Simple formatting

// simple formatting
$s = "<p>This is a paragraph</p>";
$multicell->multiCell(0, 5, $s);

Nested tags

In case of nested tags, the styles are NOT inherited

// nested tags
$s = "<p>This is <b>BOLD</b> text, this is <i>ITALIC</i></p>";
$multicell->multiCell(0, 5, $s);

Subscripts and superscripts

Subscript and superscripts can be adjusted with the y attribute. See example:

$s = "<p>The following is <s y='-1'>Subscript</s> and <s y='1'>Superscript</s></p>";



Text strikethrough can be defined using the strike attribute in any tag:

  • <p strike=''>... - default strikethrough line width - <p strike='0.6'>... - strikethrough line width: 0.6
$s = "<p>The following is <n strike=''>Text Strikethrough</n> and <bi strike='.5'>Text Strikethrough bolder line</bi></p>";
$multicell->multiCell(0, 5, $s);


You can create links by using the href attribute in a tag.

$s = "<p>Created by <h1 href=''>Interpid Office</h1>
<h1 href=''></h1></p>";
$multicell->multiCell(0, 5, $s);


Paragraphs can be created by using the size attribute and the ~~~ reserved pattern for paragraphs. See the following

$s = "<size size='50' >Paragraph Example:~~~</size><font> - Paragraph 1</font>
<p size='60' > ~~~</p><font> - Paragraph 2</font>
<p size='60' > ~~~</p> - Paragraph 2
<p size='70' >Sample text~~~</p><p> - Paragraph 3</p>
<p size='50' >Sample text~~~</p> - Paragraph 1
<p size='60' > ~~~</p><h4> - Paragraph 2</h4>";
$multicell->multiCell(0, 5, $s);

Tag Attributes


The href attribute will provide you a link in the pdf document.

<h1 href="">Visit our website</h1>


By default, the width of a tag is calculated. Use width to set a fixed width for your tag. No checks are being done
for text-overflow!


align is to be used only in combination width width, to specify where the text should be aligned.

Valid values are: left|center|right|L|C|R

Example with width and align

<p width="100" align="left"> Align Left </p>
<p width="100" align="center"> Align Center </p>
<p width="100" align="right"> Align Right </p>


size is used in case of paragraphs. This value will become deprecated in future versions and width is to be
preferred instead.


nowrap is used if you the text in a paragraph to break or be separated on a new line

For example, you want the price to always be written on the same line:

$s = "The price is <b nowrap='1'>USD 5.344,23</b>";
$multicell->multiCell(50, 5, $s);


Height Limitations

Max Lines

Limit the number of lines that will be in the multicell

//set a limit to the maximum number of lines 
$multicell->multiCell(0, 5, "...Some text...");

Max Height

Limit the height that a multicell can have

//set a limit to the maximum number of lines 
$multicell->multiCell(0, 5, "...Some text...");

If height limits are hit, the following text is cut-off from the multicell.

Text shrinking

Text and line height will shrink in order to fit into a specific maxHeight or maxLines
If the text doesn't fit the font-size will be decreased with 1 and the line-height with 0.5 units until the text


There is a possibility that the shrinking fails if the input and shrinking settings are invalid.

For example: you set maxLines to 5 and your input text has 10 EOLs in it $multicell->maxLines(5)

Limit the number of lines that will be in the multicell

$multicell->multiCell(0, 5, "...Some text...");

Limit the height that a multicell can have

$multicell->multiCell(0, 5, "...Some text...");
// shrink, max-height and all cells 
$multicell->multiCell(0, 5, "...Some text...");


Change shrinking units

$multicell->multiCell(0, 5, "...Some text...");


Apply features to all cells and reset

Features like: maxHeight, maxLines, shrinkToFit, shrinkLineHeightStep, shrinkFontStep are applied to the next
cell only.

In order to apply these features to all following cells, use $multicell->applyAll();
In order to reset these features use $multicell->reset();