I'm currently using TCPDF to generate a resume in my web application. But with the limited support for css have cornered me. Now I'm trying to apply the background color for the every page that is generated. But I'm only getting the color for the first page.
My code is:
<?php
class PROFILE_PDF extends TCPDF
{
public function Header()
{
$this->SetFillColor(52, 21, 0, 76);
$this->Rect(0, 0, $this->getPageWidth(), $this->getPageHeight(), 'DF', "");
}
private $footer_data = array();
public function Footer()
{
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$name = <<< EOD
<p>Curriculum Vitae - {$this->footer_data["name"]}</p>
<style>
p {
color: #F5F5F5;
}
</style>
EOD;
$this->writeHTMLCell(0, 10, '', '', $name, 0, 1, 0, true, 'L', true);
$page = <<< EOD
<p>Page {$this->getAliasNumPage()} / {$this->getAliasNbPages()}</p>
<style>
p {
color: #F5F5F5;
}
</style>
EOD;
$this->writeHTMLCell(0, 10, '', 284, $page, 0, 1, 0, true, 'R', true);
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(128, 229, 255));
$this->Line(0, 275, 250, 275, $style);
}
public function setFooterData($footer_data)
{
$this->footer_data = $footer_data;
}
$pdf = new PROFILE_PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetLineStyle(array('width' => 2, 'color' => array(112, 128, 144)));
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
$pdf->Line(0, 0, 0, $pdf->getPageHeight());
// set header data
$footer_data = array();
$footer_data["name"] = $personal_data["first_name"] . " " . $personal_data["last_name"];
$pdf->setFooterData($footer_data);
$pdf->setPrintHeader(false);
//$pdf->Header();
// set document information
$pdf->SetCreator(getSiteName());
$pdf->SetAuthor('hSenid Mobile Solutions');
$pdf->SetTitle($personal_data["first_name"] . " " . $personal_data["last_name"]);
$pdf->SetSubject("Student's profile");
$pdf->setPrintHeader(false);
$pdf->AddPage();
$pdf->SetFillColor(52, 21, 0, 76);
$pdf->Rect(0, 0, $pdf->getPageWidth(), $pdf->getPageHeight(), 'DF', "");
$pdf->SetFont('courier', 'B', 24);
//some html elements
$pdf->Output($personal_data["first_name"] . "_" . $personal_data["last_name"] . ".pdf", 'D');
?>
Here I'm being unable to apply the SetFillColor()
function to next generated pages. What's the reason for that? TCPDF documentation says it should be apply to all the pages.
if you mean apply a background color with your
header
function you should apply the fill color directly on the$pdf->rect
function in TCPDFso in your case it would be
where you have to change the array in the last argument to apply your color
It don't work because on TCPDF the fill color , as far as i know, will apply on the
cell
andmulticell
function if you specified the fill argument on truelink on rect function TCPDF
but the better option is to define it in the header and use as the example 51 on TCPDF link to the example
so here it's