Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i made multiple pie chart dynamically and add them into a placeholder in C# .net, and now i m facing problem when i convert that page html into pdf file.

It show "Error!Illegal characters in path".

I searches any solution from few days.
Any one please suggest me any solution ASAP.

What I have tried:

Chart txtChart = new Chart();
txtChart.ID = "txtChart" + rowIndex;
txtChart.Titles.Add("Q.No." + formFieldData.Survey_FormFields_Order + ". " + formFieldData.Survey_FormFields_Text);
txtChart.Font.Bold = true;
txtChart.RenderType = RenderType.ImageTag;


DataTable dt = dtChart;
string[] x = new string[dt.Rows.Count];
int[] y = new int[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][2].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][3]);
}

Series txtSeries = new Series();
txtSeries.Name = "txtSeries" + rowIndex;
txtSeries.Points.DataBindXY(x, y);
txtSeries.ChartType = SeriesChartType.Pie;
txtSeries.LegendText = "#VALX";

foreach (DataPoint point in txtSeries.Points)
{
point.Label = "#PERCENT";
point.ToolTip = "#VALX\n#PERCENT";
}

Legend txtLegend = new Legend();
txtLegend.Name = "txtSeries" + rowIndex;
txtLegend.Alignment = System.Drawing.StringAlignment.Center;
txtLegend.Docking = Docking.Right;
txtLegend.IsTextAutoFit = false;
txtLegend.LegendStyle = LegendStyle.Column;
txtLegend.Enabled = true;
txtLegend.Title = _strResultOptions;// "overall results";
txtLegend.IsDockedInsideChartArea = false;

txtSeries.EmptyPointStyle.IsVisibleInLegend = false;
txtSeries.EmptyPointStyle.IsValueShownAsLabel = false;

ChartArea txtChartArea = new ChartArea();
txtChartArea.Name = "txtChartArea" + rowIndex;
txtChartArea.BorderWidth = 0;
txtChartArea.Area3DStyle.Enable3D = true;

txtChart.Series.Add(txtSeries);
txtChart.ChartAreas.Add(txtChartArea);
txtChart.Legends.Add(txtLegend);

txtChart.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Bmp;
txtChart.ImageStorageMode = ImageStorageMode.UseHttpHandler;

txtChart.Width = new System.Web.UI.WebControls.Unit(500, System.Web.UI.WebControls.UnitType.Pixel);
txtChart.Height = new System.Web.UI.WebControls.Unit(250, System.Web.UI.WebControls.UnitType.Pixel);

phChartArea.Controls.Add(txtChart);
phChartArea.Controls.Add(new LiteralControl(""));

______________________________________________________________________________

html into pdf file code
------------------------

System.IO.StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

phChartArea.RenderControl(htmlWrite);

StringReader reader = new StringReader(stringWrite.ToString());

Document doc = new Document(PageSize.A4);
HTMLWorker parser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
parser.Parse(reader);
doc.Close();

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(doc);
Response.End();

______________________________________________________________________________
Posted
Comments
Sergey Alexandrovich Kryukov 8-Jun-16 1:47am    
And what is that path?
—SA
Anand Saini 8-Jun-16 2:48am    
there is no specific path i am given
Sergey Alexandrovich Kryukov 8-Jun-16 9:40am    
Specific or not... I'm just trying to address your message: "Error! Illegal characters in path". It means, there is a path at this moment. I want to know the value of this string, what is that path? After all use the debugger and see where that path comes from.
—SA
Anand Saini 8-Jun-16 12:33pm    
ok i will also try it

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