2009-06-25 8 views
2

fpdfライブラリを使用してpdfでテーブル構造を作成する際に問題があります。ペリチュラルセルのデータが長い場合、セルデータは他のセルデータと重複します。 したがって、テーブル全体のデータが乱れています。 pdfのデータは正しく表示されません。fpdfを使ってデータをPDFで作成する

いずれか1つは、セル内のデータに従ってすべてのセルをpdf autoで調整するのに役立ちます。

<?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/ –

関連する問題