sFPDF

Informations

Author: Ian Back
License: LGPL

Description

This class is a modified version of FPDF that adds UTF-8 support. Moreover, it embeds only the necessary parts of the fonts that are used in the document, making the file size much smaller than if the whole fonts were embedded. These features were originally developed for the mPDF project.

Before you can use UTF-8, you have to install at least one Unicode font in the font/unifont directory. Some free font packages are available for download (extract them into font/unifont):

Fonts from the DejaVu family:

Fonts from the GNU FreeFont family:

You can also make your own fonts by pointing your browser to font/unifont/makefonts/makefonts.php and following instructions (if you're on Windows).

Then, to use a Unicode font in your script, pass true as the fourth parameter of AddFont().

Note: this class requires the mbstring extension.

Example

This example uses the DejaVu Sans Condensed font to display some Unicode strings. Be sure to install the font in the font/unifont directory first.
<?php
require('sfpdf.php');

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

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

// Load a UTF-8 string from a file and print it
$txt = file_get_contents('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 17 KB.');

$pdf->Output();
?>
View the result here.

Download

ZIP | TGZ