使用 FPDI 和 FPDF

发布于 2024-10-03 20:39:55 字数 1001 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(2

小糖芽 2024-10-10 20:39:55

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

解决方案是在 $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.

樱花坊 2024-10-10 20:39:55
$pdf->SetFillColor(227,227,227);
$pdf->Cell(100,10,'bla bla',1,0,'L',TRUE);
$pdf->SetFillColor(227,227,227);
$pdf->Cell(100,10,'bla bla',1,0,'L',TRUE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文