Pat*_*rik 3 php pdf font-size dimensions tcpdf
我想通过TCPDF设置一些文本块.但是我的字体大小有些问题.第一个文本块在xy/5-5上,字体大小为5到.但它比5更小.TCPDF中的字体大小与其他维度的字体大小不同?

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...
Run Code Online (Sandbox Code Playgroud)
好的我找到了答案和解决方案.当我们在tcPDF中创建新的PDF文档时,尺寸单位整个文档可以采用mm,cm,pt,px等格式.但字体是点 - pt.
解决方案......
PHP - tcPDF示例:
$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 );
Run Code Online (Sandbox Code Playgroud)
小智 5
更改 TCPDF 中的字体大小...可以使用以下代码进行设置:
$pdf = new TCPDF();
$pdf->SetFont('Font family', '', font size here);
Run Code Online (Sandbox Code Playgroud)
TCPDF 中的默认设置