2010-11-20 117 views
0

我正在尝试使用FPDI和FPDF生成PDF,但创建单元时出现问题。我想使用fillcolor。所以Cell有背景色。使用FPDI和FPDF

现在我有这样的:

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

?> 
+0

只为我使用$ x&$ y中的空值 '$ outPdf-> useTemplate($ outPdf-> importPage($ i),null,null,0,0,true);'。否则它将页面切割为A4。 – juanmf 2014-07-23 19:25:42

回答

0
$pdf->SetFillColor(227,227,227); 
$pdf->Cell(100,10,'bla bla',1,0,'L',TRUE); 
+0

我tryed但不起作用 – Alen 2010-11-20 13:17:05

+0

给我完整的代码,你有什么 – jatt 2010-11-20 13:19:19

+0

我想写在pdf表上,但evry第二科尔必须有backgorund颜色。 – Alen 2010-11-20 13:30:56

2

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

解决方案是$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);

后加入$pdf->setPageMark();可能有更多的人喜欢我在那里谁具有同样的问题,这里就结束了。