Question

http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3

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.

Was it helpful?

Solution

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.

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);

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top