TCPDF Advanced Multicell

This TCPDF addon class allows creation of a “Advanced Multicell” which uses as input a TAG based formatted string instead of a simple string. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters and many other features.

The function is pretty similar to the Multicell function in the tcpdf base class with some extended parameters.

Features:

  • TCPDF class needs minimal extension, the pdf object will be passed as a parameter to the class constructor
  • Text can be aligned, centered or justified
  • Different Font, Sizes, Styles, Colors can be used
  • The cell block can be framed and the background painted
  • Links can be used in any tag
  • TAB spaces (t) can be used
  • Variable Y relative positions can be used for Subscript or Superscript
  • Cell padding (left, right, top, bottom)
  • Controlled Tag Sizes can be used

Requirements:

  • PHP version > 5.3.0

Resources:

Example:

Source code:


<?php /** * Pdf Advanced Multicell - Example * Copyright (c), Interpid, http://www.interpid.eu */ require_once __DIR__ . '/../autoload.php'; use Interpid\PdfLib\Multicell; use Interpid\PdfExamples\PdfFactory; $factory = new PdfFactory(); //get the PDF object $pdf = PdfFactory::newPdf('multicell'); // Create the Advanced Multicell Object and inject the PDF object $multicell = new Multicell($pdf); // Set the styles for the advanced multicell // Notice: 'base' style is always inherited $multicell->setStyle('base', 11, '', '130,0,30', 'helvetica'); $multicell->setStyle('p', null); $multicell->setStyle('b', null, 'B'); $multicell->setStyle('i', null, 'I', '80,80,260'); $multicell->setStyle('u', null, 'U', '80,80,260'); $multicell->setStyle('h1', 14, 'B', '203,0,48'); $multicell->setStyle('h3', 12, 'B', '203,0,48'); $multicell->setStyle('h4', 11, 'BI', '0,151,200'); $multicell->setStyle('hh', 11, 'B', '255,189,12'); $multicell->setStyle('ss', 7, '', '203,0,48'); $multicell->setStyle('font', 10, '', '0,0,255'); $multicell->setStyle('style', 10, 'BI', '0,0,220'); $multicell->setStyle('size', 12, 'BI', '0,0,120'); $multicell->setStyle('color', 12, 'BI', '0,255,255'); //set the style for utf8 texts, use 'dejavusans' fonts $multicell->setStyle('u8', null, '', [0, 45, 179], 'dejavusans'); $multicell->setStyle('u8b', null, 'B', null, null, 'u8'); $pdf->Ln(10); //line break // create the advanced multicell $title = file_get_contents(PDF_APPLICATION_PATH . '/content/multicell-title.txt'); $multicell->multiCell(0, 5, $title, 1, 'J', 1, 3, 3, 3, 3); $pdf->Ln(10); //line break //read TAG formatted text from file $txt = file_get_contents(PDF_APPLICATION_PATH . '/content/multicell.txt'); $multicell->multiCell(0, 5, $txt, 1, 'J', 1, 3, 3, 3, 3); // output the pdf $pdf->Output();
Code language: PHP (php)

content/multicell-title.txt:

<h1>TCPDF Advanced Multicell</h1>
Code language: HTML, XML (xml)

content/multicell.txt:

<h3>Description:</h3> <p> This <b>TCPDF addon</b> allows creation of an <b>Advanced Multicell</b> which uses as input a <b>TAG based formatted string</b> instead of a simple string. The use of tags allows to change the font, the style (<b>bold</b>, <i>italic</i>, <u>underline</u>), the size, and the color of characters and many other features. The call of the function is pretty similar to the Multicell function in the TCPDF base class with some extended parameters. UTF8 characters are supported: <u8>¥ € ₡ ₢ ₤ ₥ ₦ ₧ ₩ ₪ ₫ ₭ ₮ ₯ ₹ Σ ε φ ά η</u8> <h3>Features:</h3> - Text can be <hh>aligned</hh>, <hh>centered</hh> or <hh>justified</hh> - Different <font>Font</font>, <size>Sizes</size>, <style>Styles</style>, <color>Colors</color> can be used - <u>Underline</u>, <s strike=''>Strikethrough</s>, <size strike='0.8'>Strikethrough line bold</size> - The cell block can be framed and the background painted - <style href='www.tcpdf.org'>Links</style> can be used in any tag - <h4>TAB</h4> spaces (<b>\t</b>) can be used - Variable Y relative positions can be used for <ss y='-0.8'>Subscript</ss> or <ss y='1.1'>Superscript</ss> - Cell padding (left, right, top, bottom) - Controlled Tag Sizes can be used</p> <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> <h3>Observations:</h3><p> - If no <h4><TAG></h4> is specified then the TCPDF current settings(font, style, size, color) are used - The <h4>ttags</h4> tag name is reserved for the TAB SPACES </p>
Code language: HTML, XML (xml)
View Result PDF