I'm trying to generate a PDF report and I need the charts I generate for my HTML for the PDF file. I'm trying to send the image data to the server but when I try to load it into an image object it fails. Hoping you can help me.
-- Code on client side
kendo.drawing.drawDOM($("#ESChart"))
.then(function (group) {
return kendo.drawing.exportImage(group);
})
.done(function (data) {
chartData = encodeURI(data);
$.ajax({
method: "POST",
data: chartData,
url: "/Home/CreateFacilityReport" + location.search,
})
.done(function (msg) {
alert(msg);
})
.fail(function (data) {
alert("Failed to load svg");
});
});
-- Code on server side
public ActionResult CreateFacilityReport(string FacilityId, string chartData)
{
string myData = HttpUtility.UrlDecode(chartData.ESChart);
byte[] myBytes = Encoding.ASCII.GetBytes(myData);
using (var ms = new MemoryStream(myBytes))
{
Image myImage = Image.FromStream(ms, true, false); <---- Blows up here and gets a 'Parameter is not valid'
myImage.Save("/ESChart.png");
}
}