Zend_Pdf中没有显示Unicode字符?

时间:2022-02-24 21:10:53
require_once 'Zend/Pdf.php';
$pdf = new Zend_Pdf();
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10);
$page->drawText("Bogus Russian: это фигня", 100, 400, "UTF-8");
$pdfData = $pdf->render();
header("Content-Disposition: inline; filename=output.pdf"); 
header("Content-type: application/x-pdf"); 
echo $pdfData;

I can't get the Russian characters to show up! I've managed to get them to show up as:

我不能让俄罗斯人物出现!我设法让他们出现:

Russian: ???????????
Russian: ÐоммÑнÐ
Russian: 
and
Russian: ><

2 个解决方案

#1


Perhaps this will answer your question:

也许这会回答你的问题:

How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符

By the looks of it the default fonts do not have all the utf-8 characters...you may have to load external TTF...

从它的外观来看,默认字体没有所有的utf-8字符...你可能需要加载外部TTF ...

#2


This post explains it better: How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

这篇文章更好地解释了:如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符

Essentially the built-in fonts (eg. Zend_Pdf_Font::FONT_HELVETICA) don't contain enough info, so you need to attach a font ttf file with the pdf, and set your script to use that font.

本质上,内置字体(例如Zend_Pdf_Font :: FONT_HELVETICA)不包含足够的信息,因此您需要使用pdf附加字体ttf文件,并将脚本设置为使用该字体。

$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times.ttf');
$pdfPage->setFont($font, 36);

#1


Perhaps this will answer your question:

也许这会回答你的问题:

How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符

By the looks of it the default fonts do not have all the utf-8 characters...you may have to load external TTF...

从它的外观来看,默认字体没有所有的utf-8字符...你可能需要加载外部TTF ...

#2


This post explains it better: How to generate pdf files _with_ utf-8 multibyte characters using Zend Framework

这篇文章更好地解释了:如何使用Zend Framework生成pdf文件_with_ utf-8多字节字符

Essentially the built-in fonts (eg. Zend_Pdf_Font::FONT_HELVETICA) don't contain enough info, so you need to attach a font ttf file with the pdf, and set your script to use that font.

本质上,内置字体(例如Zend_Pdf_Font :: FONT_HELVETICA)不包含足够的信息,因此您需要使用pdf附加字体ttf文件,并将脚本设置为使用该字体。

$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times.ttf');
$pdfPage->setFont($font, 36);