[英]Save PDF to location to folder on save
我一直在尋找我認為很容易找到的東西。
我有一個使用輸入字段並將值放在可填充PDF上的表單。
PDFDocument template = new PDFDocument(Server.MapPath("~/Forms/OfferSheet.pdf"));
template.Form.Fields["Seller"].Value = litName.Text;
template.Form.Fields["Address"].Value = litAddress.Text;
template.Form.Fields["Email"].Value = litEmailAddress.Text;
template.Form.Fields["Phone"].Value = string.Format("({0}) {1}-{2}", phone.Substring(0, 3), phone.Substring(3, 3), phone.Substring(6, 4));
template.Form.Fields["ProjectedFutureSale"].Value = string.Format("{0:n}", offer.FutureSalesPrice);
template.Form.Fields["PurchaseLoan"].Value = string.Format("{0:n}", offer.PurchasingLoanTitleClosing);
template.Form.Fields["Remodeling"].Value = string.Format("{0:n}", offer.Remodeling);
template.Form.Fields["Utilities"].Value = string.Format("{0:n}", offer.Utilities * 6);
template.Form.Fields["HOADues"].Value = string.Format("{0:n}", offer.HOADues / 2);
template.Form.Fields["Insurance"].Value = string.Format("{0:n}", offer.Insurance / 2);
template.Form.Fields["Taxes"].Value = string.Format("{0:n}", offer.Taxes / 2);
template.Form.Fields["LoanInterestCarry"].Value = string.Format("{0:n}", offer.LoanInterestCarry);
template.Form.Fields["InspectionRepairs"].Value = string.Format("{0:n}", offer.InspectionRepairs);
template.Form.Fields["SaleTitleClosingFees"].Value = string.Format("{0:n}", offer.SaleTitleClosingFees);
template.Form.Fields["RealEstateSalesCommission"].Value = string.Format("{0:n}", offer.SalesCommission);
template.Form.Fields["ProjectedProfit"].Value = string.Format("{0:n}", offer.ProjectedProfit);
template.Form.Fields["PurchasePrice"].Value = string.Format("{0:n}", offer.FinalOffer);
template.Form.Fields["ClosingDate"].Value = String.Format(new CultureInfo("en-US"), "{0:MM/dd/yyyy}", offer.ClosingDate);
var date = DateTime.Now;
template.Form.Fields["SellerSig1"].Value = litName.Text;
template.FlattenFormFields();
using (MailMessage message = new MailMessage())
{
message.Attachments.Add(new Attachment(new MemoryStream(template.GetPDFAsByteArray(), false), "PurchaseOffer.pdf"));
message.Subject = "PurchaseOffer";
message.Body = ConfigurationManager.AppSettings["FormEmail.Body"];
message.To.Add(new MailAddress(lnkEmail.Text));
new SmtpClient().Send(message);
}
var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now;
var rootPath = "~/Forms/Offers/";
var filePath = System.IO.Path.Combine(rootPath, fileName);
我不僅需要通過電子郵件發送PDF,還需要將PDF保存到文件位置,以便網站管理員可以查看PDF。 任何幫助都很棒。
您無法寫到客戶位置。
但是您的管理員可以輕松訪問服務器本身上的文件。
如果沒有,您可以列出該文件夾中的文件並提供下載選項。
您應該使用File.WriteAllBytes
函數將字節數組寫入本地文件。
var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now;
var rootPath = "~/Forms/Offers/";
var filePath = System.IO.Path.Combine(rootPath, fileName);
File.WriteAllBytes(filePath, template.GetPDFAsByteArray());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.