我正在使用TCPDF库生成pdf。我需要创建一个svg的pdf文件,其中包含一些重音符号,无法正确显示。如果我添加不带svg的带重音符的字符,则可以正常工作,但在svg中存在问题。 我已经尝试过使用$ pdf = new TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,false,'ISO-8859-1',false);但没有成功。
这是我的代码。
<?php
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Example');
$pdf->SetTitle('Test PDF');
$pdf->SetSubject('Test PDF');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 058', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// add a page
$pdf->AddPage();
$svgString = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="154" height="90" xml:space="preserve"><desc>Created with Fabric.js 1.5.0</desc><defs></defs><rect x="-76.5" y="-44.5" rx="0" ry="0" width="153" height="89" style="stroke: #FF0000; stroke-width: 0.5; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: white; fill-rule: nonzero; opacity: 1;" transform="translate(76.75 44.75)"/><g transform="translate(77 51.92)"><text font-family="Arial" font-size="22" font-weight="normal" style="stroke: #000; stroke-width: 0; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #000; fill-rule: nonzero; opacity: 1;" ><tspan x="-17.73" y="4.9412" fill="#000">àèìòù</tspan></text></g></svg>';
$pdf->ImageSVG('@' . $svgString, $x=80, $y=30, $w='', $h='', $link='', $align='', $palign='', $border='', $fitonpage=false);
//$pdf->writeHTML($html, true, 0, true, 0);
$pdf->SetFont('helvetica', '', 8);
$pdf->SetY(195);
$txt = '';
$utf8text = 'àèìòù';
$filename = 'example.pdf'
$pdf->Write(0, $utf8text, '', 0, 'L', true, 0, false, false, 0);
$pdf->Output($filename, 'D');
有人可以提供快速解答吗?