Reputation: 4304
I am using a custom header in TCPDF. I would like to set the margin left for this header.
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'uwa_logo.jpg';
$this->Image($image_file, 10, 10, 40, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 14);
// Title
$this->SetTextColor(33,64,154);
$this->Write(0, $this->CustomHeaderText);
}...
$pdf->CustomHeaderText = $presentation_name;
Is there a method to do this?
UPDATE
Mmm, strangely enough this works:
$pdf->CustomHeaderText = ' '.$presentation_name;
Though I wouldn't necessarily call that an accepted method...
Upvotes: 0
Views: 847
Reputation: 7220
Easy enough: create a GetLeftMargin()
method to access the lMargin
property (not a strictly necessary step, but highly recommended), store the original value, set the title margin, do your normal write action, then finally revert the margin afterward.
An example might look something like this:
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Margin
$old_margin = $this->GetLeftMargin();
$this->SetLeftMargin(/* Your new margin here. */);
// Logo
$image_file = K_PATH_IMAGES.'uwa_logo.jpg';
$this->Image($image_file, 10, 10, 40, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 14);
// Title
$this->SetTextColor(33,64,154);
$this->Write(0, $this->CustomHeaderText);
// Revert margin
$this->SetLeftMargin($old_margin);
}
public function GetLeftMargin() {
return $this->lMargin;
}
}
Upvotes: 1