<?php
require('fpdf.php');
include("dbConfig.php");
$CUST_ID ="3000/001";
$result = mysql_query("SELECT * FROM com_profile WHERE CUST_ID = '$CUST_ID'");
while ($row = mysql_fetch_array($result)) {
$CUST_NAME = $row["CUST_NAME"];
$CUST_NAME2 = $row["CUST_NAME2"];
$CUST_TEL = $row["CUST_TEL"];
$CUST_FAX = $row["CUST_FAX"];
$CUST_EMAIL = $row["CUST_EMAIL"];
}
$CUST_NAME = htmlspecialchars_decode($CUST_NAME) ;
$CUST_NAME2 = htmlspecialchars_decode($CUST_NAME2);
$CUST_TEL = htmlspecialchars_decode($CUST_TEL);
$CUST_FAX = htmlspecialchars_decode($CUST_FAX);
$CUST_EMAIL = htmlspecialchars_decode($CUST_EMAIL);
/**
* header and footer for pdf
*/
class PDF extends FPDF
{
}
// Instantiation of inherited class
$pdf = new PDF('L', 'mm', 'A4');
$pdf -> AliasNbPages();
$pdf -> SetTitle("Point History");
$pdf -> AddPage();
$pdf -> SetFont('Times', 'U', 16);
$pdf -> Cell(5);
$pdf -> Cell(30,10,'Point Transactions:');
$pdf ->SetFont('Times', 'B', 12);
$pdf -> Ln(5);
$pdf -> Cell(10);
$pdf -> Cell(35,10, 'Company Code :');
$pdf ->SetFont('Times', '', 12);
$pdf -> Cell(30, 10, $CUST_ID);
$pdf -> Ln(5);
$pdf -> Cell(10);
$pdf ->SetFont('Times', 'B', 12);
$pdf -> Cell(35,10, 'Company Name :');
$pdf ->SetFont('Times', '', 12);
$pdf -> Cell(30, 10, $CUST_NAME);
$pdf ->Ln(5);
$pdf ->Cell(45);
$pdf -> Cell(30, 10, $CUST_NAME2);
$pdf -> Ln(5);
$pdf -> Cell(10);
$pdf ->SetFont('Times', 'B', 12);
$pdf -> Cell(35,10, 'Tel :');
$pdf ->SetFont('Times', '', 12);
$pdf -> Cell(30, 10, $CUST_TEL);
$pdf -> Ln(5);
$pdf -> Cell(10);
$pdf ->SetFont('Times', 'B', 12);
$pdf -> Cell(35,10, 'Fax :');
$pdf ->SetFont('Times', '', 12);
$pdf -> Cell(30, 10, $CUST_FAX);
$pdf -> Ln(5);
$pdf -> Cell(10);
$pdf -> SetFont('Times', 'B', 12);
$pdf -> Cell(35,10, 'Email :');
$pdf ->SetFont('Times', '', 12);
$pdf -> Cell(30, 10, $CUST_EMAIL);
$pdf -> Ln(15);
$pdf -> Cell(5);
$pdf -> SetFont('Times', 'B', 10);
$pdf -> SetDrawColor(50,50,100);
$pdf -> Cell(155,8,'SERVICE DESCRIPTION', 1,0,'',false);
$pdf -> Cell(20,8,'POINT(-)', 1,0,'',false);
$pdf -> Cell(20,8,'POINT(+)', 1,0,'',false);
$pdf -> Cell(20,8,'BALANCE', 1,0,'',false);
$pdf -> Cell(25,8,'DATE', 1,0,'',false);
$pdf -> Cell(25,8,'SERV. BY', 1,1,'',false);
$pdf -> SetFont('Times', '', 10);
// query to retrieve data from database
$result = mysql_query("SELECT * FROM point_histories WHERE CUST_ID = '$CUST_ID' ORDER BY CON_ID ASC");
$Y = 63;
while ($row = mysql_fetch_array($result)) {
$pdf -> SetXY(15, $Y);
$pdf -> MultiCell(155,8,$row['SERVICE_DESP'], 1,"L");
$H = $pdf -> GetY();
$height = $H - $Y;
$pdf -> SetXY(170, $Y);
$pdf -> Cell(20,$height,$row['P_DEDUCTED'], 1,"L");
$pdf -> SetXY(190, $Y);
$pdf -> Cell(20,$height,$row['P_ADDED'], 1,"L");
$pdf -> SetXY(210, $Y);
$pdf -> Cell(20,$height,$row['P_BALANCES'], 1,"L");
$pdf -> SetXY(230, $Y);
$pdf -> Cell(25,$height,$row['MODIFIED_DATE'], 1,"L");
$pdf -> SetXY(255, $Y);
$pdf -> Cell(25,$height,$row['TC_SUPPORT'], 1, "L");
$Y = $H;
}
$pdf -> Output();
?>
我试图生成从MySQL表加载数据的fpdf表,当内容可以放在一个页面内时,表就可以了。但是当内容需要扩展到第二页时,表格列迷失方向就像附图中所示。我知道它与y轴有关,但我不知道如何解决这个问题,有人可以帮忙吗?
答案 0 :(得分:0)
由于您使用了AutoPageBreak
,因此MultiCell
存在问题,请使用$pdf -> SetAutoPageBreak( false );
将其关闭,然后在靠近页面底部并{{1}时手动拨打电话在底部或者如果行足够长以至于它会创建一个大于当前页面的单元格。此外,由于您已经进行了FPDF的课堂扩展,请创建一个或两个函数,而不是重复所有。
答案 1 :(得分:0)
使用EasyTable更容易。 Pagebreak不会成为问题。
例如:
require('fpdf/exfpdf.php');
require('fpdf/easyTable.php');
...
$tableB=new easyTable($pdf, '6', 'align:L; width:100%; split-row:true; border:0; border-color:#000000; bgcolor:#ffffff; font-color:#000000; paddingY:0;');
$tableB->easyCell("Data1", 'border: LB; align: L; valign:M');
$tableB->easyCell("Data2", 'border: LB; align: L; valign:M');
$tableB->easyCell("Data3", 'border: LB; align: L; valign:M');
$tableB->easyCell("Data4", 'border: LB; align: L; valign:M');
$tableB->easyCell("Data5", 'border: LB; align: L; valign:M');
$tableB->easyCell("Data6", 'border: LB; align: L; valign:M');
$tableB->printRow();
$tableB->endTable(2);