簡體   English   中英

如何在 email 中編輯/發送 pdf 模板?

[英]How do I edit/send a pdf template in an email?

我有一個模板,我想進行編輯並通過 email 發送。 我有以下代碼,但編輯后的 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;
    }

我認為,當您完成將數據寫入 MemoryStream 時,您需要將 stream 的 position 重置為 0,然后再再次讀取它。

嘗試使用 FileStream 而不是 MemoryStream 將其保存到臨時文件中,以便縮小問題范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM