tFPDF::MultiCell PHP Метод

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

public MultiCell ( $w, $h, $txt, $border, $align = 'J', $fill = false )
    function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false)
    {
        // Output text with automatic or explicit line breaks
        $cw =& $this->CurrentFont['cw'];
        if ($w == 0) {
            $w = $this->w - $this->rMargin - $this->x;
        }
        $wmax = $w - 2 * $this->cMargin;
        $s = str_replace("\r", '', $txt);
        if ($this->unifontSubset) {
            $nb = mb_strlen($s, 'utf-8');
            while ($nb > 0 && mb_substr($s, $nb - 1, 1, 'utf-8') == "\n") {
                $nb--;
            }
        } else {
            $nb = strlen($s);
            if ($nb > 0 && $s[$nb - 1] == "\n") {
                $nb--;
            }
        }
        $b = 0;
        if ($border) {
            if ($border == 1) {
                $border = 'LTRB';
                $b = 'LRT';
                $b2 = 'LR';
            } else {
                $b2 = '';
                if (strpos($border, 'L') !== false) {
                    $b2 .= 'L';
                }
                if (strpos($border, 'R') !== false) {
                    $b2 .= 'R';
                }
                $b = strpos($border, 'T') !== false ? $b2 . 'T' : $b2;
            }
        }
        $sep = -1;
        $i = 0;
        $j = 0;
        $l = 0;
        $ns = 0;
        $nl = 1;
        while ($i < $nb) {
            // Get next character
            if ($this->unifontSubset) {
                $c = mb_substr($s, $i, 1, 'UTF-8');
            } else {
                $c = $s[$i];
            }
            if ($c == "\n") {
                // Explicit line break
                if ($this->ws > 0) {
                    $this->ws = 0;
                    $this->_out('0 Tw');
                }
                if ($this->unifontSubset) {
                    $this->Cell($w, $h, mb_substr($s, $j, $i - $j, 'UTF-8'), $b, 2, $align, $fill);
                } else {
                    $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
                }
                $i++;
                $sep = -1;
                $j = $i;
                $l = 0;
                $ns = 0;
                $nl++;
                if ($border && $nl == 2) {
                    $b = $b2;
                }
                continue;
            }
            if ($c == ' ') {
                $sep = $i;
                $ls = $l;
                $ns++;
            }
            if ($this->unifontSubset) {
                $l += $this->GetStringWidth($c);
            } else {
                $l += $cw[$c] * $this->FontSize / 1000;
            }
            if ($l > $wmax) {
                // Automatic line break
                if ($sep == -1) {
                    if ($i == $j) {
                        $i++;
                    }
                    if ($this->ws > 0) {
                        $this->ws = 0;
                        $this->_out('0 Tw');
                    }
                    if ($this->unifontSubset) {
                        $this->Cell($w, $h, mb_substr($s, $j, $i - $j, 'UTF-8'), $b, 2, $align, $fill);
                    } else {
                        $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
                    }
                } else {
                    if ($align == 'J') {
                        $this->ws = $ns > 1 ? ($wmax - $ls) / ($ns - 1) : 0;
                        $this->_out(sprintf('%.3F Tw', $this->ws * $this->k));
                    }
                    if ($this->unifontSubset) {
                        $this->Cell($w, $h, mb_substr($s, $j, $sep - $j, 'UTF-8'), $b, 2, $align, $fill);
                    } else {
                        $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill);
                    }
                    $i = $sep + 1;
                }
                $sep = -1;
                $j = $i;
                $l = 0;
                $ns = 0;
                $nl++;
                if ($border && $nl == 2) {
                    $b = $b2;
                }
            } else {
                $i++;
            }
        }
        // Last chunk
        if ($this->ws > 0) {
            $this->ws = 0;
            $this->_out('0 Tw');
        }
        if ($border && strpos($border, 'B') !== false) {
            $b .= 'B';
        }
        if ($this->unifontSubset) {
            $this->Cell($w, $h, mb_substr($s, $j, $i - $j, 'UTF-8'), $b, 2, $align, $fill);
        } else {
            $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);
        }
        $this->x = $this->lMargin;
    }

Usage Example

Пример #1
0
 public function create_pdf_oferte($title, $desc, $products)
 {
     $CI =& get_instance();
     $CI->load->helper('tfpdf');
     $CI->load->helper('data_helper');
     $CI->load->model('mysql');
     $CI->load->library('session');
     $pdf = new tFPDF('P', 'mm', 'A4');
     $pdf->AddPage();
     //titlu oferta
     // Add a Unicode font (uses UTF-8)
     $pdf->AddFont('DejaVu', '', 'DejaVuSansCondensed.ttf', true);
     $pdf->SetFont('DejaVu', '', 14);
     //$pdf->AddFont('TimesNewRomanPSMT','','times.php');
     //$pdf->SetFont('TimesNewRomanPSMT','');
     // $pdf->AddFont('TimesNewRomanPSMT','','times.php');
     // $pdf->SetFont('TimesNewRomanPSMT','',12);
     // $pdf->SetFont('Arial','B',16);
     $pdf->Cell(0, 0, $title);
     $pdf->Ln(5);
     // rind nou
     //descrire oferta
     $pdf->MultiCell(0, 5, $desc);
     $pdf->Ln(5);
     $i = 0;
     foreach ($products as $item) {
         $i++;
         //info suprafata
         $pdf->SetFont('Arial', 'B', 11);
         $pdf->Cell(0, 0, 'Info Suprafata publicitara Nr' . $i);
         $pdf->Ln(8);
         // rind nou
         //adresa link
         $pdf->SetTextColor(0, 136, 204);
         $pdf->SetFont('Arial', 'B', 11);
         $pdf->Cell(0, 0, $item['adresa'], '', '', '', false, 'http://www.marplo.net/jocuri');
         $pdf->Ln(5);
         // rind nou
         //numar de inventar
         $pdf->SetFont('Arial', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->Cell(0, 0, 'Numarul de inventar: #' . $item['inv']);
         $pdf->Ln(8);
         // rind nou
         //pret
         $pdf->SetFont('Arial', 'B', 12);
         $pdf->Cell(0, 0, 'Pret: ' . $item['price'] . ' euro');
         $pdf->Ln(10);
         // rind nou
         //dimensiunea
         $pdf->SetFont('Arial', 'B', 8);
         $pdf->Cell(0, 0, 'Dimensiuni: ' . $item['format']);
         $pdf->Ln(5);
         // rind nou
         //foto
         if ($item['image'] and file_exists($_SERVER['DOCUMENT_ROOT'] . $item['image'])) {
             $pdf->Cell(0, 0, 'Foto');
             $pdf->Ln(2);
             // rind nou
             $pdf->Image('.' . $item['image']);
             $pdf->Ln(20);
             // rind nou
         } else {
             $pdf->Ln(20);
         }
         // rind nou
     }
     //footer
     $pdf->SetFont('Arial', 'B', 6);
     $pdf->Cell(0, 0, 'Trendseter Copyright 2011', '', '', 'C');
     $pdf->Ln(5);
     // rind nou
     // Tilte pdf
     $page_title = 'Oferta_' . date('d_m_Y_H:i:s');
     $pdf->output('./uploads/offerts/' . $page_title . '.pdf', 'F');
     $CI->mysql->insert('offerts_pdf', array('uid' => $CI->session->userdata('uid'), 'pdf' => './uploads/offerts/' . $page_title . '.pdf'));
     return './uploads/offerts/' . $page_title . '.pdf';
 }
All Usage Examples Of tFPDF::MultiCell