【问题标题】:Using FPDI AND FPDF使用 FPDI 和 FPDF
【发布时间】:2011-05-13 02:00:30
【问题描述】:

我正在尝试使用 FPDI 和 FPDF 来生成 pdf,但是在创建单元格时遇到了问题。我想使用填充颜色。所以 Cell 有背景颜色。

现在我是这样的:

<?php
require_once('fpdf/fpdf.php'); 
require_once('pdf/fpdi.php'); 
$pdf = new FPDI();

$pdf->AddPage(); 

$pdf->setSourceFile('anolis_dopis_a4.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
//use the imported page and place it at point 0,0; calculate width and height
//automaticallay and ajust the page size to the size of the imported page 
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true); 

// now write some text above the imported page 
$pdf->SetFont('Arial', '', '13'); 
$pdf->SetTextColor(0,0,0);
//set position in pdf document
$pdf->SetXY(40, 50);
//first parameter defines the line height
$pdf->Write(0, 'gift code');

$pdf->SetXY(40, 55);
$pdf->Write(0, 'gift code');

//HERE I WANT TO HAVE BACKGROUND COLOR
$pdf->Cell(100,10,"bla bla",1,"left","");

//force the browser to download the output
$pdf->Output('test.pdf', 'D');

?>

【问题讨论】:

  • 仅在 $x 和 $y $outPdf-&gt;useTemplate($outPdf-&gt;importPage($i), null, null, 0, 0, true); 中使用 Nulls 为我工作。否则它会将页面剪切为 A4。

标签: php fpdf fpdi


【解决方案1】:

我也遇到了同样的问题。我在本网站的另一个主题中找到了答案。

解决方案是在$pdf-&gt;useTemplate($tplIdx, 0, 0, 0, 0, true);之后添加$pdf-&gt;setPageMark();

可能有更多像我这样的人遇到同样的问题并最终来到这里。

【讨论】:

    【解决方案2】:
    $pdf->SetFillColor(227,227,227);
    $pdf->Cell(100,10,'bla bla',1,0,'L',TRUE);
    

    【讨论】:

    • 我想写在 pdf 表上,但是每一个第二个 coll 必须有背景颜色。
    • 上例对我有用,请查看单元手册 - fpdf.org/en/doc/cell.htm
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    相关资源
    最近更新 更多