TCPDF - 为自定义设置留边距 header
TCPDF - Set margin left for custom header
我在 TCPDF 中使用自定义 header。我想为此 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;
有没有办法做到这一点?
更新
嗯,奇怪的是这个有效:
$pdf->CustomHeaderText = ' '.$presentation_name;
虽然我不一定会称其为可接受的方法...
很简单:创建一个 GetLeftMargin()
方法来访问 lMargin
属性(不是绝对必要的步骤,但强烈推荐),存储原始值,设置标题边距, 执行正常的写入操作,然后最终恢复边距。
示例可能如下所示:
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;
}
}
我在 TCPDF 中使用自定义 header。我想为此 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;
有没有办法做到这一点?
更新
嗯,奇怪的是这个有效:
$pdf->CustomHeaderText = ' '.$presentation_name;
虽然我不一定会称其为可接受的方法...
很简单:创建一个 GetLeftMargin()
方法来访问 lMargin
属性(不是绝对必要的步骤,但强烈推荐),存储原始值,设置标题边距, 执行正常的写入操作,然后最终恢复边距。
示例可能如下所示:
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;
}
}