I need this done server side.
The scenario is that I am generating pdf reports using itextsharp, I would like to include graphs generated dynamically on another webpage by first calling the page and then passing back the base64 representation of the image through a return value.
Hopefully the explanation is clear enough to understand, I don’t want the called webpage displayed to the user and don’t want to save the image to the file system first, hence this approach.
Any ideas / code examples would be appreciated.
If all you are after is the graph that’s generated on the other page, you should move the generation of the graph to a separate method that both pages can call. If you want the output from a Chart.Write call, you should put the code that creates and outputs
the chart in a Helper.
Hello Mike, thanks for the reply
var pngUrl = canvas.toDataURL()
so it can be returned to my .cshtml page.
I just have very little idea on how to make the initial call from my .cshtml page to the chart generation page (.cshtml) and then make sure the only thing returned is the ‘pngUrl’, or event if this is possible.
(I wont be using the chart helper at all).
You should still separate the generation of the chart from the page. You can move your js into a separate file and call it from both pages. The alternative is to request the other page (using
HttpClient) and then parse the source code.