使用 fpdf 正确对齐 pdf 中的文本

Align the text in pdf correctly using fpdf

我必须创建一个 pdf file。我正在使用 fpdf。 我的 pdf 文件应如下所示:

This is a sample pdf.
Hello world.
sample text sample text.

但是这些行以不希望的方式显示。

我的密码是

require('fpdf.php');

$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'This is a sample pdf.');
$pdf->Cell(0,30,'Hello world.');
$pdf->Cell(0,50,'sample text sample text.');
$pdf->Output(); 

生成的 pdf 如下所示:

如何正确对齐 pdf 中的文本?

来自 FPDF documentation about Cell() 函数:

Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])

After the call, the current position moves to the right or to the next line.

ln Indicates where the current position should go after the call. Possible values are:

    0: to the right
    1: to the beginning of the next line
    2: below

Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.

试试这个:

$pdf->Cell(0,10,'This is a sample pdf.', 0, 1);
                                         ^ no border
                                            ^ after the call move to beginning of next line