Php 使用fpdf Write()时遇到奇怪的上边距

Php 使用fpdf Write()时遇到奇怪的上边距,php,pdf,pdf-generation,fpdf,fpdi,Php,Pdf,Pdf Generation,Fpdf,Fpdi,我试图将文本写入PDF,但页面顶部似乎有一个奇怪的空白 这是我的以下代码: require_once('fpdf.php'); require_once('fpdi/fpdi.php'); //Start the FPDI $pdf = new FPDI('P', 'pt'); //Set the source PDF file $source_file = $pdf->setSourceFile("template.pdf"); //Import the first page of

我试图将文本写入PDF,但页面顶部似乎有一个奇怪的空白

这是我的以下代码:

require_once('fpdf.php');
require_once('fpdi/fpdi.php');

//Start the FPDI
$pdf = new FPDI('P', 'pt');

//Set the source PDF file
$source_file = $pdf->setSourceFile("template.pdf");

//Import the first page of the file
$tppl = $pdf->importPage(1);

$pdf->AddPage();

//get size of pdf page
$size = $pdf->getTemplateSize($tppl);

$pdf->useTemplate($tppl, null, null, $size['w'], $size['h'], true);
$pdf->SetMargins(0, 0, 0);
$pdf->SetTextColor(0, 0, 0); 
当我使用字体大小为pt 12并编写文本时,我得到以下结果:

$pdf->SetFont('Arial', '', 12);
$pdf->SetXY(0, 0);
$pdf->Write(0, "Hi");

当我执行
$pdf->SetXY(0,7.5)
时,我得到了这个

上面看起来我可以很容易地在Y轴上加上7.5点,这样就可以了

但是,如果我更改字体大小,顶部和文本之间的距离会增大一点

$pdf->SetFont('Arial', '', 8);

有谁能帮我弄清楚如何中和它,至少这样,如果我将XY设置为一个数字,它将把它放在某个位置,而不管字体大小?我尝试过不同的pdf格式,效果都一样

编辑:
我做了
$pdf->GetY()
,我得到了
28.35

你只需要定义一个零的线高度。因此,文本在垂直方向上围绕0“居中”

常见的线条高度为:

$pdf->Write($pdf->FontSize * 1.2, "Hi");

我解决这个问题的方法是使用
Cell()
,而不是执行
Write()

我认为主要的问题是没有一个坚实的宽度和高度。我所知道的是它现在工作得非常好,所以任何遇到同样问题的人都应该试试这个

$pdf->Cell(WIDTH,HEIGHT,TEXT);
我也做了以下工作,不确定这是否有帮助,但我的脚本中有它

$pdf->SetMargins(0, 0);
$pdf->cMargin = 0;