views:

790

answers:

3

Hi all,

I have troubles using Zend Framework's PDF

When I create PDF file I need to use UTF-8 as encoding. This is the code I am using to generate simple pdf file. I always get this wrong displayed. Instead of seeing 'Faktúra' in pdf file, it gives me 'Faktú' Instead of seeing 'Dodávateľ:' in pdf file, it gives me 'Dodáva'

$pdf = new Zend_Pdf();    
$pdf->pages[] = ($page1 = $pdf->newPage('A4'));    
$font = Zend_Pdf_Font::fontWithPath('C:\WINDOWS\Fonts\TIMES.TTF');    
$page1->setFont($font, 20);    
$page1->drawText('Faktúra', 40, 803, 'UTF-8');    
$page1->drawText('Dodaváteľ:', $width_left, $height, 'UTF-8');

So I tried to load font from Windows directory

$font = Zend_Pdf_Font::fontWithPath('C:\WINDOWS\Fonts\TIMES.TTF');

But it gives me the error:

Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Insufficient data to read 2 bytes'

It is really driving me crazy and I believe some of you would have little hints for me:) Solving the error would be the best solution...

Thanks a lot in advance

+1  A: 

Did you save the php source file as UTF-8?

troelskn
Yes, the source is as UTF-8I was wandering maybe the PDF file itself should also itself be saved as UTF-8, but Zend Framework does not support this kind of saving.I am saving the pdf file this way$pdf->save('faktury/'.$invoice.'.pdf');
I don't think you need to save the pdf as UTF-8 .. pdf is a binary format - I'm pretty sure it handles that stuff internally. Maybe you need to have the iconv extension installed and enabled (Just a wild guess)
troelskn
iconv has been correctly installed... I don't know where to look for solution further.. any clues?
Which version are you using? Try getting the latest from svn/trunk. Apparently they made some changes recently: http://zendframework.com/issues/browse/ZF-5121
troelskn
+1  A: 

try using utf8_decode()

For example:

$pdf = new Zend_Pdf();    
$pdf->pages[] = ($page1 = $pdf->newPage('A4'));    
$font = Zend_Pdf_Font::fontWithPath('C:\WINDOWS\Fonts\TIMES.TTF');    
$page1->setFont($font, 20);    
$page1->drawText(utf8_decode('Faktúra'), 40, 803, 'UTF-8');    
$page1->drawText(utf8_decode('Dodaváteľ:'), $width_left, $height, 'UTF-8');
tharkun
+1  A: 

Zend pdf functionality is not yet very sophisticated. on http://www.starmind.com we use tcpdf which is based on fpdf. both are free to use.