This first image shows the standard header layout when using TCPDF:
What I would like to do is right justify the text, as shown below, but I have not been able to figure out how to do this:
Please offer some suggestions! Thanks.
One way to accomplish this is with the writeHTMLCell()
method. Setting the $w
parameter to 0 will cause the cell to extend to the right margin. The $align
parameter can then be set to 'R'
, which will right-align the cell content.
$html = '<strong>Header Title</strong><br/>
Header string, Line 1<br/>
Header string, Line 2<br/>
Header string, Line 3';
$pdf->writeHTMLCell(
$w=0,
$h=0,
$x=0,
$y=10,
$html,
$border=0,
$ln=0,
$fill=false,
$reseth=true,
$align='R'
);
This full example can be run in the TCPDF examples directory.
<?php
require_once('tcpdf_include.php');
class MYPDF extends TCPDF
{
public function Header()
{
$image_file = K_PATH_IMAGES.'logo_example.jpg';
$this->Image($image_file, 10, 10, 15, '', 'JPG');
$html = '<strong>Header Title</strong><br/>
Header string, Line 1<br/>
Header string, Line 2<br/>
Header string, Line 3';
$this->writeHTMLCell(
$w=0,
$h=0,
$x=0,
$y=10,
$html,
$border=0,
$ln=0,
$fill=false,
$reseth=true,
$align='R'
);
}
}
$pdf = new MYPDF();
$pdf->AddPage();
$pdf->Output('example.pdf', 'I');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With