tFPDF::SetFont PHP Метод

SetFont() публичный Метод

public SetFont ( $family, $style = '', $size )
    function SetFont($family, $style = '', $size = 0)
    {
        // Select a font; size given in points
        if ($family == '') {
            $family = $this->FontFamily;
        } else {
            $family = strtolower($family);
        }
        $style = strtoupper($style);
        if (strpos($style, 'U') !== false) {
            $this->underline = true;
            $style = str_replace('U', '', $style);
        } else {
            $this->underline = false;
        }
        if ($style == 'IB') {
            $style = 'BI';
        }
        if ($size == 0) {
            $size = $this->FontSizePt;
        }
        // Test if font is already selected
        if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) {
            return;
        }
        // Test if font is already loaded
        $fontkey = $family . $style;
        if (!isset($this->fonts[$fontkey])) {
            // Test if one of the core fonts
            if ($family == 'arial') {
                $family = 'helvetica';
            }
            if (in_array($family, $this->CoreFonts)) {
                if ($family == 'symbol' || $family == 'zapfdingbats') {
                    $style = '';
                }
                $fontkey = $family . $style;
                if (!isset($this->fonts[$fontkey])) {
                    $this->AddFont($family, $style);
                }
            } else {
                $this->Error('Undefined font: ' . $family . ' ' . $style);
            }
        }
        // Select it
        $this->FontFamily = $family;
        $this->FontStyle = $style;
        $this->FontSizePt = $size;
        $this->FontSize = $size / $this->k;
        $this->CurrentFont =& $this->fonts[$fontkey];
        if ($this->fonts[$fontkey]['type'] == 'TTF') {
            $this->unifontSubset = true;
        } else {
            $this->unifontSubset = false;
        }
        if ($this->page > 0) {
            $this->_out(sprintf('BT /F%d %.2F Tf ET', $this->CurrentFont['i'], $this->FontSizePt));
        }
    }

Usage Example

Пример #1
1
 function exportarPdf($param)
 {
     /* Abre um arquivo na pasta padrão do projeto, com o nome "resultados.pdf"      */
     $destino = dirname(__FILE__) . "/../../archives/resultados.pdf";
     /* Novo arquivo PDF.                                                            */
     $pdf = new tFPDF('P', 'mm', 'A4');
     /* Nova página em formato de retrato, e define tamanho das tabelas.				*/
     $pdf->AddPage('L');
     $pdf->SetWidths(array(52, 40, 20, 23, 27, 27, 30, 30, 28));
     /* Cabeçalho do PDF, que só vai na primeira página, devidamente formatado.      */
     $pdf->SetFont('Times', 'b', 24);
     $pdf->Cell(40, 10, 'ProDown');
     $pdf->SetTextColor(128, 128, 128);
     $pdf->SetFont('Times', '', 16);
     $pdf->Cell(0, 10, utf8_decode('Sistema de Gestão de Informações'));
     /* Prepara a formatação das tabelas                                             */
     $pdf->SetTextColor(0, 0, 0);
     $pdf->ln();
     $pdf->ln();
     $pdf = $this->geraCabecalho($pdf);
     /* Coloca os resultados obtidos relacionados aos quintis.                       */
     if (is_array($param)) {
         $i = 0;
         foreach ($param as $teste) {
             $pdf->Row(array(utf8_decode($teste['nome']), utf8_decode($teste['turma']), $teste['dt_ocorrencia'], $teste['abdominal'], $teste['agilidade'], $teste['flexibilidade'], $teste['forca_explosiva_inferir'], $teste['forca_explosiva_superior'], $teste['velocidade']));
         }
     }
     /* Quebra de linha com inserção da data e hora em que o PDF foi gerado         */
     $pdf->ln();
     $pdf->Cell(0, 10, utf8_decode(date("d/m/Y - H:i:s")));
     /* Retorna o PDF pra controller, e ela que se vire.                            */
     $pdf->output($destino);
     return ARQUIVO . "resultados.pdf";
 }
All Usage Examples Of tFPDF::SetFont