Reputation:
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
Upvotes: 3
Views: 3015
Reputation: 11
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.
Upvotes: 1
Reputation: 40675
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');
Upvotes: 1