phptcpdf

TCPDF centre text in a TextField


I am using TCPDF to generate a form. When the generated form is completed I would like to centre the text within the TextField. I suspect this may not be possible but could do with this confirming from someone in the know.

This is how I am generating my TextFields:

// write HTML content
$pdf->writeHTML($html, true, false, true, false, '');

// start adding text fields
$pdf->SetXY(11, 182);
$pdf->TextField('r8', 22, 8, array('borderColor' => array(255, 255, 255), 'align' => 'C'), array());

// Close and output the PDF
$pdf->Output('document_frontsheet.pdf', 'D');

I was advised that 'align' => 'C' should do it but this appears not to be the case.


Solution

  • I was able to find a solution which worked for me.

    $pdf->SetXY(11, 182);
    $pdf->TextField('r8', 22, 8, array(), array('Q'=>1));
    

    The last part, array('Q'=>1) takes the following values: 0 - align left 1 - align center 2 - align right.