export pdf แต่เนื้อหามันทับกัน อยากให่ตัดขึ้นบรรทัดใหม่ แต่พอใช้ MultiCell แค่เฉพาะcolume เดียว ปัญหาคือมันทำให้ช่อง colum อื่นตกลงมาด้วย แก้อย่างไรค่ะ
?php
require('fpdf.php');
class PDF extends FPDF
{
function LoadData($file)
{
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
function BasicTable($header,$data)
{
$w=array(10,55,70,25,20,5);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
foreach ($data as $eachResult)
{
$this->Cell(10,6,$eachResult["department_id"],1);
$this->MultiCell(55,6,$eachResult["department_name"],1);
$this->MultiCell(70,6,$eachResult["section_name"],1);
$this->Cell(25,6,$eachResult["phone"],1);
$this->Cell(20,6,$eachResult["building_name"],1);
$this->Cell(5,6,$eachResult["floor"],1);
$this->Ln();
}
}
function ImprovedTable($header,$data)
{
$w=array(10,55,70,25,25,5);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
foreach ($data as $eachResult)
{
$this->Cell(55,6,$eachResult["department_name"],1);
$this->Cell(70,6,$eachResult["section_name"],1);
$this->Cell(25,6,$eachResult["phone"],1);
$this->Cell(25,6,$eachResult["building_name"],1);
$this->Cell(5,6,$eachResult["floor"],1);
$this->Ln();
}
$this->Cell(array_sum($w),0,'','T');
}
function FancyTable($header,$data)
{
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(10,55,70,25,25,5);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
}
}
$pdf=new PDF();
//Column titles
$header=array('รหัส','หน่วยงาน','แผนก','เบอร์โทร','อาคาร','ชั้น');
//Data loading
//*** Load MySQL Data ***//
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'test';
$objConnect = mysqli_connect($servername, $username, $password, $dbname)or die ("ติดต่อเครื่อง Database Server ไม่สำเร็จ");
mysqli_query($objConnect,"set names tis620");
$strSQL= "SELECT department.department_id, department.department_name, section.section_id, section.section_name,
section.phone, building.building_name,department.floor
FROM ((building
INNER JOIN department ON building.building_id = department.building_id)
INNER JOIN section ON department.department_id =section.department_id) ";
$objQuery = $objConnect->query($strSQL);
$resultData = array();
for ($i=0;$i<mysqli_num_rows($objQuery);$i++) {
$result = mysqli_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
// $pdf->SetFont('Arial','',8);
$pdf->AddFont('angsana','','angsa.php');
$pdf->AddFont('angsana','B','angsab.php');
$pdf->AddFont('angsana','I','angsai.php');
$pdf->AddFont('angsana','BI','angsaz.php');
$pdf->SetFont('angsana','',12);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
//*** Table 2 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);
//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>Tag : MySQL, PDF
Date :
2021-07-25 21:40:16
By :
namasikan
View :
804
Reply :
1
Code (PHP)
foreach(.....){
$pdf->WriteHtml( '<table><tr><td width="50">xxx</td><td width="70">yyy</td>......</tr></table>');
}
Date :
2021-07-26 12:34:06
By :
Chaidhanan
Load balance : Server 02