我正在尝试生成一个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');
?>
请帮帮我!
发布于 2010-02-08 14:05:58
我之前已经使用'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
https://stackoverflow.com/questions/2217646
复制相似问题