This is my code:
function canvasToImage(canvas,backgroundColor)
{
//cache height and width
var w = canvas[0].width;
var h = canvas[0].height;
j("#tempcanvas").attr('width',w).attr('height',h);
var newCanvas = j("#tempcanvas")[0];
var newContext = newCanvas.getContext("2d");
newContext.clearRect(0,0,w,h);
var allData = newContext.getImageData(0, 0, w, h);
j(canvas).each(function(){
var context = j(this)[0].getContext("2d");
var imageData = context.getImageData(0, 0, w, h);
var pixels = 4 * w * h;
while (pixels--) {
allData.data[pixels] = allData.data[pixels] +
imageData.data[pixels];
}
});
newContext.putImageData(allData, 0,0);
newContext.globalCompositeOperation = "destination-over";
newContext.fillStyle = backgroundColor;
newContext.fillRect(0,0,w,h);
//get the image data from the canvas
var imageData = newCanvas.toDataURL("image/png");
//return the Base64 encoded data url string
return imageData;
}
var canvas = j(".jqplot-series-canvas");
var data = canvasToImage(canvas,"#ffffff");
-------
This "data" you can send to server and save in image file. After that
on the server side you can generate PDF with this image. For generate
PDF you can use
http://www.tcpdf.org/ (PHP).
On Apr 14, 2:24 am, Chris Leonello <
jqplot-us...@jqplot.com> wrote:
> //get the image data from the canvas
> var imageData = canvas.toDataURL("image/png");
>
> This is correct. Plots are composed of a number of canvases plus div elements and possibly table elements, though. They need to be positioned and collapsed or otherwise rendered into one canvas to get a complete image of a plot. A number of details to take care of.
>
> If anyone has ideas on PDF generation (maybe through SVG conversion?), let me know.
> --
> Chris Leonellohttp://
www.jqplot.com
>
>
>
> On Wednesday, April 13, 2011 at 1:29 AM, golubev wrote:
> > //get the image data from the canvas
> > var imageData = canvas.toDataURL("image/png");
>
> > See alsohttp://
www.w3.org/TR/html5/the-canvas-element.html#dom-canvas-todataurl