This may seem like a trivial question, I would like to open an existing pdf template, edit and flatten the file, then send as an email attachment. But how do I setup PdfReader to read my file located in my Content folder (Content/Documents/PDFFile.pdf). This is what I have which gives the error “(whatever path I try).pdf not found as a file or resource”.
using (MemoryStream ms = new MemoryStream())
{
//Error is here...
PdfReader reader = new PdfReader("~/Content/Documents/PDFFile.pdf");
PdfStamper formFiller = new PdfStamper(reader, ms);
AcroFields formFields = formFiller.AcroFields;
formFields.SetField("Name", formData.Name);
formFields.SetField("Location", formData.Address);
formFields.SetField("Date", DateTime.Today.ToShortDateString());
formFields.SetField("Email", formData.Email);
formFiller.FormFlattening = true;
formFiller.Close();
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("to@email.com"));
msg.From = new MailAddress("from@email.com");
msg.Subject = "Application Form";
msg.Body = "TEST";
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(ms, "Application.pdf", "application/x-pdf"));
SmtpClient client = new SmtpClient("10.1.1.15");
client.UseDefaultCredentials = true;
}
Any suggestions/ideas/recommendations?
Try using
Server.MapPath("/Path/Here.pdf");orRequest.PhysicalApplicationPath("/Path/Here.pdf");