【发布时间】:2011-06-02 19:27:35
【问题描述】:
我有一个模板,我想对其进行编辑并通过电子邮件发送。我有以下代码,但编辑后的 pdf 显示我的数据“已损坏且无法修复”。我不确定我是否正在提取要发送的编辑后的 pdf。任何帮助表示赞赏。
using (MemoryStream ms = new MemoryStream())
{
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;
ms.Position = 0;
msg.Attachments.Add(new Attachment(ms, "Application.pdf", "application/x-pdf"));
SmtpClient client = new SmtpClient("10.1.1.15");
client.UseDefaultCredentials = true;
}
【问题讨论】:
-
如果去掉邮件逻辑,直接编辑保存PDF,还损坏吗?
-
我想这就是我想做的……但我不知道该怎么做。