【问题标题】:How to have multicolumn in a pdf through php and fpdf如何通过 php 和 fpdf 在 pdf 中添加多列
【发布时间】:2012-07-22 09:38:48
【问题描述】:

我在使用 php 和 fpdf 时遇到了一些问题。

我必须通过 fpdf 和 php 制作一份 pdf 格式的报告,我想在其中向学生展示老师正在教书。

我想要的是 fpdf 应该创建一个具有相同字段的多列的页面。

图片链接:http://i1267.photobucket.com/albums/jj552/ThePerfectH/abc.png

如您所见,在这张图片中,我希望数据在一列中直到 30,然后它应该在一页中移动到不同的列中。

示例代码:

$result=mysql_query("select p.p_sname as pap from sgm, students st
    left join sps on st.studentid=sps.studentid
    left join papers p on p.p_id=sps.paperid where p.type='optional' and
    sgm.studentid=st.studentid and sgm.groupid=3 and st.course=3 and
    st.status='Regular' order by name");
    if($result === FALSE)
{
die(mysql_error()); // better error handling
}
$i=0;
$max=30;
$s=1;
$row_height = 6;
$y_axis = 33 + $row_height;
while($row = mysql_fetch_array($result))
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
    $y_axis= 33 + $row_height;
    $pdf->SetX(80);
    $pdf->SetTextColor(153,0,102);
    $pdf->SetFont('Arial','',10);
        //print column titles for the current page
    $pdf->SetY(33);
    $pdf->SetX(80);
    $pdf->Cell(20,6,'S No.',1,0,'C',1);
    $pdf->SetY($y_axis);
    $pdf->SetX(80);
    $pdf->Cell(20,6,$s,1,0,'C',1);
    $y_axis = $y_axis + $row_height;
        $i = $i + 1;
    $s=$s+1;


}

        $rollno=$row['rollno'];
    $name=$row['name'];
    $cat=$row['cat'];
    $pap=$row['pap'];
    $pdf->SetY($y_axis);
    $pdf->SetX(48);
    $pdf->SetFont('Arial','',10);
    $pdf->Cell(20,6,$s,1,0,'C',1);
    //Go to next row
    $s=$s+1;
    $y_axis = $y_axis + $row_height;

        $i = $i + 1;    }       

正如您在图片中看到的,这会导致我的行在仅创建一个新列后重叠。

谁能帮忙。

【问题讨论】:

    标签: php pdf phpmyadmin tcpdf fpdf


    【解决方案1】:

    我通过将 SetX 更改为 x_axis 来完成它,当它达到 30 时,它添加到 x_axis

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 2013-12-20
      • 2018-05-12
      • 2014-06-05
      相关资源
      最近更新 更多