Sajan Emmanuel on Mon, 26 Jun 2017 06:44:30
I have a requirement to generate pdf documents from word templates and send e-mail with attachment. We are planning to develop the functionality as a kind of micro service in Azure Service Fabric. We have done POC with Aspose.Words for .NET in an Azure App
Service application and it is working fine. In my Azure App Service I am able to do the below things.
1) From a word document template(*.docx), I am able to generate a pdf with Aspose.Words for .NET with LINQ reporting engine and save the generated pdf to a memory stream.I am keeping the template in App_Data folder and access using the below code
string templateDir = HttpContext.Current.Server.MapPath("~/") + @"\App_Data"
2) Generate the PDF and save to a Memory stream like below
// Save to memory stream var dstStream = new MemoryStream(); doc.Save(dstStream, SaveFormat.Pdf); // Rewind the stream position back to zero so it is ready for next reader. dstStream.Position = 0;3) Using the .NET SmtpClient class, send the pdf as an attachment via SendGrid service like below
var mailMsg = new MailMessage(); mailMsg.To.Add(new MailAddress("email@example.com", "John Travolta")); mailMsg.From = new MailAddress("firstname.lastname@example.org", "John Travolta"); mailMsg.Subject = "Receipt"; string text = "Please find your receipt"; string html = @"<p>Please find your receipt</p>"; mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain)); mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html)); // Attach PDF as stream mailMsg.Attachments.Add(new Attachment(strm, filename)); SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", 587); NetworkCredential credentials = new NetworkCredential("apikey", apiKey); smtpClient.Credentials = credentials; smtpClient.Send(mailMsg);
Now I am planning to make it working in Azure Service Fabric probably in a stateless web api service. Since it is an Azure VM and SF has a sandbox environment, I have below queries.
1) Is it possible to perform such action in SF since this library demands the application to run under Windows Azure Full Trust. https://docs.aspose.com/display/wordsnet/About+Aspose.Words+and+Windows+Azure
2) Is it possible to keep some static template files in SF application(I am using Stateless Web Api template). I heard about data packages and not sure my requirement can be satisfied with the same.
3) Is SF is the right place to perform such operation or do I need to consider Azure Web App?
Since I can not find any example related to this, any feedback from SF Experts will be helpful.