Export PDF file in C#
-
hi all, I want export the pdf file.and I am using following code.In my system .But an error is displaying like adobe readercould not open 'down.pdf' because it is either not a supported file type or because the file has been damaged... DataSet Ds = FillGrid2(sessionvalue, cid, cmid, crid, pid, sdate, edate); Response.Clear(); Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-disposition", "attachment; filename=Download.pdf"); string str = "<table style='border:1px solid #000000;'>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Client: </b>" + client + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Campaign: </b>" + campaign + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Report Summary</b>" + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td>" + "Type" + "</td>"; str += "<td>" + "Impression" + "</td>"; str += "<td>" + "Clicks" + "</td>"; str += "<td>" + "Start Date" + "</td>"; str += "<td>" + "End Date" + "</td>"; str += "</tr>"; for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { str += "<tr style='border:1px solid #000000;'>"; for (int j = 0; j < Ds.Tables[0].Columns.Count; j++) { str += "<td>" + Ds.Tables[0].Rows[i][j].ToString() + "</td>"; } str += "</tr>"; } str += "</table>"; Response.Write(str); If anybody knows please reply me.. thanks...
Raaj
-
hi all, I want export the pdf file.and I am using following code.In my system .But an error is displaying like adobe readercould not open 'down.pdf' because it is either not a supported file type or because the file has been damaged... DataSet Ds = FillGrid2(sessionvalue, cid, cmid, crid, pid, sdate, edate); Response.Clear(); Response.AppendHeader("Content-Type", "application/pdf"); Response.AppendHeader("Content-disposition", "attachment; filename=Download.pdf"); string str = "<table style='border:1px solid #000000;'>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Client: </b>" + client + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Campaign: </b>" + campaign + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td colspan='5'>" + "<b>Report Summary</b>" + "</td>"; str += "</tr>"; str += "<tr>"; str += "<td>" + "Type" + "</td>"; str += "<td>" + "Impression" + "</td>"; str += "<td>" + "Clicks" + "</td>"; str += "<td>" + "Start Date" + "</td>"; str += "<td>" + "End Date" + "</td>"; str += "</tr>"; for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { str += "<tr style='border:1px solid #000000;'>"; for (int j = 0; j < Ds.Tables[0].Columns.Count; j++) { str += "<td>" + Ds.Tables[0].Rows[i][j].ToString() + "</td>"; } str += "</tr>"; } str += "</table>"; Response.Write(str); If anybody knows please reply me.. thanks...
Raaj
Maybe I misunderstood, but are you assuming that writing HTML code and setting the content-type to 'application/pdf' will give you a valid PDF file? That's totally wrong!! You should use a PDF library for that. I recommend PDF Sharp, which is free. Also, use the StingBuilder class if you want to append characters to an existing string. It's far more efficient.