views:

134

answers:

2

Hello, I have problems outputting UTF-8 characters into pdf file with Zend_Pdf. Here is my code:

// Load Zend_Pdf class 
include 'Zend/Pdf.php';

// Create new PDF 
$pdf = new Zend_Pdf();

// Set font 
$page->setFont(Zend_Pdf_Font::fontWithPath('fonts/times.ttf'), 12); 

// Draw text 
$page->drawText('Janko Hraško', 200, 643, 'UTF-8');

The font I§m loading supports UTF-8 characters. But I am getting this error"

Notice: iconv() [function.iconv]: Detected an illegal character in input string in D:\data\o\Zend\Pdf\Resource\Font\Type0.php  on line 241
A: 

With the Helvetica font your code works!

Michelangelo
I finally solved this by using Windows-1250 instead of UTF-8 but thanks... +1
Richard Knop
A: 

Solved:

$page->drawText('Janko Hraško', 200, 643, 'Windows-1250');

For some reason, Windows-1250 encoding works but UTF-8 doesn't. Weird but I will use Windows-1250 then.

Richard Knop
This isn't really a "solution". If someone is viewing your PDF and doesn't have that encoding available (e.g. A Mac user), they'll get blocks or, worse, weird characters. For the sake of portability and maintainability, UTF-8 should generally be preferred. -- Odds are what's happening is you're typing the characters in Windows-1250 encoding, where s-with-caron is 0x9A, a single byte. Whereas in Unicode it's U+0161, so it should be multiple bytes. Give the input in the proper encoding, and you won't get an error.
Conspicuous Compiler