0
votes

I'm using kineticJS to make a chart, so it's an html page that generates a chart drawing in a Div. in php, I want to include an image of that chart in a pdf I'm generating. KineticJS can convert the canvas to an image, but how can I get that image in a php script?

what I want is something like

<?php
  $html="<img src='graph.html?x=20'></img>";
  pdf->AddHTML($html);
  $pdf->output();
?>

I'm a little bit lost on how I should be doing this. Ideally, the pdf should also embed the image. I'm not asking about the pdf stuff. I'm asking basically how you can get an image generated from KineticJS into a php script, as a base64 data or whatever.

do I need something like phantomJS running in order to do it?

1

1 Answers

0
votes

You can use the toDataURL function to get the image and then upload it to php

stage.toDataURL({
    callback: function(dataUrl) {
        /*
         * here you can do anything you like with the data url.
         * In this tutorial we'll just open the url with the browser
         * so that you can see the result as an image
         */
         window.open(dataUrl);
     }
});

See http://www.html5canvastutorials.com/kineticjs/html5-canvas-stage-data-url-with-kineticjs/