问题
I am trying to write out some special characters with built in fonts, is there any way to do this?
$str = 'ščťžýáíéäúň§ôúőűáéóüöűú'; $str = iconv('UTF-8', 'windows-1252', $str);
the result is one letter Š, not too good. :)
回答1:
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
回答2:
You'll need to use tFPDF derivate of FPDF. tFPDF uses the PHP multi-byte string functions and generates its output encoded with UTF-8. FPDF does not. You'll also need to use a font that supports all the Unicode characters you want to use. Most commonly, I'll use Arial.
See: http://fpdf.org/en/script/script92.php
来源:https://stackoverflow.com/questions/10626075/fpdf-and-special-characters