Special Characters in Fpdf with PHP

Special Characters in FPDF with PHP

Figured this out by doing the following (pagesubtitle is the name of the text field in the form):

$reportSubtitle = stripslashes($_POST['pagesubtitle']);
$reportSubtitle = iconv('UTF-8', 'windows-1252', $reportSubtitle);

Then print it out:

$pdf->Write (6, $reportSubtitle);

This will remove any unwanted slashes following apostrophes, as well as use the 'iconv' function to print special characters such as ™

FPDF library not showing special characters like '✓'

This character is not included in windows-1255. You may use "ZapfDingbats" and use chr(51) or chr(52).

$pdf->SetFont('ZapfDingbats', '', 12);
$pdf->Write(0, chr(51();

See here for a font dump of all standard fonts.

Fpdf and special characters

I know it's an old thread, but I've faced the issue this weekend and spent a longtime Googling and playing, so here's a time saver.
http://fpdf.org/en/script/script92.php is the way to go to use diacritics (accented characters). But you need to add some code to it...
Slot this in at line 617

 /* Modified by Vinod Patidar due to font key does not match in dejavu bold.*/
if ( $family == 'dejavu' && !empty($style) && ($style == 'B' || $style == 'b') ) {
$fontkey = $family.' '.strtolower($style);
} else {
$fontkey = $family.$style;
}
/* Modified end here*/

Then change

if($family=='arial')
$family = 'helvetica';

To

 if($family=='arial'||$family='dejavu')
$family = 'helvetica';

Then don't use the font in the example "DejaVu Sans Condensed" because Condensed seems to mean the Bold version doesn't contain all the characters

You may also need to add the getPageWidth and getPageHeight methods from the normal fpdf.php script as it is newer than tfpdf.php!

With the changes above

$pdflabel->AddFont('DejaVu','','DejaVuSans.ttf',true);  
$pdf->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true);

Works a good 'un with European languages

How to handle special characters in FPDF

Checkout the extension of FPDF/HTML2PDF called mPDF that allows Unicode fonts.

http://www.mpdf1.com/mpdf/index.php

Producing symbols from HTML characters in FPDF

You're looking for html_entity_decode().

fpdf: Embedding special characters

I found the answer myself. First, I implement tFPDF. Then I use the DejaVu UTF-8 font that is included in the package, then use urldecode to display the character.

urldecode('%E2%99%AD');


Related Topics



Leave a reply



Submit