Fpdf Multicell (Advanced)

Description:

This FPDF 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 call of the function is pretty similar to the Multicell function in the fpdf base class with some extended parameters.

Features:

  • Fpdf class doesn’t need to be extended anymore, the fpdf 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

Resources:

Example:

Source code:

<?php
/**
 * Pdf Advanced Multicell - Example
 * Copyright (c) 2014, Andrei Bintintan, http://www.interpid.eu
 */

// include the pdf factory
require_once( "pdfFactory.php" );

// Include the Advanced Multicell Class
require_once( "classes/pdfmulticell.php" );

/**
 * Include my Custom PDF class This is required only to overwrite the header
 */
require_once( "mypdf-multicell.php" );

$factory = new pdfFactory();

// create new PDF document
$oPdf = new myPdfMulticell();
$factory->initPdfObject$oPdf );

/**
 * Create the Advanced Multicell Object and pass the PDF object as a parameter to the constructor
 */
$oMulticell = new PdfMulticell$oPdf );

/**
 * Set the styles for the advanced multicell
 */
$oMulticell->SetStyle"p"$oPdf->getDefaultFontName(), ""11"130,0,30" );
$oMulticell->SetStyle"b"$oPdf->getDefaultFontName(), "B"11"130,0,30" );
$oMulticell->setStyle"i"$oPdf->getDefaultFontName(), "I"11"80,80,260" );
$oMulticell->setStyle"u"$oPdf->getDefaultFontName(), "U"11"80,80,260" );
$oMulticell->SetStyle"h1"$oPdf->getDefaultFontName(), ""11"80,80,260" );
$oMulticell->SetStyle"h3"$oPdf->getDefaultFontName(), "B"12"203,0,48" );
$oMulticell->SetStyle"h4"$oPdf->getDefaultFontName(), "BI"11"0,151,200" );
$oMulticell->SetStyle"hh"$oPdf->getDefaultFontName(), "B"11"255,189,12" );
$oMulticell->SetStyle"ss"$oPdf->getDefaultFontName(), ""7"203,0,48" );
$oMulticell->SetStyle"font"$oPdf->getDefaultFontName(), ""10"0,0,255" );
$oMulticell->SetStyle"style"$oPdf->getDefaultFontName(), "BI"10"0,0,220" );
$oMulticell->SetStyle"size"$oPdf->getDefaultFontName(), "BI"12"0,0,120" );
$oMulticell->SetStyle"color"$oPdf->getDefaultFontName(), "BI"12"0,255,255" );

//read TAG formatted text from files
$sTxt1 file_get_contents__DIR__ '/content/createdby.txt' );
$sTxt2 file_get_contents__DIR__ '/content/multicell.txt' );

//create an advanced multicell
$oMulticell->multiCell1505$sTxt11"L"1555);
$oPdf->Ln10 ); //new line

//create an advanced multicell
$oMulticell->multiCell05$sTxt21"J"1333);
$oPdf->Ln10 ); //new line

//send the pdf to the browser
$oPdf->Output();

content/createdby.txt:

<p>Created by <h1 href='mailto:andy@interpid.eu'>Andrei Bintintan, </h1><h1 href='www.interpid.eu'>www.interpid.eu</h1></p>

content/multicell.txt:

<p><h3>Description:</h3>

    This <b>FPDF 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 FPDF base class with some extended parameters.

<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 
    - The cell block can be framed and the background painted
    - <style href='www.fpdf.org'>Links</style> can be used in any tag
    - <h4>TAB</h4> spaces (<b>\    </b>) can be used
    - Variable Y relative positions can be used for <ss ypos='-0.8'>Subscript</ss> or <ss ypos='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 FPDF current settings(font, style, size, color) are used
    - The <h4>ttags</h4> tag name is reserved for the TAB SPACES
</p>

 

View the result pdf

rvn_polyon_theme rvn_polyon_theme_tv_1_2 rvn_polyon_theme_fwv_2_0