0
我想事业部内容转换为PDF格式,节省服务器的路径上创建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();
感谢, 亚太区首席技术官Matt
感谢。它的工作正常。还有一个问题是有可能,但不保存为PDF文件,我可以得到PDF文件的字节数组,因为我保存PDF的字节到数据库中。 – Hitesh
'MemoryStream'用于保存内存中的文件,而不是用于访问文件系统的'FileStream'。 – jaypeagi
嗨,我没有得到你的答案。你可以在我的代码中给我指导,我必须改变它。 – Hitesh