FLOT data as image to write to PDF

前端 未结 4 1042
星月不相逢
星月不相逢 2020-12-10 18:24

I am using jQuery/FLOT to draw a graph, I would like for the user to be able to download a PDF version of the graph. I am writing the PDF using ColdFusion. After creating th

4条回答
  •  粉色の甜心
    2020-12-10 18:48

    You could render the chart on the server with a headless browser like phantomJS (WebKit engine).

    You only need a script that takes an URL and renders the output as a Base64 encoded string to the console stream or writes an image.

    As far as I know it's the only semi browser-independent way to do this.

    Here's a script for phantomjs that outputs a given web page as base64 encoded image-string:

    var page = require('webpage').create();
    var system = require('system');
    
    var pageUrl = system.args[1];
    
    page.viewportSize = { width: 1280, height: 720 };
    page.open(pageUrl , function () {
        console.log(page.renderBase64('PNG'));
        phantom.exit();
    });
    

提交回复
热议问题