2012-10-25 5 views
4

pdf 파일 생성시 텍스트 맞춤 (상단 및 하단)이 필요합니다.pdf 맞춤형 상단 및 하단

나는이 라인을 사용하고 있습니다 :

$pdf->Cell(0,0,"Submitted To:$subto",0,0,'alignment area'); 

alignment area: L,R,C 

답변

2

나는 당신이 필요로 할 것으로 보인다 플러그인을 발견했다. 여기 있습니다 : http://fpdf.de/downloads/addons/52/

플러그인은 함수 매개 변수에 의해 정의 된 사각형 내에서 (수평 및 수직 모두) 텍스트를 정렬 할 수 있도록하는 기능

drawTextBox(string strText, float w, float h [, string align [, string valign [, int border]]]) 

을 제공합니다.

0

TCell을 사용하여 아래 텍스트 줄에 텍스트와 BCell을 정렬합니다.

이 방법은 나에게 효과적입니다. 도움이되기를 바랍니다.

class TBFpdf extends FPDF{ 

    private $padding_top = 1, $padding_bottom = 1, $line_space = 1, $paragraph_space = 1; 

    private function topBottom($type, array $args){ 
     if(!isset($args[0], $args[1], $args[2])) 
      throw new Exception("Parameter error!"); 

     $height = $args[1]; 
     $width = $args[0]; 

     $y_old = $this->GetY(); 
     $x_old = $this->GetX(); 

     if($type == "T"){ 
      $this->SetXY($x_old, $y_old + $this->padding_top); 
      $this->WriteLimit($width, $args[2], isset($args[5])? $args[5] : "L"); 
     }else{ 
      $text_height = $this->WriteLimit($width, $args[2], isset($args[5])? $args[5] : "L", true); 
      $this->SetXY($x_old, $y_old + $height - $text_height - $this->padding_bottom + 2); 
      $this->WriteLimit($width, $args[2], isset($args[5])? $args[5] : "L"); 
     } 
     //var_dump($height); 
     $this->SetXY($x_old, $y_old); 

     $args[2] = "";//empty the text already written 
     call_user_func_array([$this, 'Cell'], $args); 
    } 

    //the parameters are the same used by Cell 
    public function TCell(){ 
     call_user_func_array([$this, 'topBottom'], ['T', func_get_args()]); 
    } 

    //the parameters are the same used by Cell 
    public function BCell(){ 
     call_user_func_array([$this, 'topBottom'], ['B', func_get_args()]); 
    } 

    private function WriteLimit($width, $text, $align, $simulacao = false){ 
     $texts = explode(chr(13).chr(10), $text); 
     $height = 0; 

     for ($i = 0; $i < count($texts); $i++) { 

      $words = explode(' ', $texts[$i]); 
      $line = ""; 
      $qtd_words = count($words); 

      for ($j = 0; $j < $qtd_words; $j++) { 
       $new_word = $words[$j].' '; 
       $line .= $new_word; 

       if(($line_width = $this->getStringWidth($line)) > $width){ 
        $y_old = $this->GetY(); 
        $x_old = $this->GetX(); 
        $write_line = substr($line, 0, (-1)*strlen($new_word)); 
        $line = $words[$j].' '; 

        if(!$simulacao) 
         $this->AlignWrite($write_line, $width, $align); 

        $this->SetXY($x_old, $y_old + $this->FontSize + $this->line_space);//reset to the cell point 
        $height += $this->FontSize + $this->line_space; 
       } 

       if($j == $qtd_words-1){ 
        if(!$simulacao) 
         $this->AlignWrite($line, $width, $align); 
       } 
      } 

      $y_old = $this->GetY(); 
      $this->SetXY($x_old, $y_old + $this->FontSize + $this->paragraph_space);//reset to the cell point 
      $height += $this->FontSize + $this->paragraph_space; 

     } 

     return $height; 
    } 

    private function AlignWrite($write_line, $width, $align){ 
     $x_old = $this->GetX(); 

     if($align == "C" || $align == "R"){ 
      $width_write_line = $this->getStringWidth($write_line); 
      if($align == "C") 
       $this->SetX($x_old + ($width - $width_write_line)/2 - 0.75); 
      else 
       $this->SetX($x_old + $width - $width_write_line - 1.5); 
     } 

     $this->Write($this->FontSize, $write_line); 
    } 

    public function SetLineSpace($line_space){ 
     $this->line_space = (float)$line_space; 
     return $this; 
    } 

    public function SetParagraphSpace($paragraph_space){ 
     $this->paragraph_space = (float)$paragraph_space; 
     return $this; 
    } 

    public function SetPaddingTop($padding_top){ 
     $this->padding_top = (float)$padding_top; 
     return $this; 
    } 

    public function SetPaddingBottom($padding_bottom){ 
     $this->padding_bottom = $padding_bottom; 
     return $this; 
    } 

} 

사용 방법 :

$pdf = new TBFpdf(); 
$pdf->SetLineSpace(2)->SetPaddingTop(2)->SetParagraphSpace(3)->SetPaddingBottom(2); 
$pdf->AddPage(); 

$pdf->SetY(30); 
$pdf->SetX(15); 
$pdf->SetMargins(0, 0, 0); 
$pdf->SetFont('Arial','B', 20); 
$pdf->TCell(60, 210, utf8_decode(" Não se trata de um exercício intelectual, como aprender álgebra ou a análise de um balanço contábil. 
    O desenvolvimento da liderança servidora exige muita motivação, feedback e prática intensiva na vida cotidiana. O que vale é a motivação para mudar e crescer."), "LBTR", null, "L"); 
$pdf->SetFont('Courier','I', 15); 
$pdf->BCell(60, 210, utf8_decode("Não se trata de um exercício intelectual, como aprender álgebra ou a análise de um balanço contábil. 
O desenvolvimento da liderança servidora exige muita motivação, feedback e prática intensiva na vida cotidiana. O que vale é a motivação para mudar e crescer."), "LBTR", null, "C"); 
$pdf->SetFont('ZapfDingbats', null, 10); 
$pdf->TCell(60, 210, utf8_decode("Não se trata de um exercício intelectual, como aprender álgebra ou a análise de um balanço contábil. 
O desenvolvimento da liderança servidora exige muita motivação, feedback e prática intensiva na vida cotidiana. O que vale é a motivação para mudar e crescer."), "LBTR", null, "R"); 
$pdf->Output(); 
관련 문제