Skripty : Značky pro buňky a zvýraznění

Popis

Tento skript umožňuje tisk textu s následujícími záznamy v něm:

[text]: vloží text dovnitř orámované buňky
<text>: vykreslí text tučně

Zdrojový kód

<?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);
        }

    }
}

}

?>


Příklad

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

$pdf = new PDF();
$pdf->AddPage();

$pdf->SetFont('Arial','',12);
$text  = "Pojďme si to ukázat ... \n\n";
$text .= " [Toto je buňka][a jiná buňka]\n\n";

$text .= "<Toto je tučná věta> a jiná netučná věta.";
$pdf->WriteText($text);
$pdf->Output();

?>


Ukázka

fpdf-znacky-pro-bunky-a-zvyrazneni.pdf

Download

fpdf-znacky-pro-bunky-a-zvyrazneni.zip

Informace

Author: Marcio Sfalsin
License: FPDF