2012-12-04 20 views

回答

4

好吧,读过这篇文章,我认为你在问什么是如何发送PDF作为电子邮件的附件,而不是通过浏览器将其发送给用户。

在链接的代码包括这一部分,我假设你将能够识别和定位在自己的代码:

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文档的字节数组。因此,您只需将其保存到磁盘即可:

using(FileStream fs = new FileStream("your file name.pdf", FileMode.Create)) 
{ 
    fs.Write(buffer, 0, buffer.Length); 
} 

然后,您可以使用您的文件创建电子邮件附件。