TCPDF问题:如何对齐文本和图像?

I want to generate resume in PDF format via PHP. TCPDF looks like a flexible library for that purpose. Let's say this is the expected result:

enter image description here

I just started learning TCPDF, so far I have the company title, name and title done, but they are not on the same alignment. enter image description here

Here's my code:

<?php

require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        $image_file = 'umbrella_logo.jpg';
        $this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('helvetica', 'B', 20);
    }
}


// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);    
$pdf->SetAuthor('Umbrella Corporation'); 
$pdf->SetTitle('Employee Resume');       

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));

$pdf->AddPage();

$pdf->SetXY(15, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');

$pdf->SetXY(15, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'C', 0, '', 0, false, 'B', 'B');

$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');

?>

How to fix this?

First, you're using center alignment for your cells rather than left alignment, so your cells are being center-aligned to widths of 25 and 20 mm respectively.

Instead, change parameter 6 from 'C' to 'L' for your Cell calls, and that will change them to left alignment. That should get your cells to line up the way you're expecting.

Next, for the header image and text alignment. Since you're trying to align your cells with the boundaries of an image (or perhaps something inside an image), you'll probably want to remove the default cell padding with $pdf->setCellPadding(0);

Then you can adjust your Image or Cell positions as you see fit. Here, I have them aligned at an abscissa of 10mm.

Screen capture of generated PDF

<?php

//Note that my paths are different, use your project's appropriate paths.
require_once('TCPDF-6.2.17/tcpdf.php');

class MYPDF extends TCPDF {

    //Page header
    public function Header() {
        // Logo
        // Set font
        $image_file = 'lymle.jpg';

        $this->Image($image_file, 10, 10, 45, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        $this->SetFont('helvetica', 'B', 20);
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Umbrella Corporation');
$pdf->SetTitle('Employee Resume');


// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' My PDF', PDF_HEADER_STRING, array(0,64,255), array(0,64,100));

$pdf->AddPage();

$pdf->setCellPadding(0);

$pdf->SetXY(10, 30);
$pdf->Cell(25, 10, 'Tobias Rieper', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');

$pdf->SetXY(10, 35);
$pdf->Cell(20, 10, 'Senior Biochemist', 0, $ln=0, 'L', 0, '', 0, false, 'B', 'B');

$pdf->setFooterData(array(0,64,0), array(0,64,128));
$pdf->Output('example_001.pdf', 'I');