Php 错误的utf8字符输出savexml和tcpdf

Php 错误的utf8字符输出savexml和tcpdf,php,utf-8,svg,tcpdf,Php,Utf 8,Svg,Tcpdf,您好,我正在使用TCPDF加载svg文件,对其进行操作并将其作为pdf发送 svg文件包含utf8字符,保存后utf8字符无法正确显示 这是svg文件 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <svg xmlns="http://www.w3.org/2000/svg" height="742" id="svg_area" shape-rendering="crispEdges" title="test"

您好,我正在使用TCPDF加载svg文件,对其进行操作并将其作为pdf发送

svg文件包含utf8字符,保存后utf8字符无法正确显示

这是svg文件

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<svg xmlns="http://www.w3.org/2000/svg" height="742" id="svg_area" shape-rendering="crispEdges" title="test" viewport-fill="" viewport-fill-opacity="0" width="1042" xmlns:xlink="http://www.w3.org/1999/xlink">

<defs id="4D"/>
<g Cbarre="2" id="Image_DBB524BDFDFB4E4180B8BB48EF3F68CC" transform="rotate(0,176.5,522)">
    <text font-family="arial" font-size="14" height="20" id="txtImage_DBB524BDFDFB4E4180B8BB48EF3F68CC" visibility="visible" x="404" y="435" ztspan="1">
    <tspan>äëïòû</tspan>
    </text>
  </g>
</svg>

äëïòû
以及php代码:

 // create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'UTF-8', false);

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(0, 0, 5, true);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 0);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language dependent data:
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';

//set some language-dependent strings
$pdf->setLanguageArray($lg);
//$source : path to svg file
$dom = new DOMDocument();
$dom->load($source);
$xpath = new DOMXpath($dom);

// set orientation
$page = $dom->getElementsByTagName('svg')->item(0);
$width_page = $page->getAttribute('width');
$height_page = $page->getAttribute('height');
$orientation = 'L';
if($width_page < $height_page){
    $orientation = 'P';
}

// add a page  
$pdf->AddPage($orientation, '', false, false);    


//modify dom svg for variable
foreach ($_GET as $key => $value) {
    $gNodes=$xpath->query('//*[@id=\'' . $key . '\']');
    foreach ($gNodes as $gNode) {
        // doing stuff with $gNode
        $gNode->nodeValue = $value;
    }
 }   
$txt = '@'.$dom->saveXml();
$pdf->ImageSVG($txt, $x=0, $y=0, $w='', $h='', $link='', $align='', $palign='', $border=1, $fitonpage=true);
//Close and output PDF document
$pdf->Output('utf8.pdf', 'I');
//创建新的PDF文档
$pdf=新的TCPDF(pdf页面方向,pdf单元,pdf页面格式,假,'UTF-8',假);
//删除默认页眉/页脚
$pdf->setPrintHeader(假);
$pdf->setPrintFooter(false);
//设置默认的单间距字体
$pdf->SetDefaultMonospacedFont(pdf\u字体\u等距);
//设置边距
$pdf->SetMargins(0,0,5,true);
//设置自动分页符
$pdf->SetAutoPageBreak(真,0);
//设置图像比例因子
$pdf->setImageScale(pdf图像比例);
//设置一些语言相关数据:
$lg=数组();
$lg['a_meta_charset']='UTF-8';
//设置一些与语言相关的字符串
$pdf->setLanguageArray($lg);
//$source:svg文件的路径
$dom=新的DOMDocument();
$dom->load($source);
$xpath=newdomxpath($dom);
//设定方向
$page=$dom->getElementsByTagName('svg')->item(0);
$width_page=$page->getAttribute('width');
$height_page=$page->getAttribute('height');
$orientation='L';
如果($width\u page<$height\u page){
$orientation='P';
}
//添加页面
$pdf->AddPage($orientation',,false,false);
//修改变量的dom svg
foreach($\u获取为$key=>$value){
$gNodes=$xpath->query('/*[@id=\'.$key.'\']');
foreach($gNodes作为$gNode){
//用$gNode做事情
$gNode->nodeValue=$value;
}
}   
$txt='@'.$dom->saveXml();
$pdf->ImageSVG($txt,$x=0,$y=0,$w='',$h='',$link='',$align='',$PAIGN='',$border=1,$fitonpage=true);
//关闭并输出PDF文档
$pdf->Output('utf8.pdf','I');
治疗后的pdf文件显示错误的utf-8字符:我希望pdf中有“ëëòë”,我得到了“ÃÃëÃÃÃÃÿÿ”。 谢谢你的回答

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'UTF-8', false);
应该是:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

如果要使用unicode编码,则unicode参数应设置为true。假设您的SVG文件正确地保存为UTF-8,那么它应该可以像您预期的那样使用此更改。

很难确定问题出在哪里。PDF中显示了什么?您期望什么?您好,我期望PDF中的“ëëòë”,我得到了“ÃÃÃ~ÃÃÔ。