嗨,我想通过使用asp.net应用程序获取当前页面源代码。我发现了一段代码将HTML转换为PDF,但为了将我的页面转换为PDF,我需要获取页面的HTML代码。我怎样才能得到这些字符串?我简单的代码是这样的:如何从asp.net获取当前页面源代码页面
string sPathToWritePdfTo = Server.MapPath("") + "/pdf_dosya_adi.pdf";
System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();
sbHtml.Append("");
sbHtml.Append("
");sbHtml.Append("HTML den PDF çevirme Test");
sbHtml.Append("
");
sbHtml.Append("Body kısmında yazacak yazı");
sbHtml.Append("");
sbHtml.Append("");
using (System.IO.Stream stream = new System.IO.FileStream
(sPathToWritePdfTo, System.IO.FileMode.OpenOrCreate))
{
Pdfizer.HtmlToPdfConverter htmlToPdf = new Pdfizer.HtmlToPdfConverter();
htmlToPdf.Open(stream);
htmlToPdf.Run(sbHtml.ToString());
htmlToPdf.Close();
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "friendlypdfname.pdf"));
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.WriteFile(sPathToWritePdfTo);
HttpContext.Current.Response.End();
如果我能得到HTML代码关闭我的asp.net页面,我把我的网页上的所有行成 sbHtml.Append(“”); 代码通过使用for循环,这将解决我的问题在我看来。