FPDF标题问题 - 让我发疯!

时间:2010-02-07 17:54:16

标签: php fpdf while-loop fpdi

我正在尝试生成一个PDF,它将项目名称输出到模板PDF(使用FPDI),并在每个页面的顶部列出用户名。每个用户可以拥有不同数量的项目(例如,如果有1-4个项目,只输出一个页面;如果有5-8个项目,则输出两个页面等)

以下是我要做的事情的示例:http://www.mediafire.com/?k2ngmqm1jmm

这是我到目前为止所拥有的。我可以通过设置TopMargin来获得所有间距,但这不允许我将Username标头放入。

<?php
require_once('auth.php');      
require_once('config.php');  
require_once('connect.php');  

$username=$_GET['username'];

$sql="SELECT * FROM $tbl_items WHERE username='$username'";
$result=mysql_query($sql);

require_once('pdf/fpdf.php');
require_once('pdf/fpdi.php');

$pdf =& new FPDI(); 
$pdf->SetTopMargin(30);
$pdf->AddPage('L', 'Letter');
$pdf->setSourceFile('../pdf/files/chart_template.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx);

$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial', 'B');
$pdf->SetFontSize(7);

while($rows=mysql_fetch_array($result)){

$pdf->Cell(20,5,$rows['itemname'],0,0,'C');
$pdf->Ln(45);
}

$pdf->useTemplate($tplIdx);

$pdf->Output('file.pdf', 'I');

?>

请帮忙!

1 个答案:

答案 0 :(得分:0)

我之前使用'header'类扩展名完成了它:

class PDF extends FPDF
{
function Header()
{
    //Select Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Framed title
    $this->Cell(30,10,'Title',1,0,'C');
    //Line break
    $this->Ln(20);
}

请查看解释标题用法的教程:http://www.fpdf.org/en/tutorial/tuto2.htm

相关问题