Zend Framework PDF unicode generation problem

I'm having problems using Zend Framework PDF

When I create a PDF file, I need to use UTF-8 as the encoding. This is the code that I use to create a simple pdf file. I am always mistaken. Instead of seeing “Faktúra” in a pdf file, he gives me “Faktú” Instead of seeing “Dodávate”: in a 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 download the font from the Windows directory

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

But this gives me an error:

Fatal error: exception for the exception 'Zend_Pdf_Exception' with the message 'Not enough data to read 2 bytes'

It really drives me crazy, and I believe that some of you will have little tips for me :) Solving the error would be the best solution ...

+3
3

php UTF-8?

+1

utf8_decode()

:

$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');
+1

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

+1
source

Source: https://habr.com/ru/post/1704036/


All Articles