php-tcpdfHow do I use TCPDF with PHP to specify a font?
Using TCPDF with PHP to specify a font is easy. First, you need to include the TCPDF library in your project.
<?php
require_once('tcpdf_include.php');
?>
Then you need to create a new TCPDF object.
<?php
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
?>
After that you can use the SetFont()
method to specify a font.
<?php
$pdf->SetFont('dejavusans', '', 14, '', true);
?>
The first parameter is the font family. The second parameter is the font style (e.g. 'B' for bold). The third parameter is the font size. The fourth parameter is the font file path (if the font is not in the TCPDF folder). The fifth parameter is a boolean value that indicates whether the font is embedded or not.
You can also use the AddFont()
method to add a custom font.
<?php
$fontname = $pdf->AddFont('myfont', '', 'myfont.php');
$pdf->SetFont($fontname, '', 14, '', true);
?>
The first parameter is the font family name. The second parameter is the font style (e.g. 'B' for bold). The third parameter is the font file path.
For more information, please refer to the TCPDF documentation.
More of Php Tcpdf
- How do I install TCPDF using Yum on a PHP server?
- How do I use TCPDF with PHP?
- How do I use the setfont function in PHP TCPDF?
- How do I add a watermark to PDFs using PHP and TCPDF?
- How can I generate a QR code using PHP and TCPDF?
- How can I use PHP and TCPDF to read a PDF?
- How do I generate a PDF file using TCPDF, PHP and MySQL?
- How can I generate a PDF from data stored in a MySQL database using TCPDF and PHP?
- How do I set the page orientation when using PHP TCPDF?
- How can I generate a landscape PDF document using PHP TCPDF?
See more codes...