FPDF 标题问题 - 让我发疯!

发布于 2024-08-20 22:49:33 字数 1112 浏览 5 评论 0原文

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

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

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

<?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');

?>

请帮忙!

I am trying to generate a PDF that outputs Item Names onto a template PDF (using FPDI) with the Username listed on the top of each page. Every user can have a different number of items (i.e. if there are 1-4 items, only output one page; if there 5-8 items, output two pages, etc.)

Here is an example of what I am trying to do: http://www.mediafire.com/?k2ngmqm1jmm

This is what I have so far. I am able to get all of the spacing to work by setting a TopMargin, but this doesn't allow me to put the Username header in.

<?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');

?>

Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苹果你个爱泡泡 2024-08-27 22:49:33

我之前已经使用“标头”类扩展完成了此操作:

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

I've done it previously using the 'header' class extension:

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);
}

Have a look at the tutorial which explains the header usage at : http://www.fpdf.org/en/tutorial/tuto2.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文