【发布时间】:2014-01-05 06:30:38
【问题描述】:
我想将 Div 内容转换为 pdf 并将创建的 pdf 文件保存在服务器路径上,而不要求我保存文件(下载文件)。
我转换了 pdf 文件并将该文件保存在服务器路径中。
但在我的代码中,它还显示了我要删除的文件下载选项。
我不想将 pdf 文件另存为选项,因为我将创建的文件保存在服务器路径中。
下面是我的代码:
string appPath = HttpContext.Current.Request.ApplicationPath;
string path = Server.MapPath(appPath + "/Attachment/Test.pdf");
if (File.Exists(path))
File.Delete(path);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
createDiv.RenderControl(hw);
var output = new FileStream(path, FileMode.Create);
StringReader sr = new StringReader(sw.ToString());
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.End();
谢谢, 希特什
【问题讨论】: