Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

can anyone help me out of my problem.
I am displaying chart and some data above the chart.I need to export this data to PDF On the Fly.
I can Export HTML to PDF and but not able to export chart image.
I can Export Chart(SVG code) to image without HTML.

Thank you.

additional information copied from comment below
For PDF conversion i am using iTextsharp.dll
Following code:
C#
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

And for Convert chart to Image, I am using Svg.dll (which converts SVG containing chart data to Image).Following is code.

C#
string svgFileContents = divChart.InnerText;            
var byteArray = Encoding.ASCII.GetBytes(svgFileContents);
using (var stream = new MemoryStream(byteArray))
{
   var svgDocument = SvgDocument.Open(stream);
   var bitmap = svgDocument.Draw();
   //bitmap.Save(path, ImageFormat.Png);

   using (MemoryStream ms = new MemoryStream())
   {
      bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
      ms.WriteTo(HttpContext.Current.Response.OutputStream);
      Response.ContentType = "image/png";
   }
                
}
Posted
Updated 19-Oct-13 16:39pm
v3
Comments
Nelek 18-Oct-13 8:21am    
AbidHussain128 19-Oct-13 0:02am    
Hi Nelek,

Thanks for your interest,
For PDF conversion i am using iTextsharp.dll
Following code:
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

And for Convert chart to Image, I am using Svg.dll (which converts SVG containing chart data to Image).Following is code.
string svgFileContents = divChart.InnerText;
var byteArray = Encoding.ASCII.GetBytes(svgFileContents);
using (var stream = new MemoryStream(byteArray))
{
var svgDocument = SvgDocument.Open(stream);
var bitmap = svgDocument.Draw();
//bitmap.Save(path, ImageFormat.Png);

using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.WriteTo(HttpContext.Current.Response.OutputStream);
Response.ContentType = "image/png";
}

}
AbidHussain128 19-Oct-13 0:03am    
I am not have yet good idea, how can i achieve this.

1 solution

I have complete it by self.

Following is solution for my case, i am writing, if others have same issue.
1.I have download svg.dll from net and conver my svg code to Png file and store it in one folder.
2. Prepage one HTML file with Replace ##Chart## at place of my svg chart.
3. Use PDFTron.dll and HTMLtoPDF.dll from PdfTron and Generate PDF of this HTML with placing Image tage at place of ##Chart##, on the Fly.

- PDFTron link: http://www.pdftron.com/pdfnet/downloads.html[^]

Thank you.
 
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