I am using FPDI/FPDF to dynamically add text to a PDF file. I would like for the text to be centered horizontally on the PDF regardless of how long the text is, but I am not sure how to set this using $pdf->SetXY
Here is what I have so far:
<?php
use setasign\Fpdi\Fpdi;
require_once('fpdf.php');
require_once('autoload.php');
// initiate FPDI
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile('test2.pdf');
$tplIdx = $pdf->importPage(1);
$size = $pdf->getTemplateSize($tplIdx);
$pdf->useTemplate($tplIdx, null, null, $size['width'], $size['height'],FALSE);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(0, 0, 0);
// Here's what I have tried
$pdf->SetXY($size['width']/2, 100);
//
$pdf->Write(0, 'Lorem Ipsum');
$pdf->Output();
I tried to use the width of the imported PDF divided by 2 as the X position, however this makes it so that the text starts at that point rather than being centered on it.