0
Answer

PDF Conversion

Ask a question
Venkat

Venkat

18y
1.8k
1
How to convert a given .htm file to .pdf file.

I used the following code and it is generating the .pdf file but the file is getting generated with some errors. can any 1 help with the same.

WebRequest mywebReq ;

WebResponse mywebResp ;

StreamReader sr ;

string strHTML ;

StreamWriter sw;

mywebReq = WebRequest.Create("C:\\w.htm");

mywebResp = mywebReq.GetResponse();

sr = new StreamReader(mywebResp.GetResponseStream());

strHTML = sr.ReadToEnd();

Response.ContentType = "application/pdf";

//Response.AddHeader("Content-Type", "application/pdf");

//Response.ContentEncoding.CodePage.GetType("Content-Type","application/pdf");

//Response.ContentType = ("application/pdf");

//sw = File.CreateText(Server.MapPath("temp.pdf"));

sw = File.CreateText(Server.MapPath("temp1.pdf"));

sw.Encoding.GetDecoder();

sw.BaseStream.CanSeek.ToString();

sw.WriteLine(strHTML);

sw.Close();

Response.WriteFile(Server.MapPath("temp1.pdf"));

//Response.BinaryWrite(Server.MapPath("temp.pdf"));

Response.Write("Successfully Created");