Basically I just need the pdf to send. Once a questionnaire is filled out a report is to be emailed as a pdf to the persons who filled it in. The report relates to certain umbraco nodes etc. It's simple enough to download but it's a data mining excersise and the pretext is give us your email get a free report... if we don't mail it and just allow a download then there's no pretext so to speak.
You'd need to write the code to save it to disc and send it as an attachment, which should be pretty straightforward - but it isn't part of the package.
Aaah that's the problem I can see a PDF generated in the browser but no idea on how to save it to the server. I guess once it's saved and I know where it is a simple script could mail it but the step whereby it saves rather than renders eludes me.
OK I am stuck on this so I think I need to step back and understand what it is this package does.
My goal is to simply email the PDF without exposing it to the browser. But where is the PDF at what point is a PDF created and where is it held. It appears to be in a memory stream but at what point can I access it and send it on it's way.
I can either mail it from the memory stream but don't know how to reference it. Or I can save it to a folder on the server and mail it from there, but again I don't know how to consolidate it and save it.
Has anyone done anything with this package other than render the PDF to the browser or download the pdf ?
I use this code to download the generated pdf stream. PDFGeneratorDocuments is a my class to generate the PDF with MigraDoc.
The important line is return File to download stream file.
PDFGeneratorDocuments PDFGeneratorDocumentsManager = new PDFGeneratorDocuments();
var memStream = PDFGeneratorDocumentsManager.GetDDTinPDF(stampaView);
string nomefile = stampaView.HeaderDDT.NumMov + ".pdf";
return File(memStream.ToArray(), "application/pdf", nomefile);
and this one to attach to email ( I use System.Net.Mail )
bool emailHtml = true;
string filePath = PDFHelper.ElaboraDatiToPDF(dataInfo); //path to PDF file on disk
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(emailTo);
mail.Subject = emailSubject;
mail.Body = emailBody;
mail.IsBodyHtml = emailHtml;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(filePath);
mail.Attachments.Add(attachment);
SmtpServer.Send(mail);
}
catch (Exception ex)
{
Log.Add(LogTypes.Error, 0, "Error send email " + ex.Message);
}
EMAIL PDF as an attachment.
With this package, is it possible to email the final PDF as an attached file rather than render inside the browser.
Doogie
Do you need only attach the pdf file or generate, attach and send?
Basically I just need the pdf to send. Once a questionnaire is filled out a report is to be emailed as a pdf to the persons who filled it in. The report relates to certain umbraco nodes etc. It's simple enough to download but it's a data mining excersise and the pretext is give us your email get a free report... if we don't mail it and just allow a download then there's no pretext so to speak.
You'd need to write the code to save it to disc and send it as an attachment, which should be pretty straightforward - but it isn't part of the package.
Aaah that's the problem I can see a PDF generated in the browser but no idea on how to save it to the server. I guess once it's saved and I know where it is a simple script could mail it but the step whereby it saves rather than renders eludes me.
You'd need to do something like this:
http://www.csharp-examples.net/download-files/
From your own code, request the PDF URL and save it to disc (in a temp folder), then write the c# code to send an email and attach it.
Does that help at all?
Thanks.
Aaah I can't get this to work without showing the PDF to the browser.
OK I am stuck on this so I think I need to step back and understand what it is this package does.
My goal is to simply email the PDF without exposing it to the browser. But where is the PDF at what point is a PDF created and where is it held. It appears to be in a memory stream but at what point can I access it and send it on it's way.
I can either mail it from the memory stream but don't know how to reference it. Or I can save it to a folder on the server and mail it from there, but again I don't know how to consolidate it and save it.
Has anyone done anything with this package other than render the PDF to the browser or download the pdf ?
Hi,
I suggest to read this article and project
http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version
I use this code to download the generated pdf stream. PDFGeneratorDocuments is a my class to generate the PDF with MigraDoc. The important line is return File to download stream file.
and this one to attach to email ( I use System.Net.Mail )
Bye
Thanks for that using similar principles I have managed on first instance to make PDF Generator package do what I need.
I have a ways to go put in some proper checks and balances but this is what I have come up with that works in Razor and doesn't stress the server.
is working on a reply...