How to export google chart in pdf?

前端 未结 2 849
忘掉有多难
忘掉有多难 2020-12-29 01:00

I have draw google chart. Now, I want to put button to save the chart in pdf format. I do look from here Save google charts as pdf and other questions available in stack but

2条回答
  •  我在风中等你
    2020-12-29 01:09

    You can use Mpdf to create pdf of google chart with store images,

    Step 1. create.php

    Use google method chart.getImageURI() to get image url then store into the variable after using jquery to submit form.

          
          
            
            
              
    
            
    
          

    step 2. createchartpdf.php

    Get HTML data to get images url and store into the images folder, and then retrieve images and content.

    print into pdf using mpdf. This is work with live server to print images.

            loadHTML($html);
                $tags = $doc->getElementsByTagName('img');
                $i=1;
                $result='';
                foreach ($tags as $tag) {
                    $file_name = 'images/google_chart'.$i.'.png';
                        $img_Src=$tag->getAttribute('src');
                            file_put_contents($file_name, file_get_contents($img_Src));
                    $res= '';
                    $result.=$res;
                  $i++;
                }
    
                //include make_pdf
                include("mpdf60/mpdf.php");
                $mpdf=new mPDF();
    
                $mpdf->allow_charset_conversion = true;
                $mpdf->SetDisplayMode('fullpage');
    
                $mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
                $mpdf->WriteHTML($result);
                $mpdf->Output();
            }
    
            ?>
    

提交回复
热议问题