如何使用iTextSharp的生成和保存视图在MVC3(剃刀)PDF [英] How to generate and save view as pdf in mvc3(razor) using itextsharp
问题描述
HTTP://www.codeproject.com /用品/ 260470 / PDF报告方法使用-ASP-NET-MVC3
我已经用在上面的链接,并在保存生成的PDF发现问题给出的code。所以,请给我一个想法,用于保存PDF,这样我可以能够在邮件发送出去。
I have used the code given in above link and finding the issue in saving the generated pdf. So please give me an idea for saving the pdf, so that I could able to send it in mail.
推荐答案
OK,看了这篇文章,我的认为的你所问的是如何将PDF作为附件发送到电子邮件,而它比流式传送到浏览器中的用户
OK, having read the article, I think what you are asking is how to send the PDF as an attachment to an email rather than stream it to the user in the browser.
在链接中的code包括这一部分,我假设你将能够识别和定位自己的code:
The code in the link includes this segment, which I assume you'll be able to recognize and locate in your own code:
string htmlText = this.htmlViewRenderer.RenderViewToString(this, viewName, model);
// Let the html be rendered into a PDF document through iTextSharp.
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
在这一点上,你将有一个包含PDF文档的字节数组。因此,所有你需要做的将其保存到磁盘是这样的:
At that point you would have a byte array containing a PDF document. So all you have to do to save it to disk is this:
using(FileStream fs = new FileStream("your file name.pdf", FileMode.Create))
{
fs.Write(buffer, 0, buffer.Length);
}
您就可以使用您的文件创建一个电子邮件附件。
You can then use your file to create an email attachment.
这篇关于如何使用iTextSharp的生成和保存视图在MVC3(剃刀)PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!