有什么方法可以将Highcharts与mPDF转换器一起使用?

问题描述 投票:3回答:1

此问题与HTMLtoPDF转换器有关。

mPDF转换器可以在附带的CSS上正常工作,但不能与任何Bootstrap表或任何svg元素一起正常工作。

如何在mPDF中包括js中的js?

php svg highcharts mpdf html2pdf
1个回答
5
投票

mPDF不支持JavaScript。但是,您可以使用以下方法之一:

  1. 使用类似$('svg')[0].outerHTML的方法检索图表的SVG代码,并将其发送到服务器以作为图像插入生成的PDF。

  2. 使用Highcharts导出服务来生成可插入PDF的图像(SVG或其他格式)。代码如下:

    var chart = $('.mychart').highcharts();
    var opts = chart.options;        // retrieving current options of the chart
    opts = $.extend(true, {}, opts); // making a copy of the options for further modification
    delete opts.chart.renderTo;      // removing the possible circular reference
    
    /* Here we can modify the options to make the printed chart appear */
    /* different from the screen one                                   */
    
    var strOpts = JSON.stringify(opts);
    
    $.post(
        'http://export.highcharts.com/',
        {
            content: 'options',
            options: strOpts ,
            type:    'image/svg+xml',
            width:   '1000px',
            scale:   '1',
            constr:  'Chart',
            async:   true
        },
        function(data){
            var imgUrl = 'http://export.highcharts.com/' + data;
            /* Here you can send the image url to your server  */
            /* to make a PDF of it.                            */
            /* The url should be valid for at least 30 seconds */
        }
    );
    

    您可以在http://export.highcharts.com/上尝试不同的通话选项。另请参见http://www.highcharts.com/docs/export-module/export-module-overview

请注意,mPDF不支持某些SVG属性,因此您可以考虑将图表导出为光栅图像。


0
投票

我尝试过,但是当我从HighCharts服务器获取图像的路由时,出现了错误404。可能会发生什么?

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.