php - Wrong utf8 character output savexml and tcpdf -
php - Wrong utf8 character output savexml and tcpdf -
hi i'm using tcpdf load svg file, manipulate , send pdf.
the svg file contain utf8 characters , after saving utf8 characters don't show properly.
here svg file
<?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>
and php code :
// 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 language dependent data: $lg = array(); $lg['a_meta_charset'] = 'utf-8'; //set language-dependent strings $pdf->setlanguagearray($lg); //$source : path 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 together page $pdf->addpage($orientation, '', false, false); //modify dom svg variable foreach ($_get $key => $value) { $gnodes=$xpath->query('//*[@id=\'' . $key . '\']'); foreach ($gnodes $gnode) { // doing stuff $gnode $gnode->nodevalue = $value; } } $txt = '@'.$dom->savexml(); $pdf->imagesvg($txt, $x=0, $y=0, $w='', $h='', $link='', $align='', $palign='', $border=1, $fitonpage=true); //close , output pdf document $pdf->output('utf8.pdf', 'i');
the pdf file after treatment show wrong utf-8 character : i'm expecting "äëïòû" in pdf , "äëïòû". answers.
$pdf = new tcpdf(pdf_page_orientation, pdf_unit, pdf_page_format, false, 'utf-8', false);
should be:
$pdf = new tcpdf(pdf_page_orientation, pdf_unit, pdf_page_format, true, 'utf-8', false);
if going using unicode encoding, unicode parameter should set true. assuming svg file saved utf-8, should work expect change.
php utf-8 svg tcpdf
Comments
Post a Comment