Patrik
Patrik

Reputation: 1327

TCPDF: How to set FONT SIZE in right way

I want to set some text-blocks by TCPDF. But I have some problems with font size. First text block is on x-y/5-5, and his font size is 5 to. But it is samaller then 5. Font-size in TCPDF is not in the same units like other dimensions ?

TCPDF - dimensions and font-size

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...

Web example.

Upvotes: 3

Views: 36125

Answers (2)

Patrik
Patrik

Reputation: 1327

OK I found answer and solution. When we create new PDF document in tcPDF, dimensions units whole document can be in formats like mm, cm, pt, px. But fonts are in points - pt.

So solution...

  1. Set the documents units with 'setPageUnit'.
  2. If we have dimensions in pixels, we must convert it by 'pixelsToUnits'.

PHP - tcPDF Exampe :

$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 );

Upvotes: 10

Selva kumar
Selva kumar

Reputation: 385

Changing font size in TCPDF ... Which can set using below code :

$pdf = new TCPDF();
$pdf->SetFont('Font family', '', font size here);

Which are default setting in TCPDF

Upvotes: 5

Related Questions