Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Html到pdf转换器_Asp.net_C# 4.0_Html To Pdf - Fatal编程技术网

Asp.net 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

我的要求是将Html转换为pdf转换器,我是通过代码实现的。但现在我的要求是如何保存到文件夹中

 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();