Asp.net Html到pdf转换器
我的要求是将Html转换为pdf转换器,我是通过代码实现的。但现在我的要求是如何保存到文件夹中Asp.net Html到pdf转换器,asp.net,c#-4.0,html-to-pdf,Asp.net,C# 4.0,Html To Pdf,我的要求是将Html转换为pdf转换器,我是通过代码实现的。但现在我的要求是如何保存到文件夹中 Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Certificate.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); System.Text.St
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=Certificate.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.Text.StringBuilder ss = new System.Text.StringBuilder(CertificateHtml);
StringWriter sw = new StringWriter(ss);
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
请帮助。您可以在
响应后尝试此操作。写入(pdfDoc)代码>
除此之外,您正在使用的第三方工具或PDF生成也可能为您提供此操作的功能。使用此工具
string fileName = DateTime.Now.Ticks.ToString();
string filepath = Server.MapPath("~") + fileName + ".pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/pdf";
Response.TransmitFile(filepath);
Response.End();
你什么意思?这是处理程序的代码,用于将pdf发送到浏览器。
string fileName = DateTime.Now.Ticks.ToString();
string filepath = Server.MapPath("~") + fileName + ".pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/pdf";
Response.TransmitFile(filepath);
Response.End();