2016-08-06 1 views
1

FPDF를 사용하여 FPDF를 생성하고 각 페이지를 다른 페이지에 출력하고 싶습니다. 어떻게이 모든 내 기록을 달성 할 수있는 데이터베이스에서 파일에 쓰기 및 다음 파일에서 읽을 수 있습니다. 여기에 내가 그것을 시도했지만, 당신은 나를 위해 어쨌든 시도 할 수 있습니다 작동하지 않는 것 같다FPDF를 사용하여 fpdf (단일 파일)를 생성하는 방법

<?php 
require 'include/function.php'; 

error_reporting(1); 
$filename = "other_file/uploadsum .txt"; 
$File = $filename; 
$Handle = fopen($File, 'w'); 
$sn = 1; 
$name = ''; 
$sn = 1; 
$fetch = mysql_query("SELECT * FROM lga ORDER BY lga_id ASC"); 

while ($row = mysql_fetch_row($fetch)) 
    { 
    $center_num = array(
     $row[1] 
    ); 
    $sch_name = $row[2]; 
    $total_forSubject1 = number_format($total_); 
    $name.= $sn++ . "* " . $sch_name . "* $total_forSubject1" . "* $uploaded" . "* $balance" . "\r\n"; 
    } 

fwrite($Handle, $name); 
fclose($Handle); 
class pdf extends FPDF 

    { 
    function Header() 
     { 
     $this->SetFont('Arial', 'B', 15); 
     $this->Cell(80); 
     $this->Ln(10); 
     $this->Ln(20); 
     } 

    function Footer() 
     { 
     $this->SetY(-15); 
     $this->SetFont('Arial', 'I', 9); 
     $this->Cell(0, 10, 'Page ' . $this->PageNo() , 0, 0, 'C'); 
     } 

    function LoadData($file) 
     { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
      { 
      $data[] = explode('*', trim($line)); 
      } 

     return $data; 
     } 

    function CTable($header, $data) 
     { 
     $this->SetFillColor(255); 
     $this->SetTextColor(0); 
     $this->SetDrawColor(0, 0, 0); 
     $this->SetLineWidth(.3); 
     $this->SetFont('Arial', 'B', 9); 
     $w = array(
      10, 
      120 
     ); 
     for ($i = 0; $i < count($header); $i++) $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true); 
     $this->Ln(); 
     $this->SetFillColor(224, 235, 255); 
     $this->SetTextColor(0); 
     $this->SetFont(''); 

     // Data 

     $fill = false; 
     $a = 1; 
     foreach($data as $row) 
      { 
      $b = $a++; 
      $this->Cell($w[0], 6, $row[0], 1, 0, 'C'); 
      $this->Cell($w[1], 6, $row[1], 1, 'C'); 
      $this->Ln(); 
      $fill = !$fill; 
      } 

     $this->Cell(array_sum($w) , 0, '', 'T'); 
     } 
    } 

$pdf = new PDF(); 
$pdf->SetAutoPageBreak(true, 10); 
$header = array(
    'S/N', 
    'Local Govt Area.' 
); 
$data = $pdf->LoadData($filename); 
$pdf->SetFont('Arial', '', 12); 
$pdf->AddPage(); 
$pdf->CTable($header, $data); 
$pdf->Output(); 
?> 

답변

0
<?php 
require 'include/function.php'; 

error_reporting(1); 
$filename = "other_file/uploadsum .txt"; 
$File = $filename; 
$Handle = fopen($File, 'w'); 
$sn = 1; 
$name = ''; 
$sn = 1; 
$fetch = mysql_query("SELECT * FROM lga ORDER BY lga_id ASC"); 

while ($row = mysql_fetch_row($fetch)) 
    { 
    $center_num = array(
     $row[1] 
    ); 
    $sch_name = $row[2]; 
    $total_forSubject1 = number_format($total_); 
    $name.= $sn++ . "* " . $sch_name . "* $total_forSubject1" . "* $uploaded" . "* $balance" . "\r\n"; 
    } 

fwrite($Handle, $name); 
fclose($Handle); 
class pdf extends FPDF 

    { 
    function Header() 
     { 
     $this->SetFont('Arial', 'B', 15); 
     $this->Cell(80); 
     $this->Ln(10); 
     $this->Ln(20); 
     } 

    function Footer() 
     { 
     $this->SetY(-15); 
     $this->SetFont('Arial', 'I', 9); 
     $this->Cell(0, 10, 'Page ' . $this->PageNo() , 0, 0, 'C'); 
     } 

    function LoadData($file) 
     { 
     $lines = file($file); 
     $data = array(); 
     foreach($lines as $line) 
      { 
      $data[] = explode('*', trim($line)); 
      } 

     return $data; 
     } 

    function CTable($header, $data) 
     { 
     $this->SetFillColor(255); 
     $this->SetTextColor(0); 
     $this->SetDrawColor(0, 0, 0); 
     $this->SetLineWidth(.3); 
     $this->SetFont('Arial', 'B', 9); 
     $w = array(
      10, 
      120 
     ); 
     for ($i = 0; $i < count($header); $i++) $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true); 
     $this->Ln(); 
     $this->SetFillColor(224, 235, 255); 
     $this->SetTextColor(0); 
     $this->SetFont(''); 

     // Data 

     $fill = false; 
     $a = 1; 
     foreach($data as $row) 
      { 
      $b = $a++; 
      $this->Cell($w[0], 6, $row[0], 1, 0, 'C'); 
      $this->Cell($w[1], 6, $row[1], 1, 'C'); 
      $this->Ln(); 
      $fill = !$fill; 
      } 

     $this->Cell(array_sum($w) , 0, '', 'T'); 
     } 
    } 


$textfile = fopen($File, 'w'); 
// Foreach new line in the text file. 
$pdf = new PDF(); 
$pdf->SetAutoPageBreak(true, 10); 
$header = array(
    'S/N', 
    'Local Govt Area.' 
); 
$pdf->SetFont('Arial', '', 12); 

foreach(preg_split("/((\r?\n)|(\r\n?))/", $textfile) as $line){ 

    $pdf->AddPage(); 
    $pdf->CTable($header, $line); 

} 

$pdf->Output(); 

?> 
+0

내 스크립트입니다? –

관련 문제