使用 FPDI 和 FPDF
我正在尝试使用 FPDI 和 FPDF 生成 pdf,但在创建单元格时遇到问题。我想使用填充颜色。所以单元格有背景颜色。
现在我有这样的:
<?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');
?>
I'm trying to use FPDI and FPDF for generating a pdf, but I have a problem when I create a cell. I want to use the fillcolor. So the Cell has a background color.
For now I have like this:
<?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');
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚遇到了同样的问题。我在这个网站的另一个主题中找到了答案。
解决方案是在
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
之后添加$pdf->setPageMark();
可能还有更多像我一样遇到同样问题并最终来到这里的人。
I just had the same problem. I found the answer in another topic on this website.
The solution is adding
$pdf->setPageMark();
after the$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
There are probably more people like me out there who have the same problem and end up here.