tFPDF::Cell PHP Метод

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

public Cell ( $w, $h, $txt = '', $border, $ln, $align = '', $fill = false, $link = '' )
    function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = false, $link = '')
    {
        // Output a cell
        $k = $this->k;
        if ($this->y + $h > $this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak()) {
            // Automatic page break
            $x = $this->x;
            $ws = $this->ws;
            if ($ws > 0) {
                $this->ws = 0;
                $this->_out('0 Tw');
            }
            $this->AddPage($this->CurOrientation, $this->CurPageSize);
            $this->x = $x;
            if ($ws > 0) {
                $this->ws = $ws;
                $this->_out(sprintf('%.3F Tw', $ws * $k));
            }
        }
        if ($w == 0) {
            $w = $this->w - $this->rMargin - $this->x;
        }
        $s = '';
        if ($fill || $border == 1) {
            if ($fill) {
                $op = $border == 1 ? 'B' : 'f';
            } else {
                $op = 'S';
            }
            $s = sprintf('%.2F %.2F %.2F %.2F re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op);
        }
        if (is_string($border)) {
            $x = $this->x;
            $y = $this->y;
            if (strpos($border, 'L') !== false) {
                $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k);
            }
            if (strpos($border, 'T') !== false) {
                $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k);
            }
            if (strpos($border, 'R') !== false) {
                $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k);
            }
            if (strpos($border, 'B') !== false) {
                $s .= sprintf('%.2F %.2F m %.2F %.2F l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k);
            }
        }
        if ($txt !== '') {
            if ($align == 'R') {
                $dx = $w - $this->cMargin - $this->GetStringWidth($txt);
            } elseif ($align == 'C') {
                $dx = ($w - $this->GetStringWidth($txt)) / 2;
            } else {
                $dx = $this->cMargin;
            }
            if ($this->ColorFlag) {
                $s .= 'q ' . $this->TextColor . ' ';
            }
            // If multibyte, Tw has no effect - do word spacing using an adjustment before each space
            if ($this->ws && $this->unifontSubset) {
                foreach ($this->UTF8StringToArray($txt) as $uni) {
                    $this->CurrentFont['subset'][$uni] = $uni;
                }
                $space = $this->_escape($this->UTF8ToUTF16BE(' ', false));
                $s .= sprintf('BT 0 Tw %.2F %.2F Td [', ($this->x + $dx) * $k, ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k);
                $t = explode(' ', $txt);
                $numt = count($t);
                for ($i = 0; $i < $numt; $i++) {
                    $tx = $t[$i];
                    $tx = '(' . $this->_escape($this->UTF8ToUTF16BE($tx, false)) . ')';
                    $s .= sprintf('%s ', $tx);
                    if ($i + 1 < $numt) {
                        $adj = -($this->ws * $this->k) * 1000 / $this->FontSizePt;
                        $s .= sprintf('%d(%s) ', $adj, $space);
                    }
                }
                $s .= '] TJ';
                $s .= ' ET';
            } else {
                if ($this->unifontSubset) {
                    $txt2 = '(' . $this->_escape($this->UTF8ToUTF16BE($txt, false)) . ')';
                    foreach ($this->UTF8StringToArray($txt) as $uni) {
                        $this->CurrentFont['subset'][$uni] = $uni;
                    }
                } else {
                    $txt2 = '(' . str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))) . ')';
                }
                $s .= sprintf('BT %.2F %.2F Td %s Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k, $txt2);
            }
            if ($this->underline) {
                $s .= ' ' . $this->_dounderline($this->x + $dx, $this->y + 0.5 * $h + 0.3 * $this->FontSize, $txt);
            }
            if ($this->ColorFlag) {
                $s .= ' Q';
            }
            if ($link) {
                $this->Link($this->x + $dx, $this->y + 0.5 * $h - 0.5 * $this->FontSize, $this->GetStringWidth($txt), $this->FontSize, $link);
            }
        }
        if ($s) {
            $this->_out($s);
        }
        $this->lasth = $h;
        if ($ln > 0) {
            // Go to next line
            $this->y += $h;
            if ($ln == 1) {
                $this->x = $this->lMargin;
            }
        } else {
            $this->x += $w;
        }
    }

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::Cell