Tags for cells and bold

Add-On Tags for cells and bold

Informations

Author:Marcio Sfalsin
License: FPDF

Description

This script allows to print text with the following tags in it:

[text]: puts the text inside a framed cell
<text>: renders the text in bold

Source

<?php
require('fpdf.php');

class PDF extends FPDF
{

function WriteText($text)
{
    $intPosIni = 0;
    $intPosFim = 0;
    if (strpos($text, '<')!==false && strpos($text, '[')!==false)
    {
        if (strpos($text, '<')<strpos($text, '['))
        {
            $this->Write(5, substr($text, 0, strpos($text, '<')));
            $intPosIni = strpos($text, '<');
            $intPosFim = strpos($text, '>');
            $this->SetFont('', 'B');
            $this->Write(5, substr($text, $intPosIni+1, $intPosFim-$intPosIni-1));
            $this->SetFont('', '');
            $this->WriteText(substr($text, $intPosFim+1, strlen($text)));
        }
        else
        {
            $this->Write(5, substr($text, 0, strpos($text, '[')));
            $intPosIni = strpos($text, '[');
            $intPosFim = strpos($text, ']');
            $w=$this->GetStringWidth('a')*($intPosFim-$intPosIni-1);
            $this->Cell($w, $this->FontSize+0.75, substr($text, $intPosIni+1, $intPosFim-$intPosIni-1), 1, 0, '');
            $this->WriteText(substr($text, $intPosFim+1, strlen($text)));
        }
    }
    else
    {
        if (strpos($text, '<')!==false)
        {
            $this->Write(5, substr($text, 0, strpos($text, '<')));
            $intPosIni = strpos($text, '<');
            $intPosFim = strpos($text, '>');
            $this->SetFont('', 'B');
            $this->WriteText(substr($text, $intPosIni+1, $intPosFim-$intPosIni-1));
            $this->SetFont('', '');
            $this->WriteText(substr($text, $intPosFim+1, strlen($text)));
        }
        elseif (strpos($text, '[')!==false)
        {
            $this->Write(5, substr($text, 0, strpos($text, '[')));
            $intPosIni = strpos($text, '[');
            $intPosFim = strpos($text, ']');
            $w=$this->GetStringWidth('a')*($intPosFim-$intPosIni-1);
            $this->Cell($w, $this->FontSize+0.75, substr($text, $intPosIni+1, $intPosFim-$intPosIni-1), 1, 0, '');
            $this->WriteText(substr($text, $intPosFim+1, strlen($text)));
        }
        else
        {
            $this->Write(5, $text);
        }

    }
}

}
?>

Example

<?php
require('cells_bold.php');

$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);
$text  = "Let's show... \n\n";
$text .= " [This is a cell][and another cell]\n\n";
$text .= "<This is a bold sentence> and another non bold sentence.";
$pdf->WriteText($text);
$pdf->Output();
?>
View the result here.

Download

ZIP | TGZ
An Error Occurred:Internal Server Error

Oops! An Error Occurred

The server returned a "500Internal Server Error".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.