2011-06-02 118 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

相關問題