【发布时间】:2015-01-25 23:51:01
【问题描述】:
我正在尝试将文本写入 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
【问题讨论】:
标签: php pdf pdf-generation fpdf fpdi