2009-06-25 5 views
2

fpdf 라이브러리를 사용하여 pdf에서 테이블 구조를 생성하는 데 문제가 있습니다. perticular 셀의 데이터에 긴 문자열이 있으면 셀 데이터가 다른 셀 데이터와 중첩됩니다. 그래서 전체 테이블 데이터가 무질서합니다. pdf의 데이터가 올바르게 보이지 않습니다.PDF에서 fpdf를 사용하여 랩핑 데이터로 테이블 생성

어느 것이 든 나를 PDF의 테이블을 만드는 데 도움주세요 자동 셀의 데이터에 따라 모든 셀을 조정합니다.

<?php 
if($_POST['cmbReportType'] == '1') 
{ 
$fromdate = date_format(date_create($_POST['txtFromDate']), 'd-M-y'); 
$import = ociparse($c, "SELECT 
          t2.membercardno, (t1.firstname||' '||t1.middlename||' '||t1.lastname) as fullname, 
          t3.description, 
          to_char(t2.startdate,'DD-MON-YY') startdate, 
          to_char(t2.expirydate,'DD-MON-YY') expirydate, 
          t2.ramount, 
          t1.address1, 
          t1.address2 
         FROM 
          useradmin t1, 
          userplan t2, 
          plan t3 
         WHERE 
          t1.memberid = t2.memberid 
         AND 
          t2.planid = t3.planid 
         AND 
          t1.branchid = 3 
         AND 
          t2.startdate >= '$fromdate' 
         ORDER BY t2.membercardno"); 


OCIExecute($import); 
$k=0; 
while(OCIFetch($import)) 
{ 
    $a[$k]['membercardno'] = ociresult($import,"MEMBERCARDNO"); 
    $a[$k]['fullname'] = ociresult($import,"FULLNAME"); 
    $a[$k]['description'] = ociresult($import,"DESCRIPTION"); 
    $a[$k]['startdate'] = ociresult($import, "STARTDATE"); 
    $a[$k]['expirydate'] = ociresult($import, "EXPIRYDATE"); 
    $a[$k]['ramount'] = ociresult($import, "RAMOUNT"); 
    $a[$k]['address1'] = ociresult($import, "ADDRESS1"); 
    $a[$k]['address2'] = ociresult($import, "ADDRESS2");  
    $k++; 
} 
$resultcount = count($a); 

elseif($_POST['rdbReportFormat'] == 'pdf') 
{ 
/***This report view in tabular format.****/ 
    $pdf=new FPDF(); 

$pdf->AddPage(); 
$reportdate = date('d-m-Y'); 
$filename = $reportdate.'_report.pdf'; 
$pdf->SetFillColor(255,0,0); 
$pdf->SetTextColor(255); 
$pdf->SetDrawColor(128,0,0); 
$pdf->SetLineWidth(.3); 
$pdf->SetFont('Arial', 'B', 6); 
// Header 
$header=array('Member Card No','Full Name','Description', 'Start Date', 'Expiry Date', 'ramount', 'Address1', 'Address2'); 
$w = array(25, 35, 35, 15, 18, 15, 30, 30); 
for($i=0;$i<count($header); $i++) 
    $pdf->Cell($w[$i],7, $header[$i], 1, 0, 'L', true); 

$pdf->Ln(); 

// Reset colour set for data 
$pdf->SetFillColor(224,235,255); 
$pdf->SetTextColor(0); 
$pdf->SetFont('courier','',7); 
$fill=false; 
for($i=0;$i<$resultcount;$i++) 
{ 
    $height =6; 
    $pdf->Cell($w[0], '$height', $a[$i]['membercardno'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[1], '$height', $a[$i]['fullname'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[2], '$height', $a[$i]['description'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[3], '$height', $a[$i]['startdate'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[4], '$height', $a[$i]['expirydate'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[5], '$height', $a[$i]['ramount'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[5], '$height', $a[$i]['address1'], '1', '0', 'L', $fill); 
    $pdf->Cell($w[5], '$height', $a[$i]['address2'], '1', '0', 'L', $fill); 
    $pdf->Ln(); 
    $fill = !$fill; 

} 
$pdf->Cell(array_sum($w),0,'','T'); 
$pdf->Output($filename, 'I'); 
} 
} 
?> 
+0

안녕하세요 - SO에 오신 것을 환영합니다! 샘플 코드를 게시 할 수 있다면 가장 도움이 될 것입니다. 그런 다음 그것을 보거나 조정할 수 있으며 잘못 될 수있는 점을 지적 할 수 있습니다. – poundifdef

+0

fpdf의 테이블에는 여러 가지 솔루션이 있습니다. 스크립트는 http://www.fpdf.org를 참조하십시오. 더 복잡한 해결책은 여기에서 찾으실 수 있습니다 : http://www.interpid.eu/fpdf-table –

답변

6

multicell()을 사용하여 문제 필드 (최대 길이를 예측할 수없는 설명)를 작성해보세요. 이렇게하면 여러 줄로 줄 바꿈됩니다.

각 다중 셀 필드에 대해 nbLines를 사용하여 다음 행 위치를 줄 바꿈하고 계산할지 확인해야합니다. 다음 셀의 시작을 설정하려면 setXY()를 수행해야합니다. 여기

는 nbLines (여기 : http://www.svn.churchtool.org/viewvc/trunk/fpdf/mc_table.php?revision=1&view=markup를)되어

function NbLines($w,$txt) { 
//Computes the number of lines a MultiCell of width w will take 
$cw=&$this->CurrentFont['cw']; 
if($w==0) 
    $w=$this->w-$this->rMargin-$this->x; 
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 
$s=str_replace("\r",'',$txt); 
$nb=strlen($s); 
if($nb>0 and $s[$nb-1]=="\n") 
    $nb--; 
$sep=-1; 
$i=0; 
$j=0; 
$l=0; 
$nl=1; 
while($i<$nb) 
{ 
    $c=$s[$i]; 
    if($c=="\n") 
    { 
     $i++; 
     $sep=-1; 
     $j=$i; 
     $l=0; 
     $nl++; 
     continue; 
    } 
    if($c==' ') 
     $sep=$i; 
    $l+=$cw[$c]; 
    if($l>$wmax) 
    { 
     if($sep==-1) 
     { 
      if($i==$j) 
       $i++; 
     } 
     else 
      $i=$sep+1; 
     $sep=-1; 
     $j=$i; 
     $l=0; 
     $nl++; 
    } 
    else 
     $i++; 
} 
return $nl; 
} 
+0

새로운 링크는 http://www.fpdf.de/downloads/addons/3/에서 찾을 수 있습니다. –