将Google图表另存为pdf

Lea*_*011 3 javascript php google-visualization

我试图将 饼图保存为pdf文件,如http://keepcoding.ehsanabbasi.com/php/convert-google-chart-to-png-and-pdf/在php.chartsrc中使用javascript显示以下值而不是png图像源

" function (){if(!this.b||!this.$||!this.Ua)throw m("Chart has not finished drawing.");var a=new Ql(this.V,this.Aa),b=Tl(this.ma)[Wb](ih),a=YO(b,a),a=new EO(b,a),c=new RO(b),a=this.sO(c,a),c=yY(this.ig,this.$,this.Ua);a.Lp(this.$,c);return b[cc][0].toDataURL(Ssa)} failed (filesystem path '/var/www/html/function (){if(!this.b||!this.$||!this.Ua)throw m("Chart has not finished drawing.");var a=new Ql(this.V,this.Aa),b=Tl(this.ma)[Wb](ih),a=YO(b,a),a=new EO(b,a),c=new RO(b),a=this.sO(c,a),c=yY(this.ig,this.$,this.Ua);a.Lp(this.$,c);return b[cc][0].toDataURL(Ssa)}')"

 $script ="

        google.setOnLoadCallback(drawChart);
        function drawChart() { //code for drawing chart}
        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        google.visualization.events.addListener(chart, 'ready', function ()      {
        var chartsrc = chart.getImageURI();
     });

      $doc->addScriptDeclaration($script);
      echo "<div id='piechart'></div>";
Run Code Online (Sandbox Code Playgroud)

Kev*_*own 10

我们在@cloudformatter中添加了支持,以支持所有Google图表输出为PDF,图像,XPS和其他格式.您可以查看下面的链接.

Google Charts @cloudformatter支持页面:http://www.cloudformatter.com/GoogleCharts

整个Javascript的文档:http: //www.cloudformatter.com/CSS2Pdf.APIDoc.Usage

在Google Charts网页上有一些关于实现Handler的提示,该Handler在图表绘制后将SVG名称空间添加到生成的SVG中.

您可以从顶部的菜单中进行选择以格式化整个页面,甚至可以从内联菜单中选择仅将特定图表格式化为PDF(或其他格式).

这里还有一个小提琴:http : //jsfiddle.net/zvx6eb7e/10/,在PDF按钮后面生成PDF的代码只有这样:

var click="return xepOnline.Formatter.Format('JSFiddle', {render:'download', srctype:'svg'})";
jQuery('#buttons').append('<button onclick="'+ click +'">PDF</button>');
Run Code Online (Sandbox Code Playgroud)

我会注意到一件事 - 这不是图像到PDF的图表,这是向量到PDF的图表,用于最高分辨率和最佳数据表示.