Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey I was wondering if anybody knew how to save charts as an image, preferrable pdf. I have a chart dynamically created and have tried a couple things including the following.
C#
protected void btnSaveImage_Click(object sender, EventArgs e)
        {
            chrAdvertising.SaveImage( chrAdvertising.CurrentImageLocation, ChartImageFormat.Png);
            CommonHelper.WriteResponseImage(Server.MapPath("~/TempImages/" + chrAdvertising.CurrentImageLocation), "defaultName.png");
        }

With asp.net chart code starting as
<asp:Chart ID="chrAdvertising" runat="server" BackColor="211, 223, 240" ImageUrl="~/TempImages/ChartPic_#SEQ(300,3)"


Where chrAdvertising is the name of the chart and commonhelper.writeResponseImage brings up a window directing the user to where you can save the image (which works with other images already on the server). The problem is the image isn't acutally stored in the TempFolder I assigned it. If you have a better understanding of the chart feature and where the image is stored between postbacks or if it is lost between postbacks, please explain.

Also if you know how to convert the image to pdf that would save me from asking a seperate question :)
Thanks ~MJ
Posted

1 solution

Hi
What you want to do exactly.

You've image and then you've write it in pdf file right.

you can write any thing in pdf files in asp.net by using iTextSharp library

If you don't've idea on iTextSharp checkout links for sample codes.

http://www.developerfusion.com/code/5682/create-pdf-files-on-fly-in-c/

and there is a open source pdf library for asp.net

http://www.webresourcesdepot.com/open-source-pdf-library-for-aspnet-pdfsharp/

checkout those two links you can get clear idea on handling pdf files in asp.net

you can add text,image and charts to PDF file.

Here you are using some tempfolder for saving charts right its better to use session variable or application variable for storing charts

It can easy accessable and easily deletable.


try steps mentioned in above links you'll get good output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900