【问题标题】:FPDF Header Question - Driving me crazy!FPDF 标题问题 - 让我发疯!
【发布时间】:2010-02-07 17:54:16
【问题描述】:

我正在尝试生成一个 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');

?>

请帮忙!

【问题讨论】:

  • 我一头雾水,链接失效了。

标签: php fpdf while-loop fpdi


【解决方案1】:

我之前使用 '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

【讨论】:

  • 我尝试在其中添加 'header' 类,但仍然无法正常工作。我认为您需要调用“$pdf = new PDF();”为了显示标题。而且这个功能似乎不适用于 FPDI。还有其他想法吗?
  • @Michael - 用“我认为你需要打电话给new FPDF()”救了我的命,干杯。不是您的问题的解决方案,但可能是下一个阅读本文的人的解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-30
  • 2012-11-02
  • 2020-11-13
  • 1970-01-01
相关资源
最近更新 更多