直接保存生成的PDF到服务器的目录文件夹,无用户提示 [英] Save the generated pdf directly to the server directory folder without user prompt

查看:455
本文介绍了直接保存生成的PDF到服务器的目录文件夹,无用户提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个朋友给了我这项​​任务,所以我可以提前学习编程稍微容易一些。我目前在做一个HTML页面的皈依利用iText锋利PDF并通过电子邮件发送一份PDF文件attachement。我的想法是先保存的PDF文件夹名称ToBeEmailedPDF文件夹中的服务器计算机使用它作为电子邮件附件发送之前。困扰我的事情是,这个对话框,你可以在图片中看到显示出来使用code,我有以下。

A friend of mine gave me this task so I can learn advance programming a little bit easier. I am currently doing convertion of an html page to pdf using itext sharp and email the pdf as an attachement. My idea is to save the pdf first to the server machine in the folder name ToBeEmailedPDF folder before using it as an email attachment. The thing that bothers me is that this dialog as what you can see in the picture shows up using the code that I have below.

StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
pnlPDF.RenderControl(hw); // pnlPDF contains the html contents to be converted to pdf
string htmlDisplayText = sb.ToString();
Document document = new Document();
MemoryStream ms = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, ms);
StringReader se = new StringReader(htmlDisplayText);
HTMLWorker obj = new HTMLWorker(document);
document.Open();
obj.Parse(se);
// step 5: we close the document
document.Close();
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=report.pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
Response.OutputStream.Flush();
Response.End();

我知道你们许多人在那里知道一个更好的方法或不知道如何解决我的问题。请帮帮我。谢谢!

I know many of you out there knows a better way or know how to solve my problem. Please help me. Thank you!

推荐答案

有是客户端和服务器端之间很大的区别。

There is big difference between client-side and server-side.

响应类可以输出内容的客户端机器,如果您需要保存在服务器上使用类似文件 File.WriteAllBytes MSDN )方法。

Response class can output contents to client machine, if you need to save file on server use something like File.WriteAllBytes (msdn) method

这篇关于直接保存生成的PDF到服务器的目录文件夹,无用户提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆