PHP 7 TFPDF Add UTF-8 Fonts Inside PDF Document

index.php

<?php

define("_SYSTEM_TTFONTS", "../fonts");

require('tfpdf.php');

$pdf = new tFPDF();
$pdf->AddPage();

// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);

// Load a UTF-8 string from a file and print it
$txt = 'HelloWorld.txt';
$pdf->Write(8,$txt);

// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 13 KB.');

$pdf->Output();
?>

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.