TCPDF: How to set FONT SIZE correctly
I want to set some text blocks using TCPDF. But I have some problems with the font size. The first text block is at xy / 5-5, and its font size is 5. But that's samaller then 5. Is the font size in TCPDF not in the same units as the other measurements?
PHP
$text1 = 'AAAg';
$text1_x = 5;
$text1_y = 5;
$text1_font_size = 5;
$text2 = 'BBBg';
$text2_x = 10;
$text2_y = 10;
$text2_font_size = 10;
$text3 = 'CCCg';
$text3_x = 15;
$text3_y = 15;
$text3_font_size = 15;
// I tried $pdf->Cell and $pdf->Text... both are doing the same...
+3
source to share
2 answers
OK I found the answer and solution. When we create a new PDF document in tcPDF, the units can be in formats such as mm, cm, pt, px. But the fonts are in points - pt.
So the solution ...
- Set document units with < setPageUnit .
- If we have dimensions in pixels, we must convert them using pixelsToUnits .
PHP - tcPDF exam :
$pdf->setPageUnit('pt');
$document_width = $pdf->pixelsToUnits('100');
$document_height = $pdf->pixelsToUnits('100');
$x = $pdf->pixelsToUnits('20');
$y = $pdf->pixelsToUnits('20');
$font_size = $pdf->pixelsToUnits('20');
$txt = 'AAAg';
$pdf->SetFont ('helvetica', '', $font_size , '', 'default', true );
$pdf->Text ( $x, $y, $txt, false, false, true, 0, 0, '', false, '', 0, false, 'T', 'M', false );
+6
source to share