Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am giving sample example

it is opening pdf file but data is not played


C#
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=sample.pdf");
Response.ContentType = "application/pdf";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<table cellpadding=2 cellspacing=1 border=1 width=800 height=500>");
sb.Append ("<tr>");
sb.Append("<td>column-1</td><td>column-2</td><td>column-3</td><td>column-4</td><td>column-5</td><td>column-6</td><td>column-7</td><td>column-8</td>");
sb.Append ("</tr>");
sb.Append ("<tr>");
sb.Append ("<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td>");
sb.Append ("</tr>");
sb.Append("</table>");
Response.Write(sb.ToString ());
Response.End();


Edit TR - Please use <pre> tags around your code, makes it easier to read.
Posted
Updated 7-Apr-10 23:25pm
v2

1 solution

This will not work. The response you are sending the browser is an HTML file, not a PDF. Setting Response.ContentType is not enough to produce the PDF.

You're going to want to look at a library such as iTextSharp[^]to create the PDF. You can then send the generated file in the response.
 
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