简体   繁体   中英

Duplicated svg image output TCPDF

I would like to export some charts made by ExtJs in PDF using TCPDF. I'm processing like that for passing html code to TCPDF:

var activeTabId = Ext.getCmp('tabs').activeTab.id
            , activeTab = Ext.getCmp('tabs').activeTab
            , svgHtml = '@<svg version="1.1" style="width: 700px; height: 400px;" xmlns="http://www.w3.org/2000/svg">'
            , html=''
            , svg = $("#"+activeTabId+" svg")
            , svgArray=[];

        svg.each(function(){
            svgArray.push(svgHtml+svg.html()+'</svg>');
            html+= svgHtml+svg.html()+'</svg>';
        });

        svgJSON = JSON.stringify(svgArray);

        $.post('tcpdf/examples/example_058.php', { svg : svgJSON }, function(data){
            //window.location.href='tcpdf/examples/example_058.pdf';
            console.log(data);
        });

And then i'm using the examples 058 which draw svg image. Here's the code :

$svg = isset($_POST['svg'])?json_decode($_POST['svg']):NULL;
$yDepart = 30;
$svgHeight = 200;
echo '{ svgLength :'.count($svg).'}';
for($i=0;$i<count($svg);$i++){
    $pdf->AddPage('P', $page_format, false, false);
    $pdf->ImageSVG($svg[$i], $x=0, $y=$yDepart, $w=350.0, $h=400.0, $link='', $align='M', $palign='C', $border=0, $fitonpage=true);
}

The problem is that the Output PDF contains the same duplicated chart. Thank you for reading.

I found the mistake :

Here's the problematic code :

svg.each(function(){
            svgArray.push(svgHtml+svg.html()+'</svg>');
            html+= svgHtml+svg.html()+'</svg>';
        });

I changed it by this one :

svg.each(function(){
    svgArray.push(svgHtml+$(this).html()+'</svg>');
    html+= svgHtml+$(this).html()+'</svg>';
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM