php - 分页符时FPDF表列会迷失方向-LMLPHP php - 分页符时FPDF表列会迷失方向-LMLPHP

<?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轴有关,但我不知道如何解决这个问题,有人可以帮忙吗?

最佳答案

由于使用了AutoPageBreak,您对MultiCell遇到了问题,因此请使用$pdf -> SetAutoPageBreak( false );将其关闭,并在靠近页面底部时手动进行呼叫,而在页面底部或行以下时手动进行呼叫。足够长的时间,它将创建一个比当前页面大的单元格。另外,由于您已经对FPDF进行了类扩展,因此请创建一个或两个函数,而不要重复全部操作。

关于php - 分页符时FPDF表列会迷失方向,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45929490/

10-11 08:04