2011-06-02 116 views
0

我有一个模板,我想编辑并通过电子邮件发送。我有以下代码,但编辑过的pdf表示我的数据“已损坏,无法修复”。我不确定我是否将编辑后的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("[email protected]")); 
     msg.From = new MailAddress("[email protected]"); 
     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; 
    } 
+0

如果您取出电子邮件逻辑并编辑并保存PDF,它是否仍然损坏? – Jason 2011-06-02 19:34:01

+0

我认为这是我想要做的......但我不知道该怎么做。 – MrM 2011-06-02 19:42:58

回答

1

我认为当你完成书面方式将数据您需要再次读取之前流的位置重置为0一个MemoryStream。

尝试使用FileStream而不是MemoryStream保存到临时文件中,以便缩小问题的范围。

+0

我有ms.Position = 0;很好的接收,但不幸的是,它:( – MrM 2011-06-02 19:47:11

相关问题